Fix unit tests

This commit is contained in:
zandercymatics 2024-03-26 14:45:26 -06:00
parent a70214e467
commit a512dcd1b1
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
5 changed files with 22 additions and 33 deletions

View file

@ -924,7 +924,6 @@ 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
@ -1133,8 +1132,6 @@ class DomainRequestAdmin(ListHeaderAdmin):
"requested_domain", "requested_domain",
"approved_domain", "approved_domain",
"alternative_domains", "alternative_domains",
"other_contacts",
"current_websites",
"purpose", "purpose",
"submitter", "submitter",
"no_other_contacts_rationale", "no_other_contacts_rationale",
@ -1310,7 +1307,7 @@ class DomainRequestAdmin(ListHeaderAdmin):
readonly_fields.extend([field.name for field in self.model._meta.fields]) readonly_fields.extend([field.name for field in self.model._meta.fields])
# Add the multi-select fields to readonly_fields: # Add the multi-select fields to readonly_fields:
# Complex fields like ManyToManyField require special handling # Complex fields like ManyToManyField require special handling
readonly_fields.extend(["current_websites", "other_contacts", "alternative_domains"]) readonly_fields.extend(["alternative_domains"])
if request.user.has_perm("registrar.full_access_permission"): if request.user.has_perm("registrar.full_access_permission"):
return readonly_fields return readonly_fields
@ -1421,7 +1418,6 @@ class DomainAdmin(ListHeaderAdmin):
) )
def queryset(self, request, queryset): def queryset(self, request, queryset):
logger.debug(self.value())
if self.value() == "1": if self.value() == "1":
return queryset.filter(domain_info__is_election_board=True) return queryset.filter(domain_info__is_election_board=True)
if self.value() == "0": if self.value() == "0":

View file

@ -175,6 +175,12 @@ function checkToListThenInitWidget(toListId, attempts) {
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
// Select all table rows that have a data-contact-id attribute // Select all table rows that have a data-contact-id attribute
let contactRows = document.querySelectorAll("tr[data-contact-url]"); let contactRows = document.querySelectorAll("tr[data-contact-url]");
console.log(`contact rows at this point: ${contactRows}`)
console.log(`length of ont ${contactRows.length}`)
if (!contactRows || contactRows.length == 0) {
console.log("in if statement")
contactRows = document.querySelectorAll(".other-contact-id")
}
if (contactRows){ if (contactRows){
// Add a click event listener to each row // Add a click event listener to each row

View file

@ -58,6 +58,7 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
{% for contact in all_contacts %} {% for contact in all_contacts %}
<div class="flex-container"> <div class="flex-container">
<label aria-label="Other contact details"></label> <label aria-label="Other contact details"></label>
<div class="display-none other-contact-id" data-contact-url="{% url 'admin:registrar_contact_change' contact.id %}"></div>
{% include "django/admin/includes/contact_detail_table.html" with user=contact field_name="other_contact" no_title_top_padding=field.is_readonly %} {% include "django/admin/includes/contact_detail_table.html" with user=contact field_name="other_contact" no_title_top_padding=field.is_readonly %}
</div> </div>
{% endfor %} {% endfor %}

View file

@ -204,7 +204,6 @@ class GenericTestHelper(TestCase):
{"action": "delete_selected", "select_across": selected_across, "index": index, "_selected_action": "23"}, {"action": "delete_selected", "select_across": selected_across, "index": index, "_selected_action": "23"},
follow=True, follow=True,
) )
print(f"what is the response? {response}")
return response return response

View file

@ -1335,9 +1335,9 @@ class TestDomainRequestAdmin(MockEppLib):
] ]
self.test_helper.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=5 because the underlying domain has two users with this name.
# The dropdown has 3 of these. # The dropdown has 4 of these.
self.assertContains(response, "Testy Tester", count=4) self.assertContains(response, "Testy Tester", count=5)
# Check for table titles. We only need to check for the end tag # Check for table titles. We only need to check for the end tag
# (Otherwise this test will fail if we change classes, etc) # (Otherwise this test will fail if we change classes, etc)
@ -1446,6 +1446,7 @@ class TestDomainRequestAdmin(MockEppLib):
self.assertContains(response, "Yes, select ineligible status") self.assertContains(response, "Yes, select ineligible status")
def test_readonly_when_restricted_creator(self): def test_readonly_when_restricted_creator(self):
self.maxDiff = None
with less_console_noise(): with less_console_noise():
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW) domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client): with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
@ -1458,6 +1459,8 @@ class TestDomainRequestAdmin(MockEppLib):
readonly_fields = self.admin.get_readonly_fields(request, domain_request) readonly_fields = self.admin.get_readonly_fields(request, domain_request)
expected_fields = [ expected_fields = [
"other_contacts",
"current_websites",
"id", "id",
"created_at", "created_at",
"updated_at", "updated_at",
@ -1490,8 +1493,6 @@ class TestDomainRequestAdmin(MockEppLib):
"is_policy_acknowledged", "is_policy_acknowledged",
"submission_date", "submission_date",
"notes", "notes",
"current_websites",
"other_contacts",
"alternative_domains", "alternative_domains",
] ]
@ -1505,13 +1506,13 @@ class TestDomainRequestAdmin(MockEppLib):
readonly_fields = self.admin.get_readonly_fields(request) readonly_fields = self.admin.get_readonly_fields(request)
expected_fields = [ expected_fields = [
"other_contacts",
"current_websites",
"creator", "creator",
"about_your_organization", "about_your_organization",
"requested_domain", "requested_domain",
"approved_domain", "approved_domain",
"alternative_domains", "alternative_domains",
"other_contacts",
"current_websites",
"purpose", "purpose",
"submitter", "submitter",
"no_other_contacts_rationale", "no_other_contacts_rationale",
@ -1528,7 +1529,7 @@ class TestDomainRequestAdmin(MockEppLib):
readonly_fields = self.admin.get_readonly_fields(request) readonly_fields = self.admin.get_readonly_fields(request)
expected_fields = [] expected_fields = ['other_contacts', 'current_websites']
self.assertEqual(readonly_fields, expected_fields) self.assertEqual(readonly_fields, expected_fields)
@ -1972,6 +1973,7 @@ class TestDomainInformationAdmin(TestCase):
p = "userpass" p = "userpass"
self.client.login(username="staffuser", password=p) self.client.login(username="staffuser", password=p)
response = self.client.get( response = self.client.get(
"/admin/registrar/domaininformation/{}/change/".format(domain_info.pk), "/admin/registrar/domaininformation/{}/change/".format(domain_info.pk),
follow=True, follow=True,
@ -2063,21 +2065,9 @@ class TestDomainInformationAdmin(TestCase):
] ]
self.test_helper.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=5 because the underlying domain has two users with this name.
# The dropdown has 3 of these. # The dropdown has 4 of these.
self.assertContains(response, "Testy Tester", count=4) self.assertContains(response, "Testy Tester", count=5)
# 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 == # # == Test the other_employees field == #
expected_other_employees_fields = [ expected_other_employees_fields = [
@ -2088,9 +2078,6 @@ class TestDomainInformationAdmin(TestCase):
] ]
self.test_helper.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
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():
@ -2100,6 +2087,7 @@ class TestDomainInformationAdmin(TestCase):
readonly_fields = self.admin.get_readonly_fields(request) readonly_fields = self.admin.get_readonly_fields(request)
expected_fields = [ expected_fields = [
"other_contacts",
"creator", "creator",
"type_of_work", "type_of_work",
"more_organization_information", "more_organization_information",
@ -2109,7 +2097,6 @@ 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)