Add unit tests + linting

This commit is contained in:
zandercymatics 2024-03-20 12:11:11 -06:00
parent b8b97245a4
commit 4830f5630f
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 31 additions and 23 deletions

View file

@ -33,6 +33,7 @@ def split_string(value, key):
"""
return value.split(key)
@register.simple_tag
def public_site_url(url_path):
"""Make a full URL for this path at our public site.

View file

@ -1220,14 +1220,14 @@ class TestDomainRequestAdmin(MockEppLib):
self.assertContains(response, value, count=1)
@less_console_noise_decorator
def test_other_contacts_readonly_has_link(self):
def test_other_contacts_has_readonly_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
)
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW)
# Get the other contact
other_contact = domain_request.other_contacts.all().first()
p = "userpass"
self.client.login(username="staffuser", password=p)
@ -1240,6 +1240,16 @@ class TestDomainRequestAdmin(MockEppLib):
self.assertEqual(response.status_code, 200)
self.assertContains(response, domain_request.requested_domain.name)
# Check that the page contains the url we expect
expected_href = reverse("admin:registrar_contact_change", args=[other_contact.id])
self.assertContains(response, expected_href)
# Check that the page contains the link we expect.
# Since the url is dynamic (populated by JS), we can test for its existence
# by checking for the end tag.
expected_url = f"Testy Tester</a>"
self.assertContains(response, expected_url)
@less_console_noise_decorator
def test_contact_fields_have_detail_table(self):
"""Tests if the contact fields have the detail table which displays title, email, and phone"""
@ -1247,8 +1257,8 @@ class TestDomainRequestAdmin(MockEppLib):
# Create fake creator
_creator = User.objects.create(
username="MrMeoward",
first_name = "Meoward",
last_name = "Jones",
first_name="Meoward",
last_name="Jones",
)
# Due to the relation between User <==> Contact,
@ -1259,10 +1269,7 @@ class TestDomainRequestAdmin(MockEppLib):
_creator.contact.save()
# Create a fake domain request
domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
user=_creator
)
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW, user=_creator)
p = "userpass"
self.client.login(username="staffuser", password=p)
@ -1279,7 +1286,6 @@ class TestDomainRequestAdmin(MockEppLib):
# Check for the header
# == Check for the creator == #
self.assertContains(response, "Meoward Jones")
# Check for the right title, email, and phone number in the response.
# We only need to check for the end tag
@ -1288,31 +1294,32 @@ class TestDomainRequestAdmin(MockEppLib):
# Field, expected value
("title", "Treat inspector</td>"),
("email", "meoward.jones@igorville.gov</td>"),
("phone", "(555) 123 12345</td>")
("phone", "(555) 123 12345</td>"),
]
self.assert_response_contains_distinct_values(response, expected_creator_fields)
# == Check for the submitter == #
self.assertContains(response, "Testy2 Tester2")
# Check for the field itself
self.assertContains(response, "Meoward Jones")
# == Check for the submitter == #
expected_submitter_fields = [
# Field, expected value
("title", "Admin Tester</td>"),
("email", "mayor@igorville.gov</td>"),
("phone", "(555) 555 5556</td>")
("phone", "(555) 555 5556</td>"),
]
self.assert_response_contains_distinct_values(response, expected_submitter_fields)
self.assertContains(response, "Testy2 Tester2")
# == Check for the authorizing_official == #
self.assertContains(response, "Testy Tester")
expected_ao_fields = [
# Field, expected value
("title", "Chief Tester</td>"),
("email", "testy@town.com</td>"),
("phone", "(555) 555 5555</td>")
("phone", "(555) 555 5555</td>"),
]
self.assert_response_contains_distinct_values(response, expected_ao_fields)
self.assertContains(response, "Testy Tester")
# Check for table titles. We only need to check for the end tag
# (Otherwise this test will fail if we change classes, etc)