diff --git a/src/registrar/tests/test_admin_domain.py b/src/registrar/tests/test_admin_domain.py index 867bf1b82..f6807294c 100644 --- a/src/registrar/tests/test_admin_domain.py +++ b/src/registrar/tests/test_admin_domain.py @@ -223,7 +223,7 @@ class TestDomainAdminAsStaff(MockEppLib): self.assertEqual(domain.state, Domain.State.DELETED) - # @less_console_noise_decorator + @less_console_noise_decorator def test_deletion_is_unsuccessful(self): """ Scenario: Domain deletion is unsuccessful diff --git a/src/registrar/tests/test_api.py b/src/registrar/tests/test_api.py index f0d5dbcec..ea4ee69cc 100644 --- a/src/registrar/tests/test_api.py +++ b/src/registrar/tests/test_api.py @@ -62,7 +62,7 @@ class GetSeniorOfficialJsonTest(TestCase): p = "password" self.client.login(username="testuser", password=p) response = self.client.get(self.api_url, {"agency_name": "Test Agency"}) - self.assertEqual(response.status_code, 302) + self.assertEqual(response.status_code, 403) @less_console_noise_decorator def test_get_senior_official_json_not_found(self): @@ -138,7 +138,7 @@ class GetPortfolioJsonTest(TestCase): """Test that an unauthenticated user receives a 403 with an error message.""" self.client.force_login(self.user) response = self.client.get(self.api_url, {"id": self.portfolio.id}) - self.assertEqual(response.status_code, 302) + self.assertEqual(response.status_code, 403) @less_console_noise_decorator def test_get_portfolio_json_not_found(self): @@ -181,7 +181,7 @@ class GetFederalPortfolioTypeJsonTest(TestCase): p = "password" self.client.login(username="testuser", password=p) response = self.client.get(self.api_url, {"agency_name": "Test Agency", "organization_type": "federal"}) - self.assertEqual(response.status_code, 302) + self.assertEqual(response.status_code, 403) class GetActionNeededEmailForUserJsonTest(TestCase): diff --git a/src/registrar/tests/test_management_scripts.py b/src/registrar/tests/test_management_scripts.py index fd53c21f8..668eeff0e 100644 --- a/src/registrar/tests/test_management_scripts.py +++ b/src/registrar/tests/test_management_scripts.py @@ -453,6 +453,7 @@ class TestPopulateFirstReady(TestCase): # Delete domains Domain.objects.all().delete() + @less_console_noise_decorator def run_populate_first_ready(self): """ This method executes the populate_first_ready command. @@ -460,103 +461,102 @@ class TestPopulateFirstReady(TestCase): The 'call_command' function from Django's management framework is then used to execute the populate_first_ready command with the specified arguments. """ - with less_console_noise(): - with patch( - "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa - return_value=True, - ): - call_command("populate_first_ready") + with patch( + "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa + return_value=True, + ): + call_command("populate_first_ready") + @less_console_noise_decorator def test_populate_first_ready_state_ready(self): """ Tests that the populate_first_ready works as expected for the state 'ready' """ - with less_console_noise(): - # Set the created at date - self.ready_domain.created_at = self.ready_at_date_tz_aware - self.ready_domain.save() - desired_domain = copy.deepcopy(self.ready_domain) - desired_domain.first_ready = self.ready_at_date - # Run the expiration date script - self.run_populate_first_ready() - self.assertEqual(desired_domain, self.ready_domain) - # Explicitly test the first_ready date - first_ready = Domain.objects.filter(name="fakeready.gov").get().first_ready - self.assertEqual(first_ready, self.ready_at_date) + # Set the created at date + self.ready_domain.created_at = self.ready_at_date_tz_aware + self.ready_domain.save() + desired_domain = copy.deepcopy(self.ready_domain) + desired_domain.first_ready = self.ready_at_date + # Run the expiration date script + self.run_populate_first_ready() + self.assertEqual(desired_domain, self.ready_domain) + # Explicitly test the first_ready date + first_ready = Domain.objects.filter(name="fakeready.gov").get().first_ready + self.assertEqual(first_ready, self.ready_at_date) + @less_console_noise_decorator def test_populate_first_ready_state_deleted(self): """ Tests that the populate_first_ready works as expected for the state 'deleted' """ - with less_console_noise(): - # Set the created at date - self.deleted_domain.created_at = self.ready_at_date_tz_aware - self.deleted_domain.save() - desired_domain = copy.deepcopy(self.deleted_domain) - desired_domain.first_ready = self.ready_at_date - # Run the expiration date script - self.run_populate_first_ready() - self.assertEqual(desired_domain, self.deleted_domain) - # Explicitly test the first_ready date - first_ready = Domain.objects.filter(name="fakedeleted.gov").get().first_ready - self.assertEqual(first_ready, self.ready_at_date) + # Set the created at date + self.deleted_domain.created_at = self.ready_at_date_tz_aware + self.deleted_domain.save() + desired_domain = copy.deepcopy(self.deleted_domain) + desired_domain.first_ready = self.ready_at_date + # Run the expiration date script + self.run_populate_first_ready() + self.assertEqual(desired_domain, self.deleted_domain) + # Explicitly test the first_ready date + first_ready = Domain.objects.filter(name="fakedeleted.gov").get().first_ready + self.assertEqual(first_ready, self.ready_at_date) + @less_console_noise_decorator def test_populate_first_ready_state_dns_needed(self): """ Tests that the populate_first_ready doesn't make changes when a domain's state is 'dns_needed' """ - with less_console_noise(): - # Set the created at date - self.dns_needed_domain.created_at = self.ready_at_date_tz_aware - self.dns_needed_domain.save() - desired_domain = copy.deepcopy(self.dns_needed_domain) - desired_domain.first_ready = None - # Run the expiration date script - self.run_populate_first_ready() - current_domain = self.dns_needed_domain - # The object should largely be unaltered (does not test first_ready) - self.assertEqual(desired_domain, current_domain) - first_ready = Domain.objects.filter(name="fakedns.gov").get().first_ready - # Explicitly test the first_ready date - self.assertNotEqual(first_ready, self.ready_at_date) - self.assertEqual(first_ready, None) + # Set the created at date + self.dns_needed_domain.created_at = self.ready_at_date_tz_aware + self.dns_needed_domain.save() + desired_domain = copy.deepcopy(self.dns_needed_domain) + desired_domain.first_ready = None + # Run the expiration date script + self.run_populate_first_ready() + current_domain = self.dns_needed_domain + # The object should largely be unaltered (does not test first_ready) + self.assertEqual(desired_domain, current_domain) + first_ready = Domain.objects.filter(name="fakedns.gov").get().first_ready + # Explicitly test the first_ready date + self.assertNotEqual(first_ready, self.ready_at_date) + self.assertEqual(first_ready, None) + @less_console_noise_decorator def test_populate_first_ready_state_on_hold(self): """ Tests that the populate_first_ready works as expected for the state 'on_hold' """ - with less_console_noise(): - self.hold_domain.created_at = self.ready_at_date_tz_aware - self.hold_domain.save() - desired_domain = copy.deepcopy(self.hold_domain) - desired_domain.first_ready = self.ready_at_date - # Run the update first ready_at script - self.run_populate_first_ready() - current_domain = self.hold_domain - self.assertEqual(desired_domain, current_domain) - # Explicitly test the first_ready date - first_ready = Domain.objects.filter(name="fakehold.gov").get().first_ready - self.assertEqual(first_ready, self.ready_at_date) + self.hold_domain.created_at = self.ready_at_date_tz_aware + self.hold_domain.save() + desired_domain = copy.deepcopy(self.hold_domain) + desired_domain.first_ready = self.ready_at_date + # Run the update first ready_at script + self.run_populate_first_ready() + current_domain = self.hold_domain + self.assertEqual(desired_domain, current_domain) + # Explicitly test the first_ready date + first_ready = Domain.objects.filter(name="fakehold.gov").get().first_ready + self.assertEqual(first_ready, self.ready_at_date) + @less_console_noise_decorator def test_populate_first_ready_state_unknown(self): """ Tests that the populate_first_ready works as expected for the state 'unknown' """ - with less_console_noise(): - # Set the created at date - self.unknown_domain.created_at = self.ready_at_date_tz_aware - self.unknown_domain.save() - desired_domain = copy.deepcopy(self.unknown_domain) - desired_domain.first_ready = None - # Run the expiration date script - self.run_populate_first_ready() - current_domain = self.unknown_domain - # The object should largely be unaltered (does not test first_ready) - self.assertEqual(desired_domain, current_domain) - # Explicitly test the first_ready date - first_ready = Domain.objects.filter(name="fakeunknown.gov").get().first_ready - self.assertNotEqual(first_ready, self.ready_at_date) - self.assertEqual(first_ready, None) + # Set the created at date + self.unknown_domain.created_at = self.ready_at_date_tz_aware + self.unknown_domain.save() + desired_domain = copy.deepcopy(self.unknown_domain) + desired_domain.first_ready = None + # Run the expiration date script + self.run_populate_first_ready() + current_domain = self.unknown_domain + # The object should largely be unaltered (does not test first_ready) + self.assertEqual(desired_domain, current_domain) + # Explicitly test the first_ready date + first_ready = Domain.objects.filter(name="fakeunknown.gov").get().first_ready + self.assertNotEqual(first_ready, self.ready_at_date) + self.assertEqual(first_ready, None) class TestPatchAgencyInfo(TestCase): @@ -577,10 +577,10 @@ class TestPatchAgencyInfo(TestCase): TransitionDomain.objects.all().delete() @patch("registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", return_value=True) + @less_console_noise_decorator def call_patch_federal_agency_info(self, mock_prompt): """Calls the patch_federal_agency_info command and mimics a keypress""" - with less_console_noise(): - call_command("patch_federal_agency_info", "registrar/tests/data/fake_current_full.csv", debug=True) + call_command("patch_federal_agency_info", "registrar/tests/data/fake_current_full.csv", debug=True) class TestExtendExpirationDates(MockEppLib): @@ -636,6 +636,7 @@ class TestExtendExpirationDates(MockEppLib): User.objects.all().delete() UserDomainRole.objects.all().delete() + @less_console_noise_decorator def run_extend_expiration_dates(self): """ This method executes the extend_expiration_dates command. @@ -643,83 +644,83 @@ class TestExtendExpirationDates(MockEppLib): The 'call_command' function from Django's management framework is then used to execute the extend_expiration_dates command with the specified arguments. """ - with less_console_noise(): - with patch( - "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa - return_value=True, - ): - call_command("extend_expiration_dates") + with patch( + "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa + return_value=True, + ): + call_command("extend_expiration_dates") + @less_console_noise_decorator def test_extends_expiration_date_correctly(self): """ Tests that the extend_expiration_dates method extends dates as expected """ - with less_console_noise(): - desired_domain = Domain.objects.filter(name="waterbutpurple.gov").get() - desired_domain.expiration_date = date(2024, 11, 15) - # Run the expiration date script - self.run_extend_expiration_dates() - current_domain = Domain.objects.filter(name="waterbutpurple.gov").get() - self.assertEqual(desired_domain, current_domain) - # Explicitly test the expiration date - self.assertEqual(current_domain.expiration_date, date(2024, 11, 15)) + desired_domain = Domain.objects.filter(name="waterbutpurple.gov").get() + desired_domain.expiration_date = date(2024, 11, 15) + # Run the expiration date script + self.run_extend_expiration_dates() + current_domain = Domain.objects.filter(name="waterbutpurple.gov").get() + self.assertEqual(desired_domain, current_domain) + # Explicitly test the expiration date + self.assertEqual(current_domain.expiration_date, date(2024, 11, 15)) + @less_console_noise_decorator def test_extends_expiration_date_skips_non_current(self): """ Tests that the extend_expiration_dates method correctly skips domains with an expiration date less than a certain threshold. """ - with less_console_noise(): - desired_domain = Domain.objects.filter(name="fake.gov").get() - desired_domain.expiration_date = date(2022, 5, 25) - # Run the expiration date script - self.run_extend_expiration_dates() - current_domain = Domain.objects.filter(name="fake.gov").get() - self.assertEqual(desired_domain, current_domain) - # Explicitly test the expiration date. The extend_expiration_dates script - # will skip all dates less than date(2023, 11, 15), meaning that this domain - # should not be affected by the change. - self.assertEqual(current_domain.expiration_date, date(2022, 5, 25)) + desired_domain = Domain.objects.filter(name="fake.gov").get() + desired_domain.expiration_date = date(2022, 5, 25) + # Run the expiration date script + self.run_extend_expiration_dates() + current_domain = Domain.objects.filter(name="fake.gov").get() + self.assertEqual(desired_domain, current_domain) + # Explicitly test the expiration date. The extend_expiration_dates script + # will skip all dates less than date(2023, 11, 15), meaning that this domain + # should not be affected by the change. + self.assertEqual(current_domain.expiration_date, date(2022, 5, 25)) + @less_console_noise_decorator def test_extends_expiration_date_skips_maximum_date(self): """ Tests that the extend_expiration_dates method correctly skips domains with an expiration date more than a certain threshold. """ - with less_console_noise(): - desired_domain = Domain.objects.filter(name="fakemaximum.gov").get() - desired_domain.expiration_date = date(2024, 12, 31) + desired_domain = Domain.objects.filter(name="fakemaximum.gov").get() + desired_domain.expiration_date = date(2024, 12, 31) - # Run the expiration date script - self.run_extend_expiration_dates() + # Run the expiration date script + self.run_extend_expiration_dates() - current_domain = Domain.objects.filter(name="fakemaximum.gov").get() - self.assertEqual(desired_domain, current_domain) + current_domain = Domain.objects.filter(name="fakemaximum.gov").get() + self.assertEqual(desired_domain, current_domain) - # Explicitly test the expiration date. The extend_expiration_dates script - # will skip all dates less than date(2023, 11, 15), meaning that this domain - # should not be affected by the change. - self.assertEqual(current_domain.expiration_date, date(2024, 12, 31)) + # Explicitly test the expiration date. The extend_expiration_dates script + # will skip all dates less than date(2023, 11, 15), meaning that this domain + # should not be affected by the change. + self.assertEqual(current_domain.expiration_date, date(2024, 12, 31)) + @less_console_noise_decorator def test_extends_expiration_date_skips_non_ready(self): """ Tests that the extend_expiration_dates method correctly skips domains not in the state "ready" """ - with less_console_noise(): - desired_domain = Domain.objects.filter(name="fakeneeded.gov").get() - desired_domain.expiration_date = date(2023, 11, 15) + desired_domain = Domain.objects.filter(name="fakeneeded.gov").get() + desired_domain.expiration_date = date(2023, 11, 15) - # Run the expiration date script - self.run_extend_expiration_dates() + # Run the expiration date script + self.run_extend_expiration_dates() - current_domain = Domain.objects.filter(name="fakeneeded.gov").get() - self.assertEqual(desired_domain, current_domain) + current_domain = Domain.objects.filter(name="fakeneeded.gov").get() + self.assertEqual(desired_domain, current_domain) - # Explicitly test the expiration date. The extend_expiration_dates script - # will skip all dates less than date(2023, 11, 15), meaning that this domain - # should not be affected by the change. - self.assertEqual(current_domain.expiration_date, date(2023, 11, 15)) + # Explicitly test the expiration date. The extend_expiration_dates script + # will skip all dates less than date(2023, 11, 15), meaning that this domain + # should not be affected by the change. + self.assertEqual(current_domain.expiration_date, date(2023, 11, 15)) + @less_console_noise_decorator def test_extends_expiration_date_idempotent(self): """ Tests the idempotency of the extend_expiration_dates command. @@ -727,21 +728,20 @@ class TestExtendExpirationDates(MockEppLib): Verifies that running the method multiple times does not change the expiration date of a domain beyond the initial extension. """ - with less_console_noise(): - desired_domain = Domain.objects.filter(name="waterbutpurple.gov").get() - desired_domain.expiration_date = date(2024, 11, 15) - # Run the expiration date script - self.run_extend_expiration_dates() - current_domain = Domain.objects.filter(name="waterbutpurple.gov").get() - self.assertEqual(desired_domain, current_domain) - # Explicitly test the expiration date - self.assertEqual(desired_domain.expiration_date, date(2024, 11, 15)) - # Run the expiration date script again - self.run_extend_expiration_dates() - # The old domain shouldn't have changed - self.assertEqual(desired_domain, current_domain) - # Explicitly test the expiration date - should be the same - self.assertEqual(desired_domain.expiration_date, date(2024, 11, 15)) + desired_domain = Domain.objects.filter(name="waterbutpurple.gov").get() + desired_domain.expiration_date = date(2024, 11, 15) + # Run the expiration date script + self.run_extend_expiration_dates() + current_domain = Domain.objects.filter(name="waterbutpurple.gov").get() + self.assertEqual(desired_domain, current_domain) + # Explicitly test the expiration date + self.assertEqual(desired_domain.expiration_date, date(2024, 11, 15)) + # Run the expiration date script again + self.run_extend_expiration_dates() + # The old domain shouldn't have changed + self.assertEqual(desired_domain, current_domain) + # Explicitly test the expiration date - should be the same + self.assertEqual(desired_domain.expiration_date, date(2024, 11, 15)) class TestDiscloseEmails(MockEppLib): @@ -753,6 +753,7 @@ class TestDiscloseEmails(MockEppLib): PublicContact.objects.all().delete() Domain.objects.all().delete() + @less_console_noise_decorator def run_disclose_security_emails(self): """ This method executes the disclose_security_emails command. @@ -760,44 +761,43 @@ class TestDiscloseEmails(MockEppLib): The 'call_command' function from Django's management framework is then used to execute the disclose_security_emails command. """ - with less_console_noise(): - with patch( - "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa - return_value=True, - ): - call_command("disclose_security_emails") + with patch( + "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa + return_value=True, + ): + call_command("disclose_security_emails") + @less_console_noise_decorator def test_disclose_security_emails(self): """ Tests that command disclose_security_emails runs successfully with appropriate EPP calll to UpdateContact. """ - with less_console_noise(): - domain, _ = Domain.objects.get_or_create(name="testdisclose.gov", state=Domain.State.READY) - expectedSecContact = PublicContact.get_default_security() - expectedSecContact.domain = domain - expectedSecContact.email = "123@mail.gov" - # set domain security email to 123@mail.gov instead of default email - domain.security_contact = expectedSecContact - self.run_disclose_security_emails() + domain, _ = Domain.objects.get_or_create(name="testdisclose.gov", state=Domain.State.READY) + expectedSecContact = PublicContact.get_default_security() + expectedSecContact.domain = domain + expectedSecContact.email = "123@mail.gov" + # set domain security email to 123@mail.gov instead of default email + domain.security_contact = expectedSecContact + self.run_disclose_security_emails() - # running disclose_security_emails sends EPP call UpdateContact with disclose - self.mockedSendFunction.assert_has_calls( - [ - call( - commands.UpdateContact( - id=domain.security_contact.registry_id, - postal_info=domain._make_epp_contact_postal_info(contact=domain.security_contact), - email=domain.security_contact.email, - voice=domain.security_contact.voice, - fax=domain.security_contact.fax, - auth_info=common.ContactAuthInfo(pw="2fooBAR123fooBaz"), - disclose=domain._disclose_fields(contact=domain.security_contact), - ), - cleaned=True, - ) - ] - ) + # running disclose_security_emails sends EPP call UpdateContact with disclose + self.mockedSendFunction.assert_has_calls( + [ + call( + commands.UpdateContact( + id=domain.security_contact.registry_id, + postal_info=domain._make_epp_contact_postal_info(contact=domain.security_contact), + email=domain.security_contact.email, + voice=domain.security_contact.voice, + fax=domain.security_contact.fax, + auth_info=common.ContactAuthInfo(pw="2fooBAR123fooBaz"), + disclose=domain._disclose_fields(contact=domain.security_contact), + ), + cleaned=True, + ) + ] + ) class TestCleanTables(TestCase): @@ -812,17 +812,18 @@ class TestCleanTables(TestCase): self.logger_patcher.stop() @override_settings(IS_PRODUCTION=True) + @less_console_noise_decorator def test_command_logs_error_in_production(self): """Test that the handle method does not process in production""" - with less_console_noise(): - with patch( - "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa - return_value=True, - ): - call_command("clean_tables") - self.logger_mock.error.assert_called_with("clean_tables cannot be run in production") + with patch( + "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa + return_value=True, + ): + call_command("clean_tables") + self.logger_mock.error.assert_called_with("clean_tables cannot be run in production") @override_settings(IS_PRODUCTION=False) + @less_console_noise_decorator def test_command_cleans_tables(self): """test that the handle method functions properly to clean tables""" @@ -890,61 +891,61 @@ class TestCleanTables(TestCase): raise @override_settings(IS_PRODUCTION=False) + @less_console_noise_decorator def test_command_handles_nonexistent_model(self): """Test that exceptions for non existent models are handled properly within the handle method""" - with less_console_noise(): - with patch("django.apps.apps.get_model", side_effect=LookupError): - with patch( - "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa - return_value=True, - ): - call_command("clean_tables") - # Assert that the error message was logged for any of the table names - self.logger_mock.error.assert_any_call("Model for table DomainInformation not found.") - self.logger_mock.error.assert_any_call("Model for table DomainRequest not found.") - self.logger_mock.error.assert_any_call("Model for table PublicContact not found.") - self.logger_mock.error.assert_any_call("Model for table Domain not found.") - self.logger_mock.error.assert_any_call("Model for table User not found.") - self.logger_mock.error.assert_any_call("Model for table Contact not found.") - self.logger_mock.error.assert_any_call("Model for table Website not found.") - self.logger_mock.error.assert_any_call("Model for table DraftDomain not found.") - self.logger_mock.error.assert_any_call("Model for table HostIp not found.") - self.logger_mock.error.assert_any_call("Model for table Host not found.") + with patch("django.apps.apps.get_model", side_effect=LookupError): + with patch( + "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa + return_value=True, + ): + call_command("clean_tables") + # Assert that the error message was logged for any of the table names + self.logger_mock.error.assert_any_call("Model for table DomainInformation not found.") + self.logger_mock.error.assert_any_call("Model for table DomainRequest not found.") + self.logger_mock.error.assert_any_call("Model for table PublicContact not found.") + self.logger_mock.error.assert_any_call("Model for table Domain not found.") + self.logger_mock.error.assert_any_call("Model for table User not found.") + self.logger_mock.error.assert_any_call("Model for table Contact not found.") + self.logger_mock.error.assert_any_call("Model for table Website not found.") + self.logger_mock.error.assert_any_call("Model for table DraftDomain not found.") + self.logger_mock.error.assert_any_call("Model for table HostIp not found.") + self.logger_mock.error.assert_any_call("Model for table Host not found.") @override_settings(IS_PRODUCTION=False) + @less_console_noise_decorator def test_command_logs_other_exceptions(self): """Test that generic exceptions are handled properly in the handle method""" - with less_console_noise(): - with patch("django.apps.apps.get_model") as get_model_mock: - model_mock = MagicMock() - get_model_mock.return_value = model_mock + with patch("django.apps.apps.get_model") as get_model_mock: + model_mock = MagicMock() + get_model_mock.return_value = model_mock - # Mock the values_list so that DomainInformation attempts a delete - pk_batches = [[1, 2, 3, 4, 5, 6], []] + # Mock the values_list so that DomainInformation attempts a delete + pk_batches = [[1, 2, 3, 4, 5, 6], []] - def values_list_side_effect(*args, **kwargs): - if args == ("pk",) and kwargs.get("flat", False): - return pk_batches.pop(0) - return [] + def values_list_side_effect(*args, **kwargs): + if args == ("pk",) and kwargs.get("flat", False): + return pk_batches.pop(0) + return [] - model_mock.objects.values_list.side_effect = values_list_side_effect + model_mock.objects.values_list.side_effect = values_list_side_effect - # Mock delete to raise a generic exception - model_mock.objects.filter.return_value.delete.side_effect = Exception("Mocked delete exception") + # Mock delete to raise a generic exception + model_mock.objects.filter.return_value.delete.side_effect = Exception("Mocked delete exception") - with patch( - "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", - return_value=True, - ): - with self.assertRaises(Exception) as context: - # Execute the command - call_command("clean_tables") + with patch( + "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", + return_value=True, + ): + with self.assertRaises(Exception) as context: + # Execute the command + call_command("clean_tables") - # Check the exception message - self.assertEqual(str(context.exception), "Custom delete error") + # Check the exception message + self.assertEqual(str(context.exception), "Custom delete error") - # Assert that delete was called - model_mock.objects.filter.return_value.delete.assert_called() + # Assert that delete was called + model_mock.objects.filter.return_value.delete.assert_called() class TestExportTables(MockEppLib): @@ -1029,34 +1030,34 @@ class TestExportTables(MockEppLib): self.logger_mock.info.assert_any_call(f"Removed {table_name}_1.csv") @patch("registrar.management.commands.export_tables.getattr") + @less_console_noise_decorator def test_export_table_handles_missing_resource_class(self, mock_getattr): """Test that missing resource classes are handled properly in the handle method""" - with less_console_noise(): - mock_getattr.side_effect = AttributeError + mock_getattr.side_effect = AttributeError - # Import the command to avoid any locale or gettext issues - command_class = import_string("registrar.management.commands.export_tables.Command") - command_instance = command_class() - command_instance.export_table("NonExistentTable") + # Import the command to avoid any locale or gettext issues + command_class = import_string("registrar.management.commands.export_tables.Command") + command_instance = command_class() + command_instance.export_table("NonExistentTable") - self.logger_mock.error.assert_called_with( - "Resource class NonExistentTableResource not found in registrar.admin" - ) + self.logger_mock.error.assert_called_with( + "Resource class NonExistentTableResource not found in registrar.admin" + ) @patch("registrar.management.commands.export_tables.getattr") + @less_console_noise_decorator def test_export_table_handles_generic_exception(self, mock_getattr): """Test that general exceptions in the handle method are handled correctly""" - with less_console_noise(): - mock_resource_class = MagicMock() - mock_resource_class().export.side_effect = Exception("Test Exception") - mock_getattr.return_value = mock_resource_class + mock_resource_class = MagicMock() + mock_resource_class().export.side_effect = Exception("Test Exception") + mock_getattr.return_value = mock_resource_class - # Import the command to avoid any locale or gettext issues - command_class = import_string("registrar.management.commands.export_tables.Command") - command_instance = command_class() - command_instance.export_table("TestTable") + # Import the command to avoid any locale or gettext issues + command_class = import_string("registrar.management.commands.export_tables.Command") + command_instance = command_class() + command_instance.export_table("TestTable") - self.logger_mock.error.assert_called_with("Failed to export TestTable: Test Exception") + self.logger_mock.error.assert_called_with("Failed to export TestTable: Test Exception") class TestImportTables(TestCase): @@ -1072,6 +1073,7 @@ class TestImportTables(TestCase): @patch("registrar.management.commands.import_tables.getattr") @patch("django.apps.apps.get_model") @patch("os.listdir") + @less_console_noise_decorator def test_handle( self, mock_listdir, @@ -1086,105 +1088,104 @@ class TestImportTables(TestCase): mock_makedirs, ): """Test that the handle method properly imports tables""" - with less_console_noise(): - # Mock os.makedirs to do nothing - mock_makedirs.return_value = None + # Mock os.makedirs to do nothing + mock_makedirs.return_value = None - # Mock os.path.exists to always return True - mock_path_exists.return_value = True + # Mock os.path.exists to always return True + mock_path_exists.return_value = True - # Mock the zipfile to have extractall return None - mock_zipfile_instance = mock_zipfile.return_value.__enter__.return_value - mock_zipfile_instance.extractall.return_value = None + # Mock the zipfile to have extractall return None + mock_zipfile_instance = mock_zipfile.return_value.__enter__.return_value + mock_zipfile_instance.extractall.return_value = None - # Check that the import_table function was called for each table - table_names = [ - "User", - "Contact", - "Domain", - "DomainRequest", - "DomainInformation", - "UserDomainRole", - "DraftDomain", - "Website", - "HostIp", - "Host", - "PublicContact", - ] + # Check that the import_table function was called for each table + table_names = [ + "User", + "Contact", + "Domain", + "DomainRequest", + "DomainInformation", + "UserDomainRole", + "DraftDomain", + "Website", + "HostIp", + "Host", + "PublicContact", + ] - # Mock directory listing - mock_listdir.side_effect = lambda path: [f"{table}_1.csv" for table in table_names] + # Mock directory listing + mock_listdir.side_effect = lambda path: [f"{table}_1.csv" for table in table_names] - # Mock the CSV file content - csv_content = b"mock_csv_data" + # Mock the CSV file content + csv_content = b"mock_csv_data" - # Mock the open function to return a mock file - mock_open.return_value.__enter__.return_value.read.return_value = csv_content + # Mock the open function to return a mock file + mock_open.return_value.__enter__.return_value.read.return_value = csv_content - # Mock the Dataset class and its load method to return a dataset - mock_dataset_instance = MagicMock(spec=tablib.Dataset) - with patch( - "registrar.management.commands.import_tables.tablib.Dataset.load", return_value=mock_dataset_instance - ): - # Mock the resource class and its import method - mock_resource_class = MagicMock() - mock_resource_instance = MagicMock() - mock_result = MagicMock() - mock_result.has_errors.return_value = False - mock_resource_instance.import_data.return_value = mock_result - mock_resource_class.return_value = mock_resource_instance - mock_getattr.return_value = mock_resource_class + # Mock the Dataset class and its load method to return a dataset + mock_dataset_instance = MagicMock(spec=tablib.Dataset) + with patch( + "registrar.management.commands.import_tables.tablib.Dataset.load", return_value=mock_dataset_instance + ): + # Mock the resource class and its import method + mock_resource_class = MagicMock() + mock_resource_instance = MagicMock() + mock_result = MagicMock() + mock_result.has_errors.return_value = False + mock_resource_instance.import_data.return_value = mock_result + mock_resource_class.return_value = mock_resource_instance + mock_getattr.return_value = mock_resource_class - # Call the command - call_command("import_tables") + # Call the command + call_command("import_tables") - # Check that os.makedirs was called once to create the tmp directory - mock_makedirs.assert_called_once_with("tmp", exist_ok=True) + # Check that os.makedirs was called once to create the tmp directory + mock_makedirs.assert_called_once_with("tmp", exist_ok=True) - # Check that os.path.exists was called once for the zip file - mock_path_exists.assert_any_call("tmp/exported_tables.zip") + # Check that os.path.exists was called once for the zip file + mock_path_exists.assert_any_call("tmp/exported_tables.zip") - # Check that pyzipper.AESZipFile was called once to open the zip file - mock_zipfile.assert_called_once_with("tmp/exported_tables.zip", "r") + # Check that pyzipper.AESZipFile was called once to open the zip file + mock_zipfile.assert_called_once_with("tmp/exported_tables.zip", "r") - # Check that extractall was called once to extract the zip file contents - mock_zipfile_instance.extractall.assert_called_once_with("tmp") + # Check that extractall was called once to extract the zip file contents + mock_zipfile_instance.extractall.assert_called_once_with("tmp") - # Check that os.path.exists was called for each table - for table_name in table_names: - mock_path_exists.assert_any_call(f"{table_name}_1.csv") + # Check that os.path.exists was called for each table + for table_name in table_names: + mock_path_exists.assert_any_call(f"{table_name}_1.csv") - # Check that logger.info was called for each successful import - for table_name in table_names: - mock_logger.info.assert_any_call(f"Successfully imported {table_name}_1.csv into {table_name}") + # Check that logger.info was called for each successful import + for table_name in table_names: + mock_logger.info.assert_any_call(f"Successfully imported {table_name}_1.csv into {table_name}") - # Check that logger.error was not called for resource class not found - mock_logger.error.assert_not_called() + # Check that logger.error was not called for resource class not found + mock_logger.error.assert_not_called() - # Check that os.remove was called for each CSV file - for table_name in table_names: - mock_remove.assert_any_call(f"{table_name}_1.csv") + # Check that os.remove was called for each CSV file + for table_name in table_names: + mock_remove.assert_any_call(f"{table_name}_1.csv") - # Check that logger.info was called for each CSV file removal - for table_name in table_names: - mock_logger.info.assert_any_call(f"Removed temporary file {table_name}_1.csv") + # Check that logger.info was called for each CSV file removal + for table_name in table_names: + mock_logger.info.assert_any_call(f"Removed temporary file {table_name}_1.csv") @patch("registrar.management.commands.import_tables.logger") @patch("registrar.management.commands.import_tables.os.makedirs") @patch("registrar.management.commands.import_tables.os.path.exists") + @less_console_noise_decorator def test_handle_zip_file_not_found(self, mock_path_exists, mock_makedirs, mock_logger): """Test the handle method when the zip file doesn't exist""" - with less_console_noise(): - # Mock os.makedirs to do nothing - mock_makedirs.return_value = None + # Mock os.makedirs to do nothing + mock_makedirs.return_value = None - # Mock os.path.exists to return False - mock_path_exists.return_value = False + # Mock os.path.exists to return False + mock_path_exists.return_value = False - call_command("import_tables") + call_command("import_tables") - # Check that logger.error was called with the correct message - mock_logger.error.assert_called_once_with("Zip file tmp/exported_tables.zip does not exist.") + # Check that logger.error was called with the correct message + mock_logger.error.assert_called_once_with("Zip file tmp/exported_tables.zip does not exist.") class TestTransferFederalAgencyType(TestCase): @@ -1254,6 +1255,7 @@ class TestTransferFederalAgencyType(TestCase): id__in=[self.amtrak.id, self.legislative_branch.id, self.library_of_congress.id, self.gov_admin.id] ).delete() + @less_console_noise_decorator def run_transfer_federal_agency_type(self): """ This method executes the transfer_federal_agency_type command. @@ -1261,12 +1263,11 @@ class TestTransferFederalAgencyType(TestCase): The 'call_command' function from Django's management framework is then used to execute the populate_first_ready command with the specified arguments. """ - with less_console_noise(): - with patch( - "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa - return_value=True, - ): - call_command("transfer_federal_agency_type") + with patch( + "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa + return_value=True, + ): + call_command("transfer_federal_agency_type") @less_console_noise_decorator def test_transfer_federal_agency_type_script(self): @@ -1628,6 +1629,7 @@ class TestCreateFederalPortfolio(TestCase): # Test the senior official self.assertEqual(portfolio.senior_official, self.senior_official) + @less_console_noise_decorator def test_create_multiple_portfolios_for_branch_judicial(self): """Tests creating all portfolios under a given branch""" federal_choice = DomainRequest.OrganizationChoices.FEDERAL @@ -1655,6 +1657,7 @@ class TestCreateFederalPortfolio(TestCase): self.assertTrue(all([creator == User.get_default_user() for creator in creators])) self.assertTrue(all([note == "Auto-generated record" for note in notes])) + @less_console_noise_decorator def test_create_multiple_portfolios_for_branch_legislative(self): """Tests creating all portfolios under a given branch""" federal_choice = DomainRequest.OrganizationChoices.FEDERAL @@ -1682,6 +1685,7 @@ class TestCreateFederalPortfolio(TestCase): self.assertTrue(all([creator == User.get_default_user() for creator in creators])) self.assertTrue(all([note == "Auto-generated record" for note in notes])) + @less_console_noise_decorator def test_script_adds_requested_suborganization_information(self): """Tests that the script adds the requested suborg fields for domain requests""" # Create a new domain request with some errant spacing @@ -1710,6 +1714,7 @@ class TestCreateFederalPortfolio(TestCase): custom_suborg_request.suborganization_state_territory, DomainRequest.StateTerritoryChoices.TEXAS ) + @less_console_noise_decorator def test_create_multiple_portfolios_for_branch_executive(self): """Tests creating all portfolios under a given branch""" federal_choice = DomainRequest.OrganizationChoices.FEDERAL @@ -1772,6 +1777,7 @@ class TestCreateFederalPortfolio(TestCase): self.assertEqual(expected_requests.count(), 2) self.assertEqual(expected_domain_infos.count(), 2) + @less_console_noise_decorator def test_handle_portfolio_requests(self): """Verify portfolio association with domain requests.""" self.run_create_federal_portfolio(agency_name="Test Federal Agency", parse_requests=True) @@ -1781,6 +1787,7 @@ class TestCreateFederalPortfolio(TestCase): self.assertEqual(self.domain_request.portfolio.federal_agency, self.federal_agency) self.assertEqual(self.domain_request.sub_organization.name, "Testorg") + @less_console_noise_decorator def test_handle_portfolio_domains(self): """Check portfolio association with domain information.""" self.run_create_federal_portfolio(agency_name="Test Federal Agency", parse_domains=True) @@ -1790,6 +1797,7 @@ class TestCreateFederalPortfolio(TestCase): self.assertEqual(self.domain_info.portfolio.federal_agency, self.federal_agency) self.assertEqual(self.domain_info.sub_organization.name, "Testorg") + @less_console_noise_decorator def test_handle_parse_both(self): """Ensure correct parsing of both requests and domains.""" self.run_create_federal_portfolio(agency_name="Test Federal Agency", parse_requests=True, parse_domains=True) @@ -1800,6 +1808,7 @@ class TestCreateFederalPortfolio(TestCase): self.assertIsNotNone(self.domain_info.portfolio) self.assertEqual(self.domain_request.portfolio, self.domain_info.portfolio) + @less_console_noise_decorator def test_command_error_parse_options(self): """Verify error when bad parse options are provided.""" # The command should enforce either --branch or --agency_name @@ -1821,6 +1830,7 @@ class TestCreateFederalPortfolio(TestCase): ): self.run_create_federal_portfolio(agency_name="test") + @less_console_noise_decorator def test_command_error_agency_not_found(self): """Check error handling for non-existent agency.""" expected_message = ( @@ -1830,6 +1840,7 @@ class TestCreateFederalPortfolio(TestCase): with self.assertRaisesRegex(CommandError, expected_message): self.run_create_federal_portfolio(agency_name="Non-existent Agency", parse_requests=True) + @less_console_noise_decorator def test_does_not_update_existing_portfolio(self): """Tests that an existing portfolio is not updated when""" # Create an existing portfolio @@ -1854,6 +1865,7 @@ class TestCreateFederalPortfolio(TestCase): self.assertEqual(existing_portfolio.notes, "Old notes") self.assertEqual(existing_portfolio.creator, self.user) + @less_console_noise_decorator def test_skip_existing_portfolios(self): """Tests the skip_existing_portfolios to ensure that it doesn't add suborgs, domain requests, and domain info.""" @@ -2294,6 +2306,7 @@ class TestRemovePortfolios(TestCase): Portfolio.objects.all().delete() User.objects.all().delete() + @less_console_noise_decorator @patch("registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no") def test_delete_unlisted_portfolios(self, mock_query_yes_no): """Test that portfolios not on the allowed list are deleted.""" @@ -2311,6 +2324,7 @@ class TestRemovePortfolios(TestCase): self.assertFalse(Portfolio.objects.filter(organization_name="Test with suborg").exists()) self.assertTrue(Portfolio.objects.filter(organization_name="Department of Veterans Affairs").exists()) + @less_console_noise_decorator @patch("registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no") def test_delete_entries_with_related_objects(self, mock_query_yes_no): """Test deletion with related objects being handled properly.""" @@ -2334,6 +2348,7 @@ class TestRemovePortfolios(TestCase): # Check that the portfolio was deleted self.assertFalse(Portfolio.objects.filter(organization_name="Test with orphaned objects").exists()) + @less_console_noise_decorator @patch("registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no") def test_delete_entries_with_suborganizations(self, mock_query_yes_no): """Test that suborganizations and their related objects are deleted along with the portfolio.""" diff --git a/src/registrar/tests/test_models.py b/src/registrar/tests/test_models.py index 4401b73e8..355f2e276 100644 --- a/src/registrar/tests/test_models.py +++ b/src/registrar/tests/test_models.py @@ -2100,7 +2100,7 @@ class TestDomainRequestIncomplete(TestCase): self.wizard = DomainRequestWizard() self.wizard._domain_request = self.domain_request self.wizard.request = Mock(user=self.user, session={}) - self.wizard.kwargs = {"id": self.domain_request.id} + self.wizard.kwargs = {"domain_request_pk": self.domain_request.id} # We use both of these flags in the test. In the normal app these are generated normally. # The alternative syntax is adding the decorator to each test. diff --git a/src/registrar/tests/test_url_auth.py b/src/registrar/tests/test_url_auth.py index 1cd2d1384..17b13c233 100644 --- a/src/registrar/tests/test_url_auth.py +++ b/src/registrar/tests/test_url_auth.py @@ -18,6 +18,9 @@ from .common import less_console_noise # request on the view. SAMPLE_KWARGS = { "app_label": "registrar", + "domain_pk": "1", + "domain_request_pk": "1", + "domain_invitation_pk": "1", "pk": "1", "id": "1", "content_type_id": "2", diff --git a/src/registrar/tests/test_views_domain.py b/src/registrar/tests/test_views_domain.py index b84d284d8..d9aac8178 100644 --- a/src/registrar/tests/test_views_domain.py +++ b/src/registrar/tests/test_views_domain.py @@ -175,7 +175,7 @@ class TestDomainPermissions(TestWithDomainPermissions): "domain-security-email", ]: with self.subTest(view_name=view_name): - response = self.client.get(reverse(view_name, kwargs={"pk": self.domain.id})) + response = self.client.get(reverse(view_name, kwargs={"domain_pk": self.domain.id})) self.assertEqual(response.status_code, 302) @less_console_noise_decorator @@ -194,7 +194,7 @@ class TestDomainPermissions(TestWithDomainPermissions): "domain-security-email", ]: with self.subTest(view_name=view_name): - response = self.client.get(reverse(view_name, kwargs={"pk": self.domain.id})) + response = self.client.get(reverse(view_name, kwargs={"domain_pk": self.domain.id})) self.assertEqual(response.status_code, 403) @less_console_noise_decorator @@ -218,7 +218,7 @@ class TestDomainPermissions(TestWithDomainPermissions): self.domain_deleted, ]: with self.subTest(view_name=view_name, domain=domain): - response = self.client.get(reverse(view_name, kwargs={"pk": domain.id})) + response = self.client.get(reverse(view_name, kwargs={"domain_pk": domain.id})) self.assertEqual(response.status_code, 403) @@ -271,20 +271,20 @@ class TestDomainDetail(TestDomainOverview): with less_console_noise(): self.user.status = User.RESTRICTED self.user.save() - response = self.client.get(reverse("domain", kwargs={"pk": self.domain.id})) + response = self.client.get(reverse("domain", kwargs={"domain_pk": self.domain.id})) self.assertEqual(response.status_code, 403) def test_domain_detail_allowed_for_on_hold(self): """Test that the domain overview page displays for on hold domain""" with less_console_noise(): # View domain overview page - detail_page = self.client.get(reverse("domain", kwargs={"pk": self.domain_on_hold.id})) + detail_page = self.client.get(reverse("domain", kwargs={"domain_pk": self.domain_on_hold.id})) self.assertNotContains(detail_page, "Edit") def test_domain_detail_see_just_nameserver(self): with less_console_noise(): # View nameserver on Domain Overview page - detail_page = self.app.get(reverse("domain", kwargs={"pk": self.domain_just_nameserver.id})) + detail_page = self.app.get(reverse("domain", kwargs={"domain_pk": self.domain_just_nameserver.id})) self.assertContains(detail_page, "justnameserver.com") self.assertContains(detail_page, "ns1.justnameserver.com") @@ -293,7 +293,7 @@ class TestDomainDetail(TestDomainOverview): def test_domain_detail_see_nameserver_and_ip(self): with less_console_noise(): # View nameserver on Domain Overview page - detail_page = self.app.get(reverse("domain", kwargs={"pk": self.domain_with_ip.id})) + detail_page = self.app.get(reverse("domain", kwargs={"domain_pk": self.domain_with_ip.id})) self.assertContains(detail_page, "nameserverwithip.gov") @@ -321,7 +321,7 @@ class TestDomainDetail(TestDomainOverview): session["analyst_action_location"] = self.domain_no_information.id session.save() - detail_page = self.client.get(reverse("domain", kwargs={"pk": self.domain_no_information.id})) + detail_page = self.client.get(reverse("domain", kwargs={"domain_pk": self.domain_no_information.id})) self.assertContains(detail_page, "noinformation.gov") self.assertContains(detail_page, "Domain missing domain information") @@ -341,7 +341,7 @@ class TestDomainDetail(TestDomainOverview): session["analyst_action_location"] = self.domain.id session.save() - detail_page = self.client.get(reverse("domain", kwargs={"pk": self.domain.id})) + detail_page = self.client.get(reverse("domain", kwargs={"domain_pk": self.domain.id})) self.assertNotContains( detail_page, "If you need to make updates, contact one of the listed domain managers." @@ -487,7 +487,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): ): self.assertEquals(self.domain_to_renew.state, Domain.State.UNKNOWN) detail_page = self.client.get( - reverse("domain", kwargs={"pk": self.domain_to_renew.id}), + reverse("domain", kwargs={"domain_pk": self.domain_to_renew.id}), ) self.assertContains(detail_page, "Expiring soon") @@ -530,7 +530,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): Domain, "is_expired", self.custom_is_expired_false ): detail_page = self.client.get( - reverse("domain", kwargs={"pk": domain_to_renew2.id}), + reverse("domain", kwargs={"domain_pk": domain_to_renew2.id}), ) self.assertContains(detail_page, "Contact one of the listed domain managers to renew the domain.") @@ -551,7 +551,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): Domain, "is_expired", self.custom_is_expired_false ): detail_page = self.client.get( - reverse("domain", kwargs={"pk": domain_to_renew3.id}), + reverse("domain", kwargs={"domain_pk": domain_to_renew3.id}), ) self.assertContains(detail_page, "Renew to maintain access") @@ -565,7 +565,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): ): # Grab the detail page detail_page = self.client.get( - reverse("domain", kwargs={"pk": self.domain_to_renew.id}), + reverse("domain", kwargs={"domain_pk": self.domain_to_renew.id}), ) # Make sure we see the link as a domain manager @@ -575,7 +575,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): self.assertContains(detail_page, "Renewal form") # Grab link to the renewal page - renewal_form_url = reverse("domain-renewal", kwargs={"pk": self.domain_to_renew.id}) + renewal_form_url = reverse("domain-renewal", kwargs={"domain_pk": self.domain_to_renew.id}) self.assertContains(detail_page, f'href="{renewal_form_url}"') # Simulate clicking the link @@ -595,7 +595,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): ): # Grab the detail page detail_page = self.client.get( - reverse("domain", kwargs={"pk": self.domain_to_renew.id}), + reverse("domain", kwargs={"domain_pk": self.domain_to_renew.id}), ) # Make sure we see the link as a domain manager @@ -605,7 +605,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): self.assertContains(detail_page, "Renewal form") # Grab link to the renewal page - renewal_form_url = reverse("domain-renewal", kwargs={"pk": self.domain_to_renew.id}) + renewal_form_url = reverse("domain-renewal", kwargs={"domain_pk": self.domain_to_renew.id}) self.assertContains(detail_page, f'href="{renewal_form_url}"') # Simulate clicking the link @@ -620,7 +620,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): Your Profile portion of the Renewal Form.""" with less_console_noise(): # Start on the Renewal page for the domain - renewal_page = self.app.get(reverse("domain-renewal", kwargs={"pk": self.domain_with_ip.id})) + renewal_page = self.app.get(reverse("domain-renewal", kwargs={"domain_pk": self.domain_with_ip.id})) # Verify we see "Your contact information" on the renewal form self.assertContains(renewal_page, "Your contact information") @@ -640,7 +640,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): Security Email portion of the Renewal Form.""" with less_console_noise(): # Start on the Renewal page for the domain - renewal_page = self.app.get(reverse("domain-renewal", kwargs={"pk": self.domain_with_ip.id})) + renewal_page = self.app.get(reverse("domain-renewal", kwargs={"domain_pk": self.domain_with_ip.id})) # Verify we see "Security email" on the renewal form self.assertContains(renewal_page, "Security email") @@ -649,7 +649,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): self.assertContains(renewal_page, "We strongly recommend that you provide a security email.") # Verify that the "Edit" button for Security email is there and links to correct URL - edit_button_url = reverse("domain-security-email", kwargs={"pk": self.domain_with_ip.id}) + edit_button_url = reverse("domain-security-email", kwargs={"domain_pk": self.domain_with_ip.id}) self.assertContains(renewal_page, f'href="{edit_button_url}"') # Simulate clicking on edit button @@ -663,13 +663,13 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): Domain Manager portion of the Renewal Form.""" with less_console_noise(): # Start on the Renewal page for the domain - renewal_page = self.app.get(reverse("domain-renewal", kwargs={"pk": self.domain_with_ip.id})) + renewal_page = self.app.get(reverse("domain-renewal", kwargs={"domain_pk": self.domain_with_ip.id})) # Verify we see "Domain managers" on the renewal form self.assertContains(renewal_page, "Domain managers") # Verify that the "Edit" button for Domain managers is there and links to correct URL - edit_button_url = reverse("domain-users", kwargs={"pk": self.domain_with_ip.id}) + edit_button_url = reverse("domain-users", kwargs={"domain_pk": self.domain_with_ip.id}) self.assertContains(renewal_page, f'href="{edit_button_url}"') # Simulate clicking on edit button @@ -683,7 +683,7 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): to access /renewal and that it should receive a 403.""" with less_console_noise(): # Start on the Renewal page for the domain - renewal_page = self.client.get(reverse("domain-renewal", kwargs={"pk": self.domain_not_expiring.id})) + renewal_page = self.client.get(reverse("domain-renewal", kwargs={"domain_pk": self.domain_not_expiring.id})) self.assertEqual(renewal_page.status_code, 403) @override_flag("domain_renewal", active=True) @@ -692,14 +692,14 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): with patch.object(Domain, "is_expired", self.custom_is_expired_true), patch.object( Domain, "is_expired", self.custom_is_expired_true ): - renewal_page = self.client.get(reverse("domain-renewal", kwargs={"pk": self.domain_no_domain_manager.id})) + renewal_page = self.client.get(reverse("domain-renewal", kwargs={"domain_pk": self.domain_no_domain_manager.id})) self.assertEqual(renewal_page.status_code, 403) @override_flag("domain_renewal", active=True) def test_ack_checkbox_not_checked(self): """If user don't check the checkbox, user should receive an error message.""" # Grab the renewal URL - renewal_url = reverse("domain-renewal", kwargs={"pk": self.domain_with_ip.id}) + renewal_url = reverse("domain-renewal", kwargs={"domain_pk": self.domain_with_ip.id}) # Test that the checkbox is not checked response = self.client.post(renewal_url, data={"submit_button": "next"}) @@ -713,17 +713,17 @@ class TestDomainDetailDomainRenewal(TestDomainOverview): user should be redirected Domain Over page with an updated by 1 year expiration date""" # Grab the renewal URL with patch.object(Domain, "renew_domain", self.custom_renew_domain): - renewal_url = reverse("domain-renewal", kwargs={"pk": self.domain_with_ip.id}) + renewal_url = reverse("domain-renewal", kwargs={"domain_pk": self.domain_with_ip.id}) # Click the check, and submit response = self.client.post(renewal_url, data={"is_policy_acknowledged": "on", "submit_button": "next"}) # Check that it redirects after a successfully submits - self.assertRedirects(response, reverse("domain", kwargs={"pk": self.domain_with_ip.id})) + self.assertRedirects(response, reverse("domain", kwargs={"domain_pk": self.domain_with_ip.id})) # Check for the updated expiration formatted_new_expiration_date = self.expiration_date_one_year_out().strftime("%b. %-d, %Y") - redirect_response = self.client.get(reverse("domain", kwargs={"pk": self.domain_with_ip.id}), follow=True) + redirect_response = self.client.get(reverse("domain", kwargs={"domain_pk": self.domain_with_ip.id}), follow=True) self.assertContains(redirect_response, formatted_new_expiration_date) @@ -766,7 +766,7 @@ class TestDomainManagers(TestDomainOverview): @less_console_noise_decorator def test_domain_managers(self): - response = self.client.get(reverse("domain-users", kwargs={"pk": self.domain.id})) + response = self.client.get(reverse("domain-users", kwargs={"domain_pk": self.domain.id})) self.assertContains(response, "Domain managers") self.assertContains(response, "Add a domain manager") # assert that the non-portfolio view contains Role column and doesn't contain Admin @@ -777,7 +777,7 @@ class TestDomainManagers(TestDomainOverview): @less_console_noise_decorator @override_flag("organization_feature", active=True) def test_domain_managers_portfolio_view(self): - response = self.client.get(reverse("domain-users", kwargs={"pk": self.domain.id})) + response = self.client.get(reverse("domain-users", kwargs={"domain_pk": self.domain.id})) self.assertContains(response, "Domain managers") self.assertContains(response, "Add a domain manager") # assert that the portfolio view doesn't contain Role column and does contain Admin @@ -787,7 +787,7 @@ class TestDomainManagers(TestDomainOverview): @less_console_noise_decorator def test_domain_user_add(self): - response = self.client.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + response = self.client.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) self.assertContains(response, "Add a domain manager") @less_console_noise_decorator @@ -796,7 +796,7 @@ class TestDomainManagers(TestDomainOverview): """Adding an existing user works.""" get_user_model().objects.get_or_create(email="mayor@igorville.gov") user = User.objects.filter(email="mayor@igorville.gov").first() - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = "mayor@igorville.gov" @@ -816,7 +816,7 @@ class TestDomainManagers(TestDomainOverview): self.assertEqual(success_result.status_code, 302) self.assertEqual( success_result["Location"], - reverse("domain-users", kwargs={"pk": self.domain.id}), + reverse("domain-users", kwargs={"domain_pk": self.domain.id}), ) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -832,7 +832,7 @@ class TestDomainManagers(TestDomainOverview): """Adding an existing user works and sends portfolio invitation when user is not member of portfolio.""" get_user_model().objects.get_or_create(email="mayor@igorville.gov") - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = "mayor@igorville.gov" @@ -844,7 +844,7 @@ class TestDomainManagers(TestDomainOverview): self.assertEqual(success_result.status_code, 302) self.assertEqual( success_result["Location"], - reverse("domain-users", kwargs={"pk": self.domain.id}), + reverse("domain-users", kwargs={"domain_pk": self.domain.id}), ) # Verify that the invitation emails were sent @@ -889,7 +889,7 @@ class TestDomainManagers(TestDomainOverview): self, mock_send_domain_email, mock_send_portfolio_email ): """Adding an email not associated with a user works and sends portfolio invitation.""" - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = "notauser@igorville.gov" @@ -901,7 +901,7 @@ class TestDomainManagers(TestDomainOverview): self.assertEqual(success_result.status_code, 302) self.assertEqual( success_result["Location"], - reverse("domain-users", kwargs={"pk": self.domain.id}), + reverse("domain-users", kwargs={"domain_pk": self.domain.id}), ) # Verify that the invitation emails were sent @@ -940,7 +940,7 @@ class TestDomainManagers(TestDomainOverview): ): """Adding an email not associated with a user works and sends portfolio invitation, and when domain managers email(s) fail to send, assert proper warning displayed.""" - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = "notauser@igorville.gov" @@ -954,7 +954,7 @@ class TestDomainManagers(TestDomainOverview): self.assertEqual(success_result.status_code, 302) self.assertEqual( success_result["Location"], - reverse("domain-users", kwargs={"pk": self.domain.id}), + reverse("domain-users", kwargs={"domain_pk": self.domain.id}), ) # Verify that the invitation emails were sent @@ -979,7 +979,7 @@ class TestDomainManagers(TestDomainOverview): UserPortfolioPermission.objects.get_or_create( user=other_user, portfolio=self.portfolio, roles=[UserPortfolioRoleChoices.ORGANIZATION_ADMIN] ) - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = "mayor@igorville.gov" @@ -991,7 +991,7 @@ class TestDomainManagers(TestDomainOverview): self.assertEqual(success_result.status_code, 302) self.assertEqual( success_result["Location"], - reverse("domain-users", kwargs={"pk": self.domain.id}), + reverse("domain-users", kwargs={"domain_pk": self.domain.id}), ) # Verify that the invitation emails were sent @@ -1027,7 +1027,7 @@ class TestDomainManagers(TestDomainOverview): user is not member of portfolio and send raises an error.""" mock_send_portfolio_email.side_effect = EmailSendingError("Failed to send email.") get_user_model().objects.get_or_create(email="mayor@igorville.gov") - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = "mayor@igorville.gov" @@ -1039,7 +1039,7 @@ class TestDomainManagers(TestDomainOverview): self.assertEqual(success_result.status_code, 302) self.assertEqual( success_result["Location"], - reverse("domain-users", kwargs={"pk": self.domain.id}), + reverse("domain-users", kwargs={"domain_pk": self.domain.id}), ) # Verify that the invitation emails were sent @@ -1070,7 +1070,7 @@ class TestDomainManagers(TestDomainOverview): """Removing a domain manager sends notification email to other domain managers.""" self.manager, _ = User.objects.get_or_create(email="mayor@igorville.com", first_name="Hello", last_name="World") self.manager_domain_permission, _ = UserDomainRole.objects.get_or_create(user=self.manager, domain=self.domain) - self.client.post(reverse("domain-user-delete", kwargs={"pk": self.domain.id, "user_pk": self.manager.id})) + self.client.post(reverse("domain-user-delete", kwargs={"domain_pk": self.domain.id, "user_pk": self.manager.id})) # Verify that the notification emails were sent to domain manager mock_send_templated_email.assert_called_once_with( @@ -1094,7 +1094,7 @@ class TestDomainManagers(TestDomainOverview): self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain) - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = email_address self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -1127,7 +1127,7 @@ class TestDomainManagers(TestDomainOverview): self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain) - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = caps_email_address self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -1159,7 +1159,7 @@ class TestDomainManagers(TestDomainOverview): mock_client = MagicMock() mock_client_instance = mock_client.return_value with boto3_mocking.clients.handler_for("sesv2", mock_client): - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = email_address self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -1187,7 +1187,7 @@ class TestDomainManagers(TestDomainOverview): mock_client_instance = mock_client.return_value with boto3_mocking.clients.handler_for("sesv2", mock_client): - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = email_address self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -1226,7 +1226,7 @@ class TestDomainManagers(TestDomainOverview): mock_client_instance = mock_client.return_value with boto3_mocking.clients.handler_for("sesv2", mock_client): - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = email_address self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -1270,7 +1270,7 @@ class TestDomainManagers(TestDomainOverview): mock_client_instance = mock_client.return_value with boto3_mocking.clients.handler_for("sesv2", mock_client): - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = email_address self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -1301,7 +1301,7 @@ class TestDomainManagers(TestDomainOverview): email_address = "mayor" self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain) - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = email_address self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -1325,7 +1325,7 @@ class TestDomainManagers(TestDomainOverview): self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain) with patch("django.contrib.messages.error") as mock_error: - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] add_page.form["email"] = email_address self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -1344,7 +1344,7 @@ class TestDomainManagers(TestDomainOverview): """Posting to the delete view deletes an invitation.""" email_address = "mayor@igorville.gov" invitation, _ = DomainInvitation.objects.get_or_create(domain=self.domain, email=email_address) - self.client.post(reverse("invitation-cancel", kwargs={"pk": invitation.id})) + self.client.post(reverse("invitation-cancel", kwargs={"domain_invitation_pk": invitation.id})) invitation = DomainInvitation.objects.get(id=invitation.id) self.assertEqual(invitation.status, DomainInvitation.DomainInvitationStatus.CANCELED) @@ -1355,7 +1355,7 @@ class TestDomainManagers(TestDomainOverview): invitation, _ = DomainInvitation.objects.get_or_create( domain=self.domain, email=email_address, status=DomainInvitation.DomainInvitationStatus.RETRIEVED ) - response = self.client.post(reverse("invitation-cancel", kwargs={"pk": invitation.id}), follow=True) + response = self.client.post(reverse("invitation-cancel", kwargs={"domain_invitation_pk": invitation.id}), follow=True) # Assert that an error message is displayed to the user self.assertContains(response, f"Invitation to {email_address} has already been retrieved.") # Assert that the Cancel link (form) is not displayed @@ -1375,7 +1375,7 @@ class TestDomainManagers(TestDomainOverview): self.client.force_login(other_user) mock_client = MagicMock() with boto3_mocking.clients.handler_for("sesv2", mock_client): - result = self.client.post(reverse("invitation-cancel", kwargs={"pk": invitation.id})) + result = self.client.post(reverse("invitation-cancel", kwargs={"domain_invitation_pk": invitation.id})) self.assertEqual(result.status_code, 403) @@ -1392,7 +1392,7 @@ class TestDomainManagers(TestDomainOverview): title = "title" User.objects.filter(email=email_address).delete() - add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id})) + add_page = self.app.get(reverse("domain-users-add", kwargs={"domain_pk": self.domain.id})) self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain) @@ -1430,7 +1430,7 @@ class TestDomainManagers(TestDomainOverview): ) UserDomainRole.objects.create(user=new_user_2, domain=self.domain, role=UserDomainRole.Roles.MANAGER) response = self.client.post( - reverse("domain-user-delete", kwargs={"pk": self.domain.id, "user_pk": new_user.id}), follow=True + reverse("domain-user-delete", kwargs={"domain_pk": self.domain.id, "user_pk": new_user.id}), follow=True ) # Assert that a success message is displayed to the user self.assertContains(response, f"Removed {email_address} as a manager for this domain.") @@ -1444,7 +1444,7 @@ class TestDomainManagers(TestDomainOverview): """Posting to the delete view attempts to delete a user domain role when there is only one manager.""" # self.user is the only domain manager, so attempt to delete it response = self.client.post( - reverse("domain-user-delete", kwargs={"pk": self.domain.id, "user_pk": self.user.id}), follow=True + reverse("domain-user-delete", kwargs={"domain_pk": self.domain.id, "user_pk": self.user.id}), follow=True ) # Assert that an error message is displayed to the user self.assertContains(response, "Domains must have at least one domain manager.") @@ -1461,7 +1461,7 @@ class TestDomainManagers(TestDomainOverview): new_user = User.objects.create(email=email_address, username="mayor") UserDomainRole.objects.create(user=new_user, domain=self.domain, role=UserDomainRole.Roles.MANAGER) response = self.client.post( - reverse("domain-user-delete", kwargs={"pk": self.domain.id, "user_pk": self.user.id}), follow=True + reverse("domain-user-delete", kwargs={"domain_pk": self.domain.id, "user_pk": self.user.id}), follow=True ) # Assert that a success message is displayed to the user self.assertContains(response, f"You are no longer managing the domain {self.domain}.") @@ -1473,7 +1473,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): @less_console_noise_decorator def test_domain_nameservers(self): """Can load domain's nameservers page.""" - page = self.client.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + page = self.client.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) self.assertContains(page, "DNS name servers") @less_console_noise_decorator @@ -1483,7 +1483,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): Uses self.app WebTest because we need to interact with forms. """ # initial nameservers page has one server with two ips - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # attempt to submit the form with only one nameserver, should error @@ -1506,7 +1506,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): Uses self.app WebTest because we need to interact with forms. """ # initial nameservers page has one server with two ips - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # attempt to submit the form without two hosts, both subdomains, @@ -1531,7 +1531,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): Uses self.app WebTest because we need to interact with forms. """ # initial nameservers page has one server with two ips - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # attempt to submit the form without two hosts, both subdomains, @@ -1555,7 +1555,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): Uses self.app WebTest because we need to interact with forms. """ # initial nameservers page has one server with two ips - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # attempt to submit the form with duplicate host names of fake.host.com @@ -1583,7 +1583,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): valid_ip = "1.1. 1.1" valid_ip_2 = "2.2. 2.2" # have to throw an error in order to test that the whitespace has been stripped from ip - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # attempt to submit the form without one host and an ip with whitespace @@ -1597,7 +1597,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): self.assertEqual(result.status_code, 302) self.assertEqual( result["Location"], - reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id}), + reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id}), ) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) page = result.follow() @@ -1616,7 +1616,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): nameserver2 = "ns2.igorville.com" valid_ip = "127.0.0.1" # initial nameservers page has one server with two ips - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # attempt to submit the form without two hosts, both subdomains, @@ -1644,7 +1644,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): nameserver = "ns2.igorville.gov" invalid_ip = "123" # initial nameservers page has one server with two ips - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # attempt to submit the form without two hosts, both subdomains, @@ -1671,7 +1671,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): nameserver = "invalid-nameserver.gov" valid_ip = "123.2.45.111" # initial nameservers page has one server with two ips - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # attempt to submit the form without two hosts, both subdomains, @@ -1699,7 +1699,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): nameserver2 = "ns2.igorville.gov" valid_ip = "127.0.0.1" valid_ip_2 = "128.0.0.2" - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) nameservers_page.form["form-0-server"] = nameserver1 @@ -1711,7 +1711,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): self.assertEqual(result.status_code, 302) self.assertEqual( result["Location"], - reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id}), + reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id}), ) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) page = result.follow() @@ -1731,7 +1731,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): valid_ip = "" valid_ip_2 = "128.0.0.2" valid_ip_3 = "128.0.0.3" - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) nameservers_page.form["form-0-server"] = nameserver1 @@ -1746,7 +1746,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): self.assertEqual(result.status_code, 302) self.assertEqual( result["Location"], - reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id}), + reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id}), ) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) nameservers_page = result.follow() @@ -1772,7 +1772,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): self.assertEqual(result.status_code, 302) self.assertEqual( result["Location"], - reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id}), + reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id}), ) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) nameservers_page = result.follow() @@ -1797,7 +1797,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): valid_ip_3 = "" valid_ip_4 = "" nameservers_page = self.app.get( - reverse("domain-dns-nameservers", kwargs={"pk": self.domain_with_four_nameservers.id}) + reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain_with_four_nameservers.id}) ) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] @@ -1821,7 +1821,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): self.assertEqual(result.status_code, 302) self.assertEqual( result["Location"], - reverse("domain-dns-nameservers", kwargs={"pk": self.domain_with_four_nameservers.id}), + reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain_with_four_nameservers.id}), ) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) nameservers_page = result.follow() @@ -1833,7 +1833,7 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib): Uses self.app WebTest because we need to interact with forms. """ - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # first two nameservers are required, so if we empty one out we should @@ -1855,7 +1855,7 @@ class TestDomainSeniorOfficial(TestDomainOverview): @less_console_noise_decorator def test_domain_senior_official(self): """Can load domain's senior official page.""" - page = self.client.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) + page = self.client.get(reverse("domain-senior-official", kwargs={"domain_pk": self.domain.id})) self.assertContains(page, "Senior official", count=4) @less_console_noise_decorator @@ -1864,7 +1864,7 @@ class TestDomainSeniorOfficial(TestDomainOverview): self.domain_information.senior_official = Contact(first_name="Testy") self.domain_information.senior_official.save() self.domain_information.save() - page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) + page = self.app.get(reverse("domain-senior-official", kwargs={"domain_pk": self.domain.id})) self.assertContains(page, "Testy") @less_console_noise_decorator @@ -1876,7 +1876,7 @@ class TestDomainSeniorOfficial(TestDomainOverview): ) self.domain_information.senior_official.save() self.domain_information.save() - so_page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) + so_page = self.app.get(reverse("domain-senior-official", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) so_form = so_page.forms[0] @@ -1934,7 +1934,7 @@ class TestDomainSeniorOfficial(TestDomainOverview): self.domain_information.senior_official.save() self.domain_information.save() - so_page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) + so_page = self.app.get(reverse("domain-senior-official", kwargs={"domain_pk": self.domain.id})) self.assertContains(so_page, "Apple Tester") self.assertContains(so_page, "CIO") self.assertContains(so_page, "nobody@igorville.gov") @@ -1955,7 +1955,7 @@ class TestDomainSeniorOfficial(TestDomainOverview): self.domain_information.senior_official.save() self.domain_information.save() - so_page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) + so_page = self.app.get(reverse("domain-senior-official", kwargs={"domain_pk": self.domain.id})) self.assertContains(so_page, "Apple Tester") self.assertContains(so_page, "CIO") self.assertContains(so_page, "nobody@igorville.gov") @@ -1974,7 +1974,7 @@ class TestDomainSeniorOfficial(TestDomainOverview): self.domain_information.other_contacts.add(self.domain_information.senior_official) self.domain_information.save() # load the Senior Official in the web form - so_page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) + so_page = self.app.get(reverse("domain-senior-official", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) so_form = so_page.forms[0] @@ -2002,7 +2002,7 @@ class TestDomainOrganization(TestDomainOverview): @less_console_noise_decorator def test_domain_org_name_address(self): """Can load domain's org name and mailing address page.""" - page = self.client.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id})) + page = self.client.get(reverse("domain-org-name-address", kwargs={"domain_pk": self.domain.id})) # once on the sidebar, once in the page title, once as H1 self.assertContains(page, "/org-name-address") self.assertContains(page, "Organization name and mailing address") @@ -2013,7 +2013,7 @@ class TestDomainOrganization(TestDomainOverview): """Org name and address information appears on the page.""" self.domain_information.organization_name = "Town of Igorville" self.domain_information.save() - page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id})) + page = self.app.get(reverse("domain-org-name-address", kwargs={"domain_pk": self.domain.id})) self.assertContains(page, "Town of Igorville") @less_console_noise_decorator @@ -2021,7 +2021,7 @@ class TestDomainOrganization(TestDomainOverview): """Submitting changes works on the org name address page.""" self.domain_information.organization_name = "Town of Igorville" self.domain_information.save() - org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id})) + org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] org_name_page.form["organization_name"] = "Not igorville" @@ -2053,7 +2053,7 @@ class TestDomainOrganization(TestDomainOverview): self.assertEqual(self.domain_information.generic_org_type, tribal_org_type) - org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id})) + org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"domain_pk": self.domain.id})) form = org_name_page.forms[0] # Check the value of the input field @@ -2110,7 +2110,7 @@ class TestDomainOrganization(TestDomainOverview): self.assertEqual(self.domain_information.generic_org_type, fed_org_type) - org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id})) + org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"domain_pk": self.domain.id})) form = org_name_page.forms[0] # Check the value of the input field @@ -2172,7 +2172,7 @@ class TestDomainOrganization(TestDomainOverview): new_value = ("Department of State", "Department of State") self.client.post( - reverse("domain-org-name-address", kwargs={"pk": self.domain.id}), + reverse("domain-org-name-address", kwargs={"domain_pk": self.domain.id}), { "federal_agency": new_value, }, @@ -2214,7 +2214,7 @@ class TestDomainSuborganization(TestDomainOverview): self.assertEqual(self.domain_information.sub_organization, suborg) # Navigate to the suborganization page - page = self.app.get(reverse("domain-suborganization", kwargs={"pk": self.domain.id})) + page = self.app.get(reverse("domain-suborganization", kwargs={"domain_pk": self.domain.id})) # The page should contain the choices Vanilla and Chocolate self.assertContains(page, "Vanilla") @@ -2272,7 +2272,7 @@ class TestDomainSuborganization(TestDomainOverview): self.assertEqual(self.domain_information.sub_organization, suborg) # Navigate to the suborganization page - page = self.app.get(reverse("domain-suborganization", kwargs={"pk": self.domain.id})) + page = self.app.get(reverse("domain-suborganization", kwargs={"domain_pk": self.domain.id})) # The page should display the readonly option self.assertContains(page, "Vanilla") @@ -2311,7 +2311,7 @@ class TestDomainSuborganization(TestDomainOverview): self.user.refresh_from_db() # Navigate to the domain overview page - page = self.app.get(reverse("domain", kwargs={"pk": self.domain.id})) + page = self.app.get(reverse("domain", kwargs={"domain_pk": self.domain.id})) # Test for the title change self.assertContains(page, "Suborganization") @@ -2340,7 +2340,7 @@ class TestDomainSecurityEmail(TestDomainOverview): domain_contact, _ = Domain.objects.get_or_create(name="freeman.gov") # Add current user to this domain _ = UserDomainRole(user=self.user, domain=domain_contact, role="admin").save() - page = self.client.get(reverse("domain-security-email", kwargs={"pk": domain_contact.id})) + page = self.client.get(reverse("domain-security-email", kwargs={"domain_pk": domain_contact.id})) # Loads correctly self.assertContains(page, "Security email") @@ -2355,7 +2355,7 @@ class TestDomainSecurityEmail(TestDomainOverview): self.mockedSendFunction = self.mockSendPatch.start() self.mockedSendFunction.side_effect = self.mockSend - page = self.client.get(reverse("domain-security-email", kwargs={"pk": self.domain.id})) + page = self.client.get(reverse("domain-security-email", kwargs={"domain_pk": self.domain.id})) # Loads correctly self.assertContains(page, "Security email") @@ -2365,7 +2365,7 @@ class TestDomainSecurityEmail(TestDomainOverview): def test_domain_security_email(self): """Can load domain's security email page.""" with less_console_noise(): - page = self.client.get(reverse("domain-security-email", kwargs={"pk": self.domain.id})) + page = self.client.get(reverse("domain-security-email", kwargs={"domain_pk": self.domain.id})) self.assertContains(page, "Security email") def test_domain_security_email_form(self): @@ -2373,7 +2373,7 @@ class TestDomainSecurityEmail(TestDomainOverview): Uses self.app WebTest because we need to interact with forms. """ with less_console_noise(): - security_email_page = self.app.get(reverse("domain-security-email", kwargs={"pk": self.domain.id})) + security_email_page = self.app.get(reverse("domain-security-email", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] security_email_page.form["security_email"] = "mayor@igorville.gov" self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -2384,7 +2384,7 @@ class TestDomainSecurityEmail(TestDomainOverview): self.assertEqual(result.status_code, 302) self.assertEqual( result["Location"], - reverse("domain-security-email", kwargs={"pk": self.domain.id}), + reverse("domain-security-email", kwargs={"domain_pk": self.domain.id}), ) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -2427,7 +2427,7 @@ class TestDomainSecurityEmail(TestDomainOverview): ] for test_name, data, expected_message in test_cases: response = self.client.post( - reverse("domain-security-email", kwargs={"pk": self.domain.id}), + reverse("domain-security-email", kwargs={"domain_pk": self.domain.id}), data=data, follow=True, ) @@ -2455,7 +2455,7 @@ class TestDomainSecurityEmail(TestDomainOverview): management pages share the same permissions class""" self.user.status = User.RESTRICTED self.user.save() - response = self.client.get(reverse("domain", kwargs={"pk": self.domain.id})) + response = self.client.get(reverse("domain", kwargs={"domain_pk": self.domain.id})) self.assertEqual(response.status_code, 403) @@ -2467,7 +2467,7 @@ class TestDomainDNSSEC(TestDomainOverview): """DNSSEC overview page loads when domain has no DNSSEC data and shows a 'Enable DNSSEC' button.""" - page = self.client.get(reverse("domain-dns-dnssec", kwargs={"pk": self.domain.id})) + page = self.client.get(reverse("domain-dns-dnssec", kwargs={"domain_pk": self.domain.id})) self.assertContains(page, "Enable DNSSEC") @less_console_noise_decorator @@ -2475,7 +2475,7 @@ class TestDomainDNSSEC(TestDomainOverview): """DNSSEC overview page loads when domain has DNSSEC data and the template contains a button to disable DNSSEC.""" - page = self.client.get(reverse("domain-dns-dnssec", kwargs={"pk": self.domain_multdsdata.id})) + page = self.client.get(reverse("domain-dns-dnssec", kwargs={"domain_pk": self.domain_multdsdata.id})) self.assertContains(page, "Disable DNSSEC") # Prepare the data for the POST request @@ -2483,7 +2483,7 @@ class TestDomainDNSSEC(TestDomainOverview): "disable_dnssec": "Disable DNSSEC", } updated_page = self.client.post( - reverse("domain-dns-dnssec", kwargs={"pk": self.domain.id}), + reverse("domain-dns-dnssec", kwargs={"domain_pk": self.domain.id}), post_data, follow=True, ) @@ -2497,7 +2497,7 @@ class TestDomainDNSSEC(TestDomainOverview): """DNSSEC Add DS data page loads when there is no domain DNSSEC data and shows a button to Add new record""" - page = self.client.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dnssec_none.id})) + page = self.client.get(reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dnssec_none.id})) self.assertContains(page, "You have no DS data added") self.assertContains(page, "Add new record") @@ -2506,13 +2506,13 @@ class TestDomainDNSSEC(TestDomainOverview): """DNSSEC Add DS data page loads when there is domain DNSSEC DS data and shows the data""" - page = self.client.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dsdata.id})) + page = self.client.get(reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dsdata.id})) self.assertContains(page, "DS data record 1") @less_console_noise_decorator def test_ds_data_form_modal(self): """When user clicks on save, a modal pops up.""" - add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dsdata.id})) + add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dsdata.id})) # Assert that a hidden trigger for the modal does not exist. # This hidden trigger will pop on the page when certain condition are met: # 1) Initial form contained DS data, 2) All data is deleted and form is @@ -2521,7 +2521,7 @@ class TestDomainDNSSEC(TestDomainOverview): # Simulate a delete all data form_data = {} response = self.client.post( - reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dsdata.id}), + reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dsdata.id}), data=form_data, ) self.assertEqual(response.status_code, 200) # Adjust status code as needed @@ -2534,7 +2534,7 @@ class TestDomainDNSSEC(TestDomainOverview): Uses self.app WebTest because we need to interact with forms. """ - add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dsdata.id})) + add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dsdata.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) result = add_data_page.forms[0].submit() @@ -2542,7 +2542,7 @@ class TestDomainDNSSEC(TestDomainOverview): self.assertEqual(result.status_code, 302) self.assertEqual( result["Location"], - reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dsdata.id}), + reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dsdata.id}), ) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) page = result.follow() @@ -2554,7 +2554,7 @@ class TestDomainDNSSEC(TestDomainOverview): Uses self.app WebTest because we need to interact with forms. """ - add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dsdata.id})) + add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dsdata.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # all four form fields are required, so will test with each blank @@ -2577,7 +2577,7 @@ class TestDomainDNSSEC(TestDomainOverview): Uses self.app WebTest because we need to interact with forms. """ - add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dsdata.id})) + add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dsdata.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # first two nameservers are required, so if we empty one out we should @@ -2600,7 +2600,7 @@ class TestDomainDNSSEC(TestDomainOverview): Uses self.app WebTest because we need to interact with forms. """ - add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dsdata.id})) + add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dsdata.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # first two nameservers are required, so if we empty one out we should @@ -2623,7 +2623,7 @@ class TestDomainDNSSEC(TestDomainOverview): Uses self.app WebTest because we need to interact with forms. """ - add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dsdata.id})) + add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dsdata.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # first two nameservers are required, so if we empty one out we should @@ -2646,7 +2646,7 @@ class TestDomainDNSSEC(TestDomainOverview): Uses self.app WebTest because we need to interact with forms. """ - add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_dsdata.id})) + add_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain_dsdata.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # first two nameservers are required, so if we empty one out we should @@ -2700,7 +2700,7 @@ class TestDomainChangeNotifications(TestDomainOverview): self.domain_information.zipcode = "62052" self.domain_information.save() - org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id})) + org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] org_name_page.form["organization_name"] = "Not igorville" @@ -2741,7 +2741,7 @@ class TestDomainChangeNotifications(TestDomainOverview): self.domain_information.portfolio = portfolio self.domain_information.save() - org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id})) + org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] org_name_page.form["organization_name"] = "Not igorville" @@ -2768,7 +2768,7 @@ class TestDomainChangeNotifications(TestDomainOverview): self.domain_information.portfolio = portfolio self.domain_information.save() - org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id})) + org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] session = self.app.session @@ -2790,7 +2790,7 @@ class TestDomainChangeNotifications(TestDomainOverview): def test_notification_on_security_email_change(self): """Test that an email is sent when the security email is changed.""" - security_email_page = self.app.get(reverse("domain-security-email", kwargs={"pk": self.domain.id})) + security_email_page = self.app.get(reverse("domain-security-email", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] security_email_page.form["security_email"] = "new_security@example.com" @@ -2813,7 +2813,7 @@ class TestDomainChangeNotifications(TestDomainOverview): def test_notification_on_dnssec_enable(self): """Test that an email is sent when DNSSEC is enabled.""" - page = self.client.get(reverse("domain-dns-dnssec", kwargs={"pk": self.domain_multdsdata.id})) + page = self.client.get(reverse("domain-dns-dnssec", kwargs={"domain_pk": self.domain_multdsdata.id})) self.assertContains(page, "Disable DNSSEC") # Prepare the data for the POST request @@ -2823,7 +2823,7 @@ class TestDomainChangeNotifications(TestDomainOverview): with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class): updated_page = self.client.post( - reverse("domain-dns-dnssec", kwargs={"pk": self.domain.id}), + reverse("domain-dns-dnssec", kwargs={"domain_pk": self.domain.id}), post_data, follow=True, ) @@ -2846,7 +2846,7 @@ class TestDomainChangeNotifications(TestDomainOverview): def test_notification_on_ds_data_change(self): """Test that an email is sent when DS data is changed.""" - ds_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain.id})) + ds_data_page = self.app.get(reverse("domain-dns-dnssec-dsdata", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] # Add DS data @@ -2880,7 +2880,7 @@ class TestDomainChangeNotifications(TestDomainOverview): ) self.domain_information.save() - senior_official_page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) + senior_official_page = self.app.get(reverse("domain-senior-official", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] senior_official_page.form["first_name"] = "New" @@ -2917,7 +2917,7 @@ class TestDomainChangeNotifications(TestDomainOverview): self.domain_information.portfolio = portfolio self.domain_information.save() - senior_official_page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) + senior_official_page = self.app.get(reverse("domain-senior-official", kwargs={"domain_pk": self.domain.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] senior_official_page.form["first_name"] = "New" @@ -2936,7 +2936,7 @@ class TestDomainChangeNotifications(TestDomainOverview): def test_no_notification_when_dns_needed(self): """Test that an email is not sent when nameservers are changed while the state is DNS_NEEDED.""" - nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain_dns_needed.id})) + nameservers_page = self.app.get(reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain_dns_needed.id})) session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] # add nameservers diff --git a/src/registrar/views/domain.py b/src/registrar/views/domain.py index 7a76284a4..1f0285314 100644 --- a/src/registrar/views/domain.py +++ b/src/registrar/views/domain.py @@ -2,6 +2,7 @@ from datetime import date import logging import requests from django.contrib import messages +from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.messages.views import SuccessMessageMixin from django.http import HttpResponseRedirect from django.shortcuts import redirect, render, get_object_or_404 @@ -73,7 +74,7 @@ from django import forms logger = logging.getLogger(__name__) -class DomainBaseView(DetailView): +class DomainBaseView(PermissionRequiredMixin, DetailView): """ Base View for the Domain. Handles getting and setting the domain in session cache on GETs. Also provides methods for getting @@ -174,7 +175,6 @@ class DomainBaseView(DetailView): def in_editable_state(self, pk): """Is the domain in an editable state""" - requested_domain = None if Domain.objects.filter(id=pk).exists(): requested_domain = Domain.objects.get(id=pk) @@ -1240,7 +1240,7 @@ class DomainUsersView(DomainBaseView): """Domain managers page in the domain details.""" template_name = "domain_users.html" - + def get_context_data(self, **kwargs): """The initial value for the form (which is a formset here).""" context = super().get_context_data(**kwargs) diff --git a/src/registrar/views/utility/api_views.py b/src/registrar/views/utility/api_views.py index aedfa757a..fbbe72f01 100644 --- a/src/registrar/views/utility/api_views.py +++ b/src/registrar/views/utility/api_views.py @@ -1,6 +1,7 @@ import logging from django.http import JsonResponse from django.forms.models import model_to_dict +from registrar.decorators import IS_STAFF, grant_access from registrar.models import FederalAgency, SeniorOfficial, DomainRequest from django.contrib.admin.views.decorators import staff_member_required from django.contrib.auth.decorators import login_required @@ -11,8 +12,7 @@ from registrar.utility.constants import BranchChoices logger = logging.getLogger(__name__) -@login_required -@staff_member_required +@grant_access(IS_STAFF) def get_senior_official_from_federal_agency_json(request): """Returns federal_agency information as a JSON""" @@ -39,8 +39,7 @@ def get_senior_official_from_federal_agency_json(request): return JsonResponse({"error": "Senior Official not found"}, status=404) -@login_required -@staff_member_required +@grant_access(IS_STAFF) def get_portfolio_json(request): """Returns portfolio information as a JSON""" @@ -96,8 +95,7 @@ def get_portfolio_json(request): return JsonResponse(portfolio_dict) -@login_required -@staff_member_required +@grant_access(IS_STAFF) def get_suborganization_list_json(request): """Returns suborganization list information for a portfolio as a JSON""" @@ -119,8 +117,7 @@ def get_suborganization_list_json(request): return JsonResponse({"results": results, "pagination": {"more": False}}) -@login_required -@staff_member_required +@grant_access(IS_STAFF) def get_federal_and_portfolio_types_from_federal_agency_json(request): """Returns specific portfolio information as a JSON. Request must have both agency_name and organization_type.""" @@ -148,8 +145,7 @@ def get_federal_and_portfolio_types_from_federal_agency_json(request): return JsonResponse(response_data) -@login_required -@staff_member_required +@grant_access(IS_STAFF) def get_action_needed_email_for_user_json(request): """Returns a default action needed email for a given user""" @@ -173,8 +169,7 @@ def get_action_needed_email_for_user_json(request): return JsonResponse({"email": email}, status=200) -@login_required -@staff_member_required +@grant_access(IS_STAFF) def get_rejection_email_for_user_json(request): """Returns a default rejection email for a given user"""