Unit tests for 13 name servers

This commit is contained in:
Rachid Mrad 2025-03-06 15:59:38 -05:00
parent 56c4b5381e
commit 02f2c1d086
No known key found for this signature in database
3 changed files with 87 additions and 2 deletions

View file

@ -5,8 +5,8 @@
{% block domain_content %} {% block domain_content %}
{# this is right after the messages block in the parent template. We use > not >= to account for the blank form. #} {# this is right after the messages block in the parent template. #}
{% if formset.total_form_count > formset.max_num %} {% if formset.initial|length >= formset.max_num %}
<div class="usa-alert usa-alert--info usa-alert--slim" role="alert"> <div class="usa-alert usa-alert--info usa-alert--slim" role="alert">
<div class="usa-alert__body"> <div class="usa-alert__body">
<p class="usa-alert__text"> <p class="usa-alert__text">

View file

@ -1471,6 +1471,47 @@ class MockEppLib(TestCase):
], ],
) )
infoDomainTwelveHosts = fakedEppObject(
"twelvenameserversdomain.gov",
cr_date=make_aware(datetime(2023, 5, 25, 19, 45, 35)),
contacts=[],
hosts=[
"ns1.my-nameserver-1.com",
"ns1.my-nameserver-2.com",
"ns1.cats-are-superior3.com",
"ns1.explosive-chicken-nuggets.com",
"ns5.example.com",
"ns6.example.com",
"ns7.example.com",
"ns8.example.com",
"ns9.example.com",
"ns10.example.com",
"ns11.example.com",
"ns12.example.com",
],
)
infoDomainThirteenHosts = fakedEppObject(
"thirteennameserversdomain.gov",
cr_date=make_aware(datetime(2023, 5, 25, 19, 45, 35)),
contacts=[],
hosts=[
"ns1.my-nameserver-1.com",
"ns1.my-nameserver-2.com",
"ns1.cats-are-superior3.com",
"ns1.explosive-chicken-nuggets.com",
"ns5.example.com",
"ns6.example.com",
"ns7.example.com",
"ns8.example.com",
"ns9.example.com",
"ns10.example.com",
"ns11.example.com",
"ns12.example.com",
"ns13.example.com",
],
)
infoDomainNoHost = fakedEppObject( infoDomainNoHost = fakedEppObject(
"my-nameserver.gov", "my-nameserver.gov",
cr_date=make_aware(datetime(2023, 5, 25, 19, 45, 35)), cr_date=make_aware(datetime(2023, 5, 25, 19, 45, 35)),
@ -1821,6 +1862,8 @@ class MockEppLib(TestCase):
"freeman.gov": (self.InfoDomainWithContacts, None), "freeman.gov": (self.InfoDomainWithContacts, None),
"threenameserversdomain.gov": (self.infoDomainThreeHosts, None), "threenameserversdomain.gov": (self.infoDomainThreeHosts, None),
"fournameserversdomain.gov": (self.infoDomainFourHosts, None), "fournameserversdomain.gov": (self.infoDomainFourHosts, None),
"twelvenameserversdomain.gov": (self.infoDomainTwelveHosts, None),
"thirteennameserversdomain.gov": (self.infoDomainThirteenHosts, None),
"defaultsecurity.gov": (self.InfoDomainWithDefaultSecurityContact, None), "defaultsecurity.gov": (self.InfoDomainWithDefaultSecurityContact, None),
"adomain2.gov": (self.InfoDomainWithVerisignSecurityContact, None), "adomain2.gov": (self.InfoDomainWithVerisignSecurityContact, None),
"defaulttechnical.gov": (self.InfoDomainWithDefaultTechnicalContact, None), "defaulttechnical.gov": (self.InfoDomainWithDefaultTechnicalContact, None),

View file

@ -87,12 +87,16 @@ class TestWithDomainPermissions(TestWithUser):
self.domain_dnssec_none, _ = Domain.objects.get_or_create(name="dnssec-none.gov") self.domain_dnssec_none, _ = Domain.objects.get_or_create(name="dnssec-none.gov")
self.domain_with_three_nameservers, _ = Domain.objects.get_or_create(name="threenameserversdomain.gov") self.domain_with_three_nameservers, _ = Domain.objects.get_or_create(name="threenameserversdomain.gov")
self.domain_with_four_nameservers, _ = Domain.objects.get_or_create(name="fournameserversdomain.gov") self.domain_with_four_nameservers, _ = Domain.objects.get_or_create(name="fournameserversdomain.gov")
self.domain_with_twelve_nameservers, _ = Domain.objects.get_or_create(name="twelvenameserversdomain.gov")
self.domain_with_thirteen_nameservers, _ = Domain.objects.get_or_create(name="thirteennameserversdomain.gov")
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain) self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_dsdata) DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_dsdata)
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_multdsdata) DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_multdsdata)
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_dnssec_none) 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_thirteen_nameservers)
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_with_twelve_nameservers)
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_with_four_nameservers) DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_with_four_nameservers)
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_with_three_nameservers) DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_with_three_nameservers)
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_with_ip) DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_with_ip)
@ -132,6 +136,16 @@ class TestWithDomainPermissions(TestWithUser):
domain=self.domain_with_four_nameservers, domain=self.domain_with_four_nameservers,
role=UserDomainRole.Roles.MANAGER, role=UserDomainRole.Roles.MANAGER,
) )
UserDomainRole.objects.get_or_create(
user=self.user,
domain=self.domain_with_twelve_nameservers,
role=UserDomainRole.Roles.MANAGER,
)
UserDomainRole.objects.get_or_create(
user=self.user,
domain=self.domain_with_thirteen_nameservers,
role=UserDomainRole.Roles.MANAGER,
)
UserDomainRole.objects.get_or_create( UserDomainRole.objects.get_or_create(
user=self.user, user=self.user,
domain=self.domain_with_ip, domain=self.domain_with_ip,
@ -1890,6 +1904,34 @@ class TestDomainNameservers(TestDomainOverview, MockEppLib):
nameservers_page = result.follow() nameservers_page = result.follow()
self.assertContains(nameservers_page, "The name servers for this domain have been updated") self.assertContains(nameservers_page, "The name servers for this domain have been updated")
@less_console_noise_decorator
def test_domain_nameservers_12_entries(self):
"""Nameserver form does not present info alert when 12 enrties."""
nameservers_page = self.app.get(
reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain_with_twelve_nameservers.id})
)
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
self.assertNotContains(
nameservers_page, "Youve reached the maximum amount of allowed name server records (13)."
)
@less_console_noise_decorator
def test_domain_nameservers_13_entries(self):
"""Nameserver form present3 info alert when 13 enrties."""
nameservers_page = self.app.get(
reverse("domain-dns-nameservers", kwargs={"domain_pk": self.domain_with_thirteen_nameservers.id})
)
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
self.assertContains(nameservers_page, "Youve reached the maximum amount of allowed name server records (13).")
@less_console_noise_decorator @less_console_noise_decorator
def test_domain_nameservers_form_invalid(self): def test_domain_nameservers_form_invalid(self):
"""Nameserver form does not submit with invalid data. """Nameserver form does not submit with invalid data.