This commit is contained in:
rachidatecs 2023-06-29 18:21:41 -04:00
parent de36ca9cf7
commit 15688b8fdb
No known key found for this signature in database
GPG key ID: 3CEBBFA7325E5525
3 changed files with 49 additions and 2 deletions

View file

@ -1,6 +1,6 @@
from django.test import TestCase, RequestFactory
from django.test import TestCase, RequestFactory, Client
from django.contrib.admin.sites import AdminSite
from registrar.admin import DomainApplicationAdmin
from registrar.admin import DomainApplicationAdmin, ListHeaderAdmin, AuditedAdmin
from registrar.models import DomainApplication, User
from .common import completed_application
@ -13,6 +13,8 @@ class TestDomainApplicationAdmin(TestCase):
def setUp(self):
self.site = AdminSite()
self.factory = RequestFactory()
self.admin = ListHeaderAdmin(model=DomainApplication, admin_site=None)
self.client = Client(HTTP_HOST='localhost:8080')
@boto3_mocking.patching
def test_save_model_sends_email_on_property_change(self):
@ -62,3 +64,45 @@ class TestDomainApplicationAdmin(TestCase):
# Cleanup
application.delete()
def test_changelist_view(self):
# Make the request using the Client class
# which handles CSRF
# Follow=True handles the redirect
request = self.client.get('/admin/registrar/domainapplication/', {'param1': 'value1', 'param2': 'value2'}, follow=True, max_redirects=10)
print(f'request {request}')
# request = self.factory.get('/admin/registrar/domainapplication/')
# # Set the GET parameters for testing
# request.GET = {'param1': 'value1', 'param2': 'value2', 'q': 'search_value'}
# # Call the changelist_view method
response = self.admin.changelist_view(request, extra_context={'filters': [{'parameter_name': 'status', 'parameter_value': 'started'}], 'search_query': ''})
print(f'response {response}')
# Assert that the final response is a successful response (not a redirect)
# self.assertEqual(response.status_code, 200)
# Assert that the filters and search_query are added to the extra_context
self.assertIn('filters', response.extra_context)
self.assertIn('search_query', response.extra_context)
# Assert the content of filters and search_query
filters = response.extra_context['filters']
search_query = response.extra_context['search_query']
self.assertEqual(filters, [{'parameter_name': 'param1', 'parameter_value': 'value1'},
{'parameter_name': 'param2', 'parameter_value': 'value2'}])
self.assertEqual(search_query, 'value of q parameter if present in the request GET')
def test_get_filters(self):
# Create a mock request object
request = self.factory.get('/admin/yourmodel/')
# Set the GET parameters for testing
request.GET = {'param1': 'value1', 'param2': 'value2', 'q': 'search_value'}
# Call the get_filters method
filters = self.admin.get_filters(request)
# Assert the filters extracted from the request GET
self.assertEqual(filters, [{'parameter_name': 'param1', 'parameter_value': 'value1'},
{'parameter_name': 'param2', 'parameter_value': 'value2'}])