mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-14 15:05:14 +02:00
New test cases
This commit is contained in:
parent
ed36fc6e3b
commit
98d940386b
5 changed files with 167 additions and 34 deletions
|
@ -896,6 +896,7 @@ class DomainInformationAdmin(ListHeaderAdmin):
|
||||||
"no_other_contacts_rationale",
|
"no_other_contacts_rationale",
|
||||||
"anything_else",
|
"anything_else",
|
||||||
"is_policy_acknowledged",
|
"is_policy_acknowledged",
|
||||||
|
"other_contacts",
|
||||||
]
|
]
|
||||||
|
|
||||||
# For each filter_horizontal, init in admin js extendFilterHorizontalWidgets
|
# For each filter_horizontal, init in admin js extendFilterHorizontalWidgets
|
||||||
|
|
|
@ -1,5 +1,2 @@
|
||||||
{% extends "django/admin/includes/detail_table_fieldset.html" %}
|
{% extends "django/admin/includes/detail_table_fieldset.html" %}
|
||||||
|
{# Stubbed file for future expansion #}
|
||||||
{% block after_help_text %}
|
|
||||||
<div>TESTING123</div>
|
|
||||||
{% endblock after_help_text %}
|
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
{% extends "django/admin/includes/detail_table_fieldset.html" %}
|
{% extends "django/admin/includes/detail_table_fieldset.html" %}
|
||||||
|
{# Stubbed file for future expansion #}
|
||||||
|
|
|
@ -116,6 +116,31 @@ class GenericTestHelper(TestCase):
|
||||||
self.url = url
|
self.url = url
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
|
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</td>"),
|
||||||
|
("email", "meoward.jones@igorville.gov</td>"),
|
||||||
|
]
|
||||||
|
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)
|
||||||
|
|
||||||
def assert_table_sorted(self, o_index, sort_fields):
|
def assert_table_sorted(self, o_index, sort_fields):
|
||||||
"""
|
"""
|
||||||
This helper function validates the sorting functionality of a Django Admin table view.
|
This helper function validates the sorting functionality of a Django Admin table view.
|
||||||
|
|
|
@ -1247,31 +1247,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
expected_url = '<a href="city.com" class="padding-top-1 current-website__1">city.com</a>'
|
expected_url = '<a href="city.com" class="padding-top-1 current-website__1">city.com</a>'
|
||||||
self.assertContains(response, expected_url)
|
self.assertContains(response, expected_url)
|
||||||
|
|
||||||
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</td>"),
|
|
||||||
("email", "meoward.jones@igorville.gov</td>"),
|
|
||||||
]
|
|
||||||
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
|
@less_console_noise_decorator
|
||||||
def test_contact_fields_have_detail_table(self):
|
def test_contact_fields_have_detail_table(self):
|
||||||
"""Tests if the contact fields have the detail table which displays title, email, and phone"""
|
"""Tests if the contact fields have the detail table which displays title, email, and phone"""
|
||||||
|
@ -1318,7 +1293,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
("email", "meoward.jones@igorville.gov</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)
|
self.test_helper.assert_response_contains_distinct_values(response, expected_creator_fields)
|
||||||
|
|
||||||
# Check for the field itself
|
# Check for the field itself
|
||||||
self.assertContains(response, "Meoward Jones")
|
self.assertContains(response, "Meoward Jones")
|
||||||
|
@ -1330,7 +1305,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
("email", "mayor@igorville.gov</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.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields)
|
||||||
self.assertContains(response, "Testy2 Tester2")
|
self.assertContains(response, "Testy2 Tester2")
|
||||||
|
|
||||||
# == Check for the authorizing_official == #
|
# == Check for the authorizing_official == #
|
||||||
|
@ -1340,7 +1315,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
("email", "testy@town.com</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.test_helper.assert_response_contains_distinct_values(response, expected_ao_fields)
|
||||||
|
|
||||||
# count=4 because the underlying domain has two users with this name.
|
# count=4 because the underlying domain has two users with this name.
|
||||||
# The dropdown has 3 of these.
|
# The dropdown has 3 of these.
|
||||||
|
@ -1365,7 +1340,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
("email", "testy2@town.com</td>"),
|
("email", "testy2@town.com</td>"),
|
||||||
("phone", "(555) 555 5557</td>"),
|
("phone", "(555) 555 5557</td>"),
|
||||||
]
|
]
|
||||||
self.assert_response_contains_distinct_values(response, expected_other_employees_fields)
|
self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields)
|
||||||
|
|
||||||
# count=1 as only one should exist in a table
|
# count=1 as only one should exist in a table
|
||||||
self.assertContains(response, "Testy Tester</th>", count=1)
|
self.assertContains(response, "Testy Tester</th>", count=1)
|
||||||
|
@ -1965,6 +1940,139 @@ class TestDomainInformationAdmin(TestCase):
|
||||||
Contact.objects.all().delete()
|
Contact.objects.all().delete()
|
||||||
User.objects.all().delete()
|
User.objects.all().delete()
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_other_contacts_has_readonly_link(self):
|
||||||
|
"""Tests if the readonly other_contacts field has links"""
|
||||||
|
|
||||||
|
# Create a fake domain request and domain
|
||||||
|
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW)
|
||||||
|
domain_request.approve()
|
||||||
|
domain_info = DomainInformation.objects.filter(domain=domain_request.approved_domain).get()
|
||||||
|
|
||||||
|
# Get the other contact
|
||||||
|
other_contact = domain_info.other_contacts.all().first()
|
||||||
|
|
||||||
|
p = "userpass"
|
||||||
|
self.client.login(username="staffuser", password=p)
|
||||||
|
response = self.client.get(
|
||||||
|
"/admin/registrar/domaininformation/{}/change/".format(domain_info.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_info.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 = "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"""
|
||||||
|
|
||||||
|
# Create fake creator
|
||||||
|
_creator = User.objects.create(
|
||||||
|
username="MrMeoward",
|
||||||
|
first_name="Meoward",
|
||||||
|
last_name="Jones",
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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, user=_creator)
|
||||||
|
domain_request.approve()
|
||||||
|
domain_info = DomainInformation.objects.filter(domain=domain_request.approved_domain).get()
|
||||||
|
|
||||||
|
p = "userpass"
|
||||||
|
self.client.login(username="staffuser", password=p)
|
||||||
|
response = self.client.get(
|
||||||
|
"/admin/registrar/domaininformation/{}/change/".format(domain_info.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_info.domain.name)
|
||||||
|
|
||||||
|
# Check that the modal has the right content
|
||||||
|
# Check for the header
|
||||||
|
|
||||||
|
# == Check for the creator == #
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
expected_creator_fields = [
|
||||||
|
# Field, expected value
|
||||||
|
("title", "Treat inspector</td>"),
|
||||||
|
("email", "meoward.jones@igorville.gov</td>"),
|
||||||
|
("phone", "(555) 123 12345</td>"),
|
||||||
|
]
|
||||||
|
self.test_helper.assert_response_contains_distinct_values(response, expected_creator_fields)
|
||||||
|
|
||||||
|
# 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>"),
|
||||||
|
]
|
||||||
|
self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields)
|
||||||
|
self.assertContains(response, "Testy2 Tester2")
|
||||||
|
|
||||||
|
# == Check for the authorizing_official == #
|
||||||
|
expected_ao_fields = [
|
||||||
|
# Field, expected value
|
||||||
|
("title", "Chief Tester</td>"),
|
||||||
|
("email", "testy@town.com</td>"),
|
||||||
|
("phone", "(555) 555 5555</td>"),
|
||||||
|
]
|
||||||
|
self.test_helper.assert_response_contains_distinct_values(response, expected_ao_fields)
|
||||||
|
|
||||||
|
# count=4 because the underlying domain has two users with this name.
|
||||||
|
# The dropdown has 3 of these.
|
||||||
|
self.assertContains(response, "Testy Tester", count=4)
|
||||||
|
|
||||||
|
# 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</th>", count=3)
|
||||||
|
|
||||||
|
# Email. Count=3 because this table appears on three records.
|
||||||
|
self.assertContains(response, "Email</th>", count=3)
|
||||||
|
|
||||||
|
# Phone. Count=3 because this table appears on three records.
|
||||||
|
self.assertContains(response, "Phone</th>", count=3)
|
||||||
|
|
||||||
|
# == Test the other_employees field == #
|
||||||
|
expected_other_employees_fields = [
|
||||||
|
# Field, expected value
|
||||||
|
("title", "Another Tester</td>"),
|
||||||
|
("email", "testy2@town.com</td>"),
|
||||||
|
("phone", "(555) 555 5557</td>"),
|
||||||
|
]
|
||||||
|
self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields)
|
||||||
|
|
||||||
|
# count=1 as only one should exist in a table
|
||||||
|
self.assertContains(response, "Testy Tester</th>", count=1)
|
||||||
|
|
||||||
def test_readonly_fields_for_analyst(self):
|
def test_readonly_fields_for_analyst(self):
|
||||||
"""Ensures that analysts have their permissions setup correctly"""
|
"""Ensures that analysts have their permissions setup correctly"""
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
|
@ -1983,6 +2091,7 @@ class TestDomainInformationAdmin(TestCase):
|
||||||
"no_other_contacts_rationale",
|
"no_other_contacts_rationale",
|
||||||
"anything_else",
|
"anything_else",
|
||||||
"is_policy_acknowledged",
|
"is_policy_acknowledged",
|
||||||
|
"other_contacts",
|
||||||
]
|
]
|
||||||
|
|
||||||
self.assertEqual(readonly_fields, expected_fields)
|
self.assertEqual(readonly_fields, expected_fields)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue