wrote unit tests

This commit is contained in:
David Kennedy 2023-11-22 11:18:54 -05:00
parent 1efb7d23f3
commit 3ec910c37a
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B

View file

@ -1082,6 +1082,7 @@ class TestWithDomainPermissions(TestWithUser):
self.domain_with_ip, _ = Domain.objects.get_or_create(name="nameserverwithip.gov")
self.domain_just_nameserver, _ = Domain.objects.get_or_create(name="justnameserver.com")
self.domain_no_information, _ = Domain.objects.get_or_create(name="noinformation.gov")
self.domain_on_hold, _ = Domain.objects.get_or_create(name="on-hold.gov", state=Domain.State.ON_HOLD)
self.domain_dsdata, _ = Domain.objects.get_or_create(name="dnssec-dsdata.gov")
self.domain_multdsdata, _ = Domain.objects.get_or_create(name="dnssec-multdsdata.gov")
@ -1096,6 +1097,7 @@ class TestWithDomainPermissions(TestWithUser):
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_dnssec_none)
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_with_ip)
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_just_nameserver)
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_on_hold)
self.role, _ = UserDomainRole.objects.get_or_create(
user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER
@ -1124,6 +1126,9 @@ class TestWithDomainPermissions(TestWithUser):
domain=self.domain_just_nameserver,
role=UserDomainRole.Roles.MANAGER,
)
UserDomainRole.objects.get_or_create(
user=self.user, domain=self.domain_on_hold, role=UserDomainRole.Roles.MANAGER
)
def tearDown(self):
try:
@ -1204,6 +1209,15 @@ class TestDomainOverview(TestWithDomainPermissions, WebTest):
response = self.client.get(reverse("domain", kwargs={"pk": self.domain.id}))
self.assertEqual(response.status_code, 403)
def test_domain_overview_allowed_for_on_hold(self):
"""Test that the domain overview page displays for on hold domain"""
home_page = self.app.get("/")
self.assertContains(home_page, "on-hold.gov")
# View domain overview page
detail_page = self.client.get(reverse("domain", kwargs={"pk": self.domain_on_hold.id}))
self.assertNotContains(detail_page, "Edit")
def test_domain_see_just_nameserver(self):
home_page = self.app.get("/")
self.assertContains(home_page, "justnameserver.com")
@ -1258,6 +1272,19 @@ class TestDomainManagers(TestDomainOverview):
response = self.client.get(reverse("domain-users", kwargs={"pk": self.domain.id}))
self.assertContains(response, "Domain managers")
def test_domain_users_blocked_for_on_hold(self):
"""Test that the domain users page blocked for on hold domain"""
# attempt to view domain users page
with less_console_noise():
response = self.client.get(reverse("domain-users", kwargs={"pk": self.domain_on_hold.id}))
self.assertEqual(response.status_code, 403)
# attempt to view domain users add page
with less_console_noise():
response = self.client.get(reverse("domain-users-add", kwargs={"pk": self.domain_on_hold.id}))
self.assertEqual(response.status_code, 403)
def test_domain_managers_add_link(self):
"""Button to get to user add page works."""
management_page = self.app.get(reverse("domain-users", kwargs={"pk": self.domain.id}))
@ -1391,6 +1418,14 @@ class TestDomainNameservers(TestDomainOverview):
page = self.client.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain.id}))
self.assertContains(page, "DNS name servers")
def test_domain_nameservers_blocked_for_on_hold(self):
"""Test that the domain nameservers page blocked for on hold domain"""
# attempt to view domain nameservers page
with less_console_noise():
response = self.client.get(reverse("domain-dns-nameservers", kwargs={"pk": self.domain_on_hold.id}))
self.assertEqual(response.status_code, 403)
def test_domain_nameservers_form_submit_one_nameserver(self):
"""Nameserver form submitted with one nameserver throws error.
@ -1606,6 +1641,14 @@ class TestDomainAuthorizingOfficial(TestDomainOverview):
# once on the sidebar, once in the title
self.assertContains(page, "Authorizing official", count=2)
def test_domain_authorizing_official_blocked_for_on_hold(self):
"""Test that the domain authorizing official page blocked for on hold domain"""
# attempt to view domain authorizing official page
with less_console_noise():
response = self.client.get(reverse("domain-authorizing-official", kwargs={"pk": self.domain_on_hold.id}))
self.assertEqual(response.status_code, 403)
def test_domain_authorizing_official_content(self):
"""Authorizing official information appears on the page."""
self.domain_information.authorizing_official = Contact(first_name="Testy")
@ -1622,6 +1665,14 @@ class TestDomainOrganization(TestDomainOverview):
# once on the sidebar, once in the page title, once as H1
self.assertContains(page, "Organization name and mailing address", count=3)
def test_domain_org_name_blocked_for_on_hold(self):
"""Test that the domain org name page blocked for on hold domain"""
# attempt to view domain org name page
with less_console_noise():
response = self.client.get(reverse("domain-org-name-address", kwargs={"pk": self.domain_on_hold.id}))
self.assertEqual(response.status_code, 403)
def test_domain_org_name_address_content(self):
"""Org name and address information appears on the page."""
self.domain_information.organization_name = "Town of Igorville"
@ -1653,6 +1704,14 @@ class TestDomainContactInformation(TestDomainOverview):
page = self.client.get(reverse("domain-your-contact-information", kwargs={"pk": self.domain.id}))
self.assertContains(page, "Your contact information")
def test_domain_contact_information_blocked_for_on_hold(self):
"""Test that the domain contact information page blocked for on hold domain"""
# attempt to view domain contact information page
with less_console_noise():
response = self.client.get(reverse("domain-your-contact-information", kwargs={"pk": self.domain_on_hold.id}))
self.assertEqual(response.status_code, 403)
def test_domain_your_contact_information_content(self):
"""Logged-in user's contact information appears on the page."""
self.user.contact.first_name = "Testy"
@ -1678,6 +1737,14 @@ class TestDomainSecurityEmail(TestDomainOverview):
self.assertContains(page, "security@mail.gov")
self.mockSendPatch.stop()
def test_domain_security_email_blocked_for_on_hold(self):
"""Test that the domain security email page blocked for on hold domain"""
# attempt to view domain security email page
with less_console_noise():
response = self.client.get(reverse("domain-security-email", kwargs={"pk": self.domain_on_hold.id}))
self.assertEqual(response.status_code, 403)
def test_domain_security_email_no_security_contact(self):
"""Loads a domain with no defined security email.
We should not show the default."""
@ -1805,6 +1872,19 @@ class TestDomainDNSSEC(TestDomainOverview):
page = self.client.get(reverse("domain-dns-dnssec", kwargs={"pk": self.domain.id}))
self.assertContains(page, "Enable DNSSEC")
def test_domain_dnssec_blocked_for_on_hold(self):
"""Test that the domain dnssec page blocked for on hold domain"""
# attempt to view domain dnssec page
with less_console_noise():
response = self.client.get(reverse("domain-dns-dnssec", kwargs={"pk": self.domain_on_hold.id}))
self.assertEqual(response.status_code, 403)
# attempt to view domain dnssec dsdata page
with less_console_noise():
response = self.client.get(reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.domain_on_hold.id}))
self.assertEqual(response.status_code, 403)
def test_dnssec_page_loads_with_data_in_domain(self):
"""DNSSEC overview page loads when domain has DNSSEC data
and the template contains a button to disable DNSSEC."""