-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #287 from co-cddo/DEV_373_data_download
Admin download action for Applications and Reviews
- Loading branch information
Showing
2 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from datetime import datetime | ||
from unittest.mock import Mock | ||
|
||
from django.contrib.auth.models import User | ||
from django.test import TestCase, Client | ||
from django.urls import reverse | ||
|
||
from request_a_govuk_domain.request import db | ||
from request_a_govuk_domain.request.models import Registrar, Application | ||
|
||
|
||
class ModelAdminActionsTestCase(TestCase): | ||
def setUp(self): | ||
self.registrar = Registrar.objects.create(name="dummy registrar") | ||
self.registration_data = { | ||
"registrant_type": "parish_council", | ||
"domain_name": "test.domain.gov.uk", | ||
"registrar_name": "dummy registrar", | ||
"registrar_email": "[email protected]", | ||
"registrar_phone": "23456789", | ||
"registrar_organisation": f"{self.registrar.name}-{self.registrar.id}", | ||
"registrant_organisation": "dummy org", | ||
"registrant_full_name": "dummy user", | ||
"registrant_phone": "012345678", | ||
"registrant_email": "[email protected]", | ||
"registrant_role": "dummy", | ||
"registrant_contact_email": "[email protected]", | ||
} | ||
|
||
User.objects.create_superuser( | ||
username="superuser", | ||
password="secret", # pragma: allowlist secret | ||
email="[email protected]", | ||
) | ||
|
||
def test_file_is_downloaded(self): | ||
request = Mock() | ||
request.session = SessionDict({"registration_data": self.registration_data}) | ||
db.save_data_in_database("ABCDEFGHIJK", request) | ||
app = Application.objects.filter(reference="ABCDEFGHIJK")[0] | ||
c = Client() | ||
c.login(username="superuser", password="secret") # pragma: allowlist secret | ||
|
||
response = c.post( | ||
reverse( | ||
"admin:request_application_changelist", | ||
), | ||
data={ | ||
"action": "export", | ||
"_selected_action": [app.pk], | ||
}, | ||
follow=True, | ||
) | ||
|
||
self.assertEqual( | ||
response.get("Content-Disposition"), | ||
f"attachment; filename=request.application_{datetime.today().strftime('%Y-%m-%d')}_data_backup.csv", | ||
) | ||
|
||
self.assertContains(response, "reference") | ||
self.assertContains(response, "ABCDEFGHIJK") | ||
|
||
|
||
class SessionDict(dict): | ||
def __init__(self, *k, **kwargs): | ||
self.__dict__ = self | ||
super().__init__(*k, **kwargs) | ||
self.session_key = "session-key" |