mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 17:47:02 +02:00
Add test cases
This commit is contained in:
parent
46677f4588
commit
377786cccf
2 changed files with 20 additions and 19 deletions
|
@ -343,6 +343,11 @@ class UserDomainRoleAdmin(ListHeaderAdmin):
|
|||
|
||||
class DomainInvitationAdmin(ListHeaderAdmin):
|
||||
"""Custom domain invitation admin class."""
|
||||
class Meta:
|
||||
model = models.DomainInvitation
|
||||
fields = "__all__"
|
||||
|
||||
_meta = Meta()
|
||||
|
||||
# Columns
|
||||
list_display = [
|
||||
|
|
|
@ -850,9 +850,8 @@ class TestDomainApplicationAdmin(MockEppLib):
|
|||
|
||||
class DomainInvitationAdminTest(TestCase):
|
||||
def setUp(self):
|
||||
self.site = AdminSite()
|
||||
self.factory = RequestFactory()
|
||||
self.admin = ListHeaderAdmin(model=DomainInvitationAdmin, admin_site=None)
|
||||
self.admin = ListHeaderAdmin(model=DomainInvitationAdmin, admin_site=AdminSite())
|
||||
self.client = Client(HTTP_HOST="localhost:8080")
|
||||
self.superuser = create_superuser()
|
||||
|
||||
|
@ -863,26 +862,23 @@ class DomainInvitationAdminTest(TestCase):
|
|||
User.objects.all().delete()
|
||||
|
||||
def test_get_filters(self):
|
||||
# Create a mock request object
|
||||
request = self.factory.get("/admin/yourmodel/")
|
||||
# Set the GET parameters for testing
|
||||
request.GET = {
|
||||
"status": "started",
|
||||
"investigator": "Rachid Mrad",
|
||||
"q": "search_value",
|
||||
}
|
||||
# Call the get_filters method
|
||||
filters = self.admin.get_filters(request)
|
||||
# Have to get creative to get past linter
|
||||
p = "adminpass"
|
||||
self.client.login(username="superuser", password=p)
|
||||
|
||||
# Assert the filters extracted from the request GET
|
||||
self.assertEqual(
|
||||
filters,
|
||||
[
|
||||
{"parameter_name": "status", "parameter_value": "started"},
|
||||
{"parameter_name": "investigator", "parameter_value": "Rachid Mrad"},
|
||||
],
|
||||
# Mock a user
|
||||
user = mock_user()
|
||||
|
||||
response = self.client.get(
|
||||
"/admin/registrar/domaininvitation/",
|
||||
{},
|
||||
follow=True,
|
||||
)
|
||||
|
||||
# Assert that the filters are added
|
||||
self.assertContains(response, "invited", count=4)
|
||||
self.assertContains(response, "retrieved", count=4)
|
||||
|
||||
|
||||
class ListHeaderAdminTest(TestCase):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue