Fix test cases

This commit is contained in:
zandercymatics 2023-12-18 09:56:04 -07:00
parent 04c9c8388f
commit fdb8147c1f
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -316,47 +316,6 @@ class TestDomainApplicationAdminForm(TestCase):
) )
class TestDomainApplicationAdminTable(MockEppLib):
"""Tests the table for DomainApplicationAdmin"""
def setUp(self):
"""Enables epplib patching, and creates a fake admin object"""
super().setUp()
self.site = AdminSite()
self.factory = RequestFactory()
self.superuser = create_superuser()
self.admin = DomainApplicationAdmin(model=DomainApplication, admin_site=self.site)
def test_table_sorted_alphabetically(self):
"""Tests if DomainApplicationAdmin table is sorted alphabetically"""
# Creates a list of DomainApplications in scrambled order
multiple_unalphabetical_domain_objects("application")
request = self.factory.get("/")
request.user = self.superuser
# Get the expected list of alphabetically sorted DomainApplications
expected_order = DomainApplication.objects.order_by("requested_domain__name")
# Get the returned queryset
queryset = self.admin.get_queryset(request)
# Check the order
self.assertEqual(
list(queryset),
list(expected_order),
)
def tearDown(self):
"""Delete all associated domain objects"""
super().tearDown()
Domain.objects.all().delete()
DomainInformation.objects.all().delete()
DomainApplication.objects.all().delete()
User.objects.all().delete()
Contact.objects.all().delete()
Website.objects.all().delete()
class TestDomainApplicationAdmin(MockEppLib): class TestDomainApplicationAdmin(MockEppLib):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
@ -897,6 +856,26 @@ class TestDomainApplicationAdmin(MockEppLib):
self.assertEqual(readonly_fields, expected_fields) self.assertEqual(readonly_fields, expected_fields)
def test_table_sorted_alphabetically(self):
"""Tests if DomainApplicationAdmin table is sorted alphabetically"""
# Creates a list of DomainApplications in scrambled order
multiple_unalphabetical_domain_objects("application")
request = self.factory.get("/")
request.user = self.superuser
# Get the expected list of alphabetically sorted DomainApplications
expected_order = DomainApplication.objects.order_by("requested_domain__name")
# Get the returned queryset
queryset = self.admin.get_queryset(request)
# Check the order
self.assertEqual(
list(queryset),
list(expected_order),
)
def test_displays_investigator_filter(self): def test_displays_investigator_filter(self):
"""Tests if DomainApplicationAdmin displays the investigator filter""" """Tests if DomainApplicationAdmin displays the investigator filter"""
@ -911,13 +890,14 @@ class TestDomainApplicationAdmin(MockEppLib):
response = self.client.get( response = self.client.get(
"/admin/registrar/domainapplication/", "/admin/registrar/domainapplication/",
{ {
"investigator": investigator_user.id, "investigator__id__exact": investigator_user.id,
}, },
follow=True, follow=True,
) )
# Then, test if the filter actually exists # Then, test if the filter actually exists
self.assertIn("filters", response.context) self.assertIn("filters", response.context)
# Assert the content of filters and search_query # Assert the content of filters and search_query
filters = response.context["filters"] filters = response.context["filters"]
@ -927,27 +907,6 @@ class TestDomainApplicationAdmin(MockEppLib):
[ [
{ {
"parameter_name": "investigator", "parameter_name": "investigator",
"parameter_value": str(investigator_user.id),
},
],
)
# Manually test the returned values
request = self.factory.get("/admin/registrar/domainapplication/")
# Set the GET parameters for testing
request.GET = {
"investigator__id__exact": investigator_user.id,
}
# Call the get_filters method
filters = self.admin.get_filters(request)
# Assert the filters extracted from the request GET
self.assertEqual(
filters,
[
{
"parameter_name": "investigator",
# We intentionally test a weird value, to see what happens
"parameter_value": "SomeGuy first_name:investigator SomeGuy last_name:investigator", "parameter_value": "SomeGuy first_name:investigator SomeGuy last_name:investigator",
}, },
], ],