From c7124669aa88111fb8ef6be0049446874be0c8cd Mon Sep 17 00:00:00 2001 From: David Kennedy Date: Tue, 11 Mar 2025 18:55:15 -0400 Subject: [PATCH] updated tests --- src/registrar/tests/test_views_domain.py | 49 +++++++++++++----------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/registrar/tests/test_views_domain.py b/src/registrar/tests/test_views_domain.py index c2120b58f..62d463627 100644 --- a/src/registrar/tests/test_views_domain.py +++ b/src/registrar/tests/test_views_domain.py @@ -2547,8 +2547,8 @@ class TestDomainDNSSEC(TestDomainOverview): domain DNSSEC data and shows a button to Add new record""" 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") + self.assertEqual(page.status_code, 200) + self.assertContains(page, "Add DS record") @less_console_noise_decorator def test_ds_form_loads_with_ds_data(self): @@ -2556,26 +2556,8 @@ class TestDomainDNSSEC(TestDomainOverview): domain DNSSEC DS data and shows the data""" 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={"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 - # submitted. - self.assertNotContains(add_data_page, "Trigger Disable DNSSEC Modal") - # Simulate a delete all data - form_data = {} - response = self.client.post( - 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 - # Now check to see whether the JS trigger for the modal is present on the page - self.assertContains(response, "Trigger Disable DNSSEC Modal") + self.assertContains(page, "Add DS record") # assert add form is present + self.assertContains(page, "Action") # assert table is present @less_console_noise_decorator def test_ds_data_form_submits(self): @@ -2643,6 +2625,29 @@ class TestDomainDNSSEC(TestDomainOverview): result, str(DsDataError(code=DsDataErrorCodes.INVALID_KEYTAG_SIZE)), count=2, status_code=200 ) + @less_console_noise_decorator + def test_ds_data_form_invalid_keytag_chars(self): + """DS data form errors with invalid data (key tag not numeric) + + Uses self.app WebTest because we need to interact with forms. + """ + 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 + # get a form error + add_data_page.forms[0]["form-0-key_tag"] = "invalid" # not numeric + add_data_page.forms[0]["form-0-algorithm"] = "" + add_data_page.forms[0]["form-0-digest_type"] = "" + add_data_page.forms[0]["form-0-digest"] = "" + result = add_data_page.forms[0].submit() + # form submission was a post with an error, response should be a 200 + # error text appears twice, once at the top of the page, once around + # the field. + self.assertContains( + result, str(DsDataError(code=DsDataErrorCodes.INVALID_KEYTAG_CHARS)), count=2, status_code=200 + ) + @less_console_noise_decorator def test_ds_data_form_invalid_digest_chars(self): """DS data form errors with invalid data (digest contains non hexadecimal chars)