mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-20 17:56:11 +02:00
wip
This commit is contained in:
parent
de36ca9cf7
commit
15688b8fdb
3 changed files with 49 additions and 2 deletions
|
@ -36,6 +36,7 @@ class ListHeaderAdmin(AuditedAdmin):
|
||||||
# Pass the filtered values to the template context
|
# Pass the filtered values to the template context
|
||||||
extra_context['filters'] = filters
|
extra_context['filters'] = filters
|
||||||
extra_context['search_query'] = request.GET.get('q', '') # Assuming the search query parameter is 'q'
|
extra_context['search_query'] = request.GET.get('q', '') # Assuming the search query parameter is 'q'
|
||||||
|
logger.debug(f'changelist_view {extra_context}')
|
||||||
return super().changelist_view(request, extra_context=extra_context)
|
return super().changelist_view(request, extra_context=extra_context)
|
||||||
|
|
||||||
def get_filters(self, request):
|
def get_filters(self, request):
|
||||||
|
|
|
@ -94,6 +94,8 @@ INSTALLED_APPS = [
|
||||||
# generic interface for Django models
|
# generic interface for Django models
|
||||||
"auditlog",
|
"auditlog",
|
||||||
# library to simplify form templating
|
# library to simplify form templating
|
||||||
|
# it needs to be listed before django.contrib.contenttypes
|
||||||
|
# for a ContentType query in fixtures.py
|
||||||
"django.contrib.contenttypes",
|
"django.contrib.contenttypes",
|
||||||
# required for CSRF protection and many other things
|
# required for CSRF protection and many other things
|
||||||
"django.contrib.sessions",
|
"django.contrib.sessions",
|
||||||
|
|
|
@ -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 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 registrar.models import DomainApplication, User
|
||||||
from .common import completed_application
|
from .common import completed_application
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ class TestDomainApplicationAdmin(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.site = AdminSite()
|
self.site = AdminSite()
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
|
self.admin = ListHeaderAdmin(model=DomainApplication, admin_site=None)
|
||||||
|
self.client = Client(HTTP_HOST='localhost:8080')
|
||||||
|
|
||||||
@boto3_mocking.patching
|
@boto3_mocking.patching
|
||||||
def test_save_model_sends_email_on_property_change(self):
|
def test_save_model_sends_email_on_property_change(self):
|
||||||
|
@ -62,3 +64,45 @@ class TestDomainApplicationAdmin(TestCase):
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
application.delete()
|
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'}])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue