diff --git a/src/epplibwrapper/tests/test_pool.py b/src/epplibwrapper/tests/test_pool.py index c602d4a06..f8e556445 100644 --- a/src/epplibwrapper/tests/test_pool.py +++ b/src/epplibwrapper/tests/test_pool.py @@ -135,7 +135,7 @@ class TestConnectionPool(TestCase): stack.enter_context(patch.object(EPPConnectionPool, "kill_all_connections", do_nothing)) stack.enter_context(patch.object(SocketTransport, "send", self.fake_send)) stack.enter_context(patch.object(SocketTransport, "receive", fake_receive)) - with less_console_noise(): + with less_console_noise(): # Restart the connection pool registry.start_connection_pool() # Pool should be running, and be the right size @@ -211,7 +211,7 @@ class TestConnectionPool(TestCase): stack.enter_context(patch.object(EPPConnectionPool, "kill_all_connections", do_nothing)) stack.enter_context(patch.object(SocketTransport, "send", self.fake_send)) stack.enter_context(patch.object(SocketTransport, "receive", fake_receive)) - with less_console_noise(): + with less_console_noise(): # Start the connection pool registry.start_connection_pool() # Kill the connection pool @@ -243,7 +243,7 @@ class TestConnectionPool(TestCase): def test_raises_connection_error(self): """A .send is invoked on the pool, but registry connection is lost right as we send a command.""" - + with ExitStack() as stack: stack.enter_context(patch.object(EPPConnectionPool, "_create_socket", self.fake_socket)) stack.enter_context(patch.object(Socket, "connect", self.fake_client)) @@ -260,4 +260,3 @@ class TestConnectionPool(TestCase): expected = "InfoDomain failed to execute due to a connection error." result = registry.send(commands.InfoDomain(name="test.gov"), cleaned=True) self.assertEqual(result, expected) - diff --git a/src/epplibwrapper/utility/pool.py b/src/epplibwrapper/utility/pool.py index 2c7de119f..56ed46143 100644 --- a/src/epplibwrapper/utility/pool.py +++ b/src/epplibwrapper/utility/pool.py @@ -97,7 +97,7 @@ class EPPConnectionPool(ConnectionPool): # Nothing to do, the pool will generate a new connection later pass gevent.sleep(delay) - + def _create_socket(self, client, login) -> Socket: """Creates and returns a socket instance""" socket = Socket(client, login) diff --git a/src/registrar/tests/test_management_scripts.py b/src/registrar/tests/test_management_scripts.py index 40cdce6d2..34178e262 100644 --- a/src/registrar/tests/test_management_scripts.py +++ b/src/registrar/tests/test_management_scripts.py @@ -263,9 +263,7 @@ class TestExtendExpirationDates(MockEppLib): epp_expiration_date=date(2023, 11, 15), ) # Create a domain with an invalid expiration date - Domain.objects.get_or_create( - name="fake.gov", state=Domain.State.READY, expiration_date=date(2022, 5, 25) - ) + Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY, expiration_date=date(2022, 5, 25)) TransitionDomain.objects.get_or_create( username="themoonisactuallycheese@mail.com", domain_name="fake.gov", diff --git a/src/registrar/tests/test_models_domain.py b/src/registrar/tests/test_models_domain.py index 8cedb65e9..ca0a5e8d8 100644 --- a/src/registrar/tests/test_models_domain.py +++ b/src/registrar/tests/test_models_domain.py @@ -743,9 +743,11 @@ class TestRegistrantContacts(MockEppLib): self.domain_contact.get_security_email() # invalidate the cache so the next time get_security_email is called, it has to attempt to populate cache self.domain_contact._invalidate_cache() + # mock that registry throws an error on the EPP send def side_effect(_request, cleaned): raise RegistryError(code=ErrorCode.COMMAND_FAILED) + patcher = patch("registrar.models.domain.registry.send") mocked_send = patcher.start() mocked_send.side_effect = side_effect @@ -1236,6 +1238,7 @@ class TestRegistrantNameservers(MockEppLib): nameserver12 = "ns1.cats-are-superior12.com" nameserver13 = "ns1.cats-are-superior13.com" nameserver14 = "ns1.cats-are-superior14.com" + def _get_14_nameservers(): self.domain.nameservers = [ (nameserver1,), @@ -1253,6 +1256,7 @@ class TestRegistrantNameservers(MockEppLib): (nameserver13,), (nameserver14,), ] + self.assertRaises(NameserverError, _get_14_nameservers) self.assertEqual(self.mockedSendFunction.call_count, 0) @@ -1553,9 +1557,11 @@ class TestRegistrantNameservers(MockEppLib): # fetch_cache host, _ = Host.objects.get_or_create(domain=domain, name="ns1.fake.gov") host_ip, _ = HostIP.objects.get_or_create(host=host, address="1.1.1.1") + # mock that registry throws an error on the InfoHost send def side_effect(_request, cleaned): raise RegistryError(code=ErrorCode.COMMAND_FAILED) + patcher = patch("registrar.models.domain.registry.send") mocked_send = patcher.start() mocked_send.side_effect = side_effect @@ -1729,6 +1735,7 @@ class TestRegistrantDNSSEC(MockEppLib): ) else: return MagicMock(res_data=[self.mockDataInfoHosts]) + with less_console_noise(): patcher = patch("registrar.models.domain.registry.send") mocked_send = patcher.start() @@ -1806,6 +1813,7 @@ class TestRegistrantDNSSEC(MockEppLib): ) else: return MagicMock(res_data=[self.mockDataInfoHosts]) + with less_console_noise(): patcher = patch("registrar.models.domain.registry.send") mocked_send = patcher.start() @@ -1879,6 +1887,7 @@ class TestRegistrantDNSSEC(MockEppLib): ) else: return MagicMock(res_data=[self.mockDataInfoHosts]) + with less_console_noise(): patcher = patch("registrar.models.domain.registry.send") mocked_send = patcher.start() @@ -1947,6 +1956,7 @@ class TestRegistrantDNSSEC(MockEppLib): ) else: return MagicMock(res_data=[self.mockDataInfoHosts]) + with less_console_noise(): patcher = patch("registrar.models.domain.registry.send") mocked_send = patcher.start() @@ -2271,6 +2281,7 @@ class TestAnalystClientHold(MockEppLib): def side_effect(_request, cleaned): raise RegistryError(code=ErrorCode.OBJECT_STATUS_PROHIBITS_OPERATION) + with less_console_noise(): patcher = patch("registrar.models.domain.registry.send") mocked_send = patcher.start() diff --git a/src/registrar/tests/test_reports.py b/src/registrar/tests/test_reports.py index d74ebaffd..630904218 100644 --- a/src/registrar/tests/test_reports.py +++ b/src/registrar/tests/test_reports.py @@ -25,6 +25,7 @@ from datetime import date, datetime, timedelta from django.utils import timezone from .common import less_console_noise + class CsvReportsTest(TestCase): """Tests to determine if we are uploading our reports correctly""" @@ -124,6 +125,7 @@ class CsvReportsTest(TestCase): def side_effect(Bucket, Key): raise ClientError({"Error": {"Code": "NoSuchKey", "Message": "No such key"}}, "get_object") + with less_console_noise(): mock_client = MagicMock() mock_client.get_object.side_effect = side_effect @@ -145,6 +147,7 @@ class CsvReportsTest(TestCase): def side_effect(Bucket, Key): raise ClientError({"Error": {"Code": "NoSuchKey", "Message": "No such key"}}, "get_object") + with less_console_noise(): mock_client = MagicMock() mock_client.get_object.side_effect = side_effect @@ -524,8 +527,8 @@ class ExportDataTest(MockEppLib): # Create a CSV file in memory csv_file = StringIO() writer = csv.writer(csv_file) - # We use timezone.make_aware to sync to server time a datetime object with the current date (using date.today()) - # and a specific time (using datetime.min.time()). + # We use timezone.make_aware to sync to server time a datetime object with the current date + # (using date.today()) and a specific time (using datetime.min.time()). end_date = timezone.make_aware(datetime.combine(date.today() + timedelta(days=2), datetime.min.time())) start_date = timezone.make_aware(datetime.combine(date.today() - timedelta(days=2), datetime.min.time())) diff --git a/src/registrar/tests/test_transition_domain_migrations.py b/src/registrar/tests/test_transition_domain_migrations.py index d419e6fcd..e9453bd03 100644 --- a/src/registrar/tests/test_transition_domain_migrations.py +++ b/src/registrar/tests/test_transition_domain_migrations.py @@ -24,6 +24,7 @@ import logging logger = logging.getLogger(__name__) + class TestProcessedMigrations(TestCase): """This test case class is designed to verify the idempotency of migrations related to domain transitions in the application.""" @@ -241,8 +242,8 @@ class TestOrganizationMigration(TestCase): execute the load_organization_data command with the specified arguments. """ with less_console_noise(): - # noqa here (E501) because splitting this up makes it - # confusing to read. + # noqa here (E501) because splitting this up makes it + # confusing to read. with patch( "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa return_value=True, @@ -308,8 +309,9 @@ class TestOrganizationMigration(TestCase): 3. Checks that the data has been loaded as expected. The expected result is a set of TransitionDomain objects with specific attributes. - The test fetches the actual TransitionDomain objects from the database and compares them with the expected objects. - """ + The test fetches the actual TransitionDomain objects from the database and compares them with + the expected objects. + """ with less_console_noise(): # noqa - E501 (harder to read) # == First, parse all existing data == # @@ -392,7 +394,9 @@ class TestOrganizationMigration(TestCase): domain_information = DomainInformation.objects.filter(domain=_domain).get() expected_creator = User.objects.filter(username="System").get() - expected_ao = Contact.objects.filter(first_name="Seline", middle_name="testmiddle2", last_name="Tower").get() + expected_ao = Contact.objects.filter( + first_name="Seline", middle_name="testmiddle2", last_name="Tower" + ).get() expected_domain_information = DomainInformation( creator=expected_creator, organization_type="federal", @@ -445,7 +449,9 @@ class TestOrganizationMigration(TestCase): domain_information = DomainInformation.objects.filter(domain=_domain).get() expected_creator = User.objects.filter(username="System").get() - expected_ao = Contact.objects.filter(first_name="Seline", middle_name="testmiddle2", last_name="Tower").get() + expected_ao = Contact.objects.filter( + first_name="Seline", middle_name="testmiddle2", last_name="Tower" + ).get() expected_domain_information = DomainInformation( creator=expected_creator, organization_type="federal",