mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 17:17:02 +02:00
Fix test cases
This commit is contained in:
parent
3d4972773c
commit
daf640ded3
2 changed files with 15 additions and 38 deletions
|
@ -551,6 +551,7 @@ class DomainApplicationAdmin(ListHeaderAdmin):
|
||||||
|
|
||||||
class InvestigatorFilter(admin.SimpleListFilter):
|
class InvestigatorFilter(admin.SimpleListFilter):
|
||||||
"""Custom investigator filter that only displays users with the manager role"""
|
"""Custom investigator filter that only displays users with the manager role"""
|
||||||
|
|
||||||
title = "investigator"
|
title = "investigator"
|
||||||
parameter_name = "investigator"
|
parameter_name = "investigator"
|
||||||
|
|
||||||
|
|
|
@ -856,62 +856,38 @@ class TestDomainApplicationAdmin(MockEppLib):
|
||||||
|
|
||||||
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"""
|
||||||
|
|
||||||
|
# Create a mock DomainApplication object, with a fake investigator
|
||||||
|
application: DomainApplication = generic_domain_object("application", "SomeGuy")
|
||||||
|
investigator_user = User.objects.filter(username=application.investigator.username).get()
|
||||||
|
investigator_user.is_staff = True
|
||||||
|
investigator_user.save()
|
||||||
|
|
||||||
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/domainapplication/",
|
"/admin/registrar/domainapplication/",
|
||||||
|
{
|
||||||
|
"investigator": investigator_user.id,
|
||||||
|
},
|
||||||
|
follow=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a mock DomainApplication object, with a fake investigator
|
|
||||||
application: DomainApplication = generic_domain_object("application", "SomeGuy")
|
|
||||||
|
|
||||||
# Add the role manager to the investigator
|
|
||||||
UserDomainRole.objects.get_or_create(
|
|
||||||
user=application.investigator,
|
|
||||||
role=UserDomainRole.Roles.MANAGER,
|
|
||||||
domain=Domain.objects.create(name="SomeGuy.gov")
|
|
||||||
)
|
|
||||||
|
|
||||||
# First, make sure that there is still an investigator field to begin with
|
|
||||||
expected_sort_column = "sortable column-investigator"
|
|
||||||
self.assertContains(response, expected_sort_column, count=1)
|
|
||||||
|
|
||||||
# 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"]
|
||||||
|
print(response.context.__dict__)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
filters,
|
filters,
|
||||||
[
|
[
|
||||||
{"parameter_name": "status", "parameter_value": "started"},
|
|
||||||
{
|
{
|
||||||
"parameter_name": "investigator",
|
"parameter_name": "investigator",
|
||||||
"parameter_value": "test",
|
"parameter_value": "4",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_investigator_filter(self):
|
|
||||||
"""Tests the custom investigator filter"""
|
|
||||||
# Creates multiple domain applications
|
|
||||||
multiple_unalphabetical_domain_objects("application")
|
|
||||||
p = "userpass"
|
|
||||||
self.client.login(username="staffuser", password=p)
|
|
||||||
|
|
||||||
response = self.client.get(
|
|
||||||
"/admin/registrar/domainapplication/",
|
|
||||||
{
|
|
||||||
"investigator": 1,
|
|
||||||
},
|
|
||||||
follow=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
# The "multiple_unalphabetical_domain_objects" function will create
|
|
||||||
# user objects with a first name that contains "first_name:investigator".
|
|
||||||
# We can simply count how many times this appears in the table to determine
|
|
||||||
# how many records exist.
|
|
||||||
self.assertContains(response, "first_name:investigator", count=1)
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
Domain.objects.all().delete()
|
Domain.objects.all().delete()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue