mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 03:06:01 +02:00
Code cleanup, layout cleanup, unit tests
This commit is contained in:
parent
31031d054d
commit
cb16f5eb96
5 changed files with 229 additions and 151 deletions
52
src/registrar/tests/test_admin_views.py
Normal file
52
src/registrar/tests/test_admin_views.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
from django.test import TestCase, Client
|
||||
from django.urls import reverse
|
||||
from registrar.tests.common import create_superuser
|
||||
from registrar.views.admin_views import ExportData
|
||||
|
||||
|
||||
class TestViews(TestCase):
|
||||
def setUp(self):
|
||||
self.client = Client(HTTP_HOST="localhost:8080")
|
||||
self.superuser = create_superuser()
|
||||
|
||||
def test_export_data_view(self):
|
||||
|
||||
self.client.force_login(self.superuser)
|
||||
|
||||
# Reverse the URL for the admin index page
|
||||
admin_index_url = reverse("admin:index")
|
||||
|
||||
# Make a GET request to the admin index page
|
||||
response = self.client.get(admin_index_url)
|
||||
|
||||
print(f'response1 {response}')
|
||||
|
||||
# Assert that the response status code is 200 (OK)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Ensure that the start_date and end_date are set
|
||||
start_date = "2023-01-01"
|
||||
end_date = "2023-12-31"
|
||||
|
||||
# Construct the URL for the export data view with start_date and end_date parameters:
|
||||
# This stuff is currently done in JS
|
||||
export_data_url = reverse("admin_export_data") + f"?start_date={start_date}&end_date={end_date}"
|
||||
|
||||
# Make a GET request to the export data page
|
||||
response = self.client.get(export_data_url)
|
||||
|
||||
print(response)
|
||||
|
||||
# Assert that the response status code is 200 (OK) or the expected status code
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Assert that the content type is CSV
|
||||
self.assertEqual(response["Content-Type"], "text/csv")
|
||||
|
||||
# Check if the filename in the Content-Disposition header matches the expected pattern
|
||||
expected_filename = f'growth-from-{start_date}-to-{end_date}.csv'
|
||||
self.assertIn(f'attachment; filename="{expected_filename}"', response["Content-Disposition"])
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue