diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index fce279416..ef4d05e0b 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -1194,23 +1194,74 @@ class TestDomainRequestAdmin(MockEppLib): # Test that approved domain exists and equals requested domain self.assertEqual(domain_request.requested_domain.name, domain_request.approved_domain.name) + def assert_response_contains_distinct_values(self, response, expected_values): + """ + Asserts that each specified value appears exactly once in the response. + + This method iterates over a list of tuples, where each tuple contains a field name + and its expected value. It then performs an assertContains check for each value, + ensuring that each value appears exactly once in the response. + + Parameters: + - response: The HttpResponse object to inspect. + - expected_values: A list of tuples, where each tuple contains: + - field: The name of the field (used for subTest identification). + - value: The expected value to check for in the response. + + Example usage: + expected_values = [ + ("title", "Treat inspector"), + ("email", "meoward.jones@igorville.gov"), + ] + self.assert_response_contains_distinct_values(response, expected_values) + """ + for field, value in expected_values: + with self.subTest(field=field, expected_value=value): + self.assertContains(response, value, count=1) + + @less_console_noise_decorator + def test_other_contacts_readonly_has_link(self): + """Tests if the readonly other_contacts field has links""" + + # Create a fake domain request + domain_request = completed_domain_request( + status=DomainRequest.DomainRequestStatus.IN_REVIEW, + user=_creator + ) + + p = "userpass" + self.client.login(username="staffuser", password=p) + response = self.client.get( + "/admin/registrar/domainrequest/{}/change/".format(domain_request.pk), + follow=True, + ) + + # Make sure the page loaded, and that we're on the right page + self.assertEqual(response.status_code, 200) + self.assertContains(response, domain_request.requested_domain.name) + @less_console_noise_decorator - def test_creator_has_detail_table(self): - """Tests if the "creator" field has the detail table which displays title, email, and phone""" + def test_contact_fields_have_detail_table(self): + """Tests if the contact fields have the detail table which displays title, email, and phone""" # Create fake creator _creator = User.objects.create( username="MrMeoward", first_name = "Meoward", last_name = "Jones", - email="meoward.jones@igorville.gov", - phone="(555) 123 12345", - title="Treat inspector" ) + + # Due to the relation between User <==> Contact, + # the underlying contact has to be modified this way. + _creator.contact.email = "meoward.jones@igorville.gov" + _creator.contact.phone = "(555) 123 12345" + _creator.contact.title = "Treat inspector" + _creator.contact.save() + # Create a fake domain request domain_request = completed_domain_request( status=DomainRequest.DomainRequestStatus.IN_REVIEW, - creator=_creator + user=_creator ) p = "userpass" @@ -1227,29 +1278,53 @@ class TestDomainRequestAdmin(MockEppLib): # Check that the modal has the right content # Check for the header - # Check for the creator + # == Check for the creator == # self.assertContains(response, "Meoward Jones") - # Check that it is readonly - self.assertContains(response, "") - # Check for the right title, email, and phone number in the response - - # Title - self.assertContains(response, "Treat inspector") - - # Email - self.assertContains(response, "meoward.jones@igorville.gov") - - # Phone number - self.assertContains(response, "(555) 123 12345") - - # Check for table titles - - # Title. We only need to check for the end tag + # Check for the right title, email, and phone number in the response. + # We only need to check for the end tag # (Otherwise this test will fail if we change classes, etc) - self.assertContains(response, "Title") - self.assertContains(response, "Email") - self.assertContains(response, "Phone") + expected_creator_fields = [ + # Field, expected value + ("title", "Treat inspector"), + ("email", "meoward.jones@igorville.gov"), + ("phone", "(555) 123 12345") + ] + self.assert_response_contains_distinct_values(response, expected_creator_fields) + + # == Check for the submitter == # + self.assertContains(response, "Testy2 Tester2") + + expected_submitter_fields = [ + # Field, expected value + ("title", "Admin Tester"), + ("email", "mayor@igorville.gov"), + ("phone", "(555) 555 5556") + ] + self.assert_response_contains_distinct_values(response, expected_submitter_fields) + + # == Check for the authorizing_official == # + self.assertContains(response, "Testy Tester") + + expected_ao_fields = [ + # Field, expected value + ("title", "Chief Tester"), + ("email", "testy@town.com"), + ("phone", "(555) 555 5555") + ] + self.assert_response_contains_distinct_values(response, expected_ao_fields) + + # Check for table titles. We only need to check for the end tag + # (Otherwise this test will fail if we change classes, etc) + + # Title. Count=3 because this table appears on three records. + self.assertContains(response, "Title", count=3) + + # Email. Count=3 because this table appears on three records. + self.assertContains(response, "Email", count=3) + + # Phone. Count=3 because this table appears on three records. + self.assertContains(response, "Phone", count=3) def test_save_model_sets_restricted_status_on_user(self): with less_console_noise():