commented, and code cleaned up

This commit is contained in:
David Kennedy 2024-05-23 11:52:23 -04:00
parent 4d16cf34ab
commit 4a06bb1d0f
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
7 changed files with 111 additions and 20 deletions

View file

@ -13,7 +13,7 @@ class DomainRequestViewTest(TestWithUser, WebTest):
self.domain_requests = [
DomainRequest.objects.create(
creator=self.user,
requested_domain=None, # Assuming requested_domain is an optional field
requested_domain=None,
submission_date="2024-01-01",
status=DomainRequest.DomainRequestStatus.STARTED,
created_at="2024-01-01",
@ -41,7 +41,7 @@ class DomainRequestViewTest(TestWithUser, WebTest):
),
DomainRequest.objects.create(
creator=self.user,
requested_domain=None, # Assuming requested_domain is an optional field
requested_domain=None,
submission_date="2024-05-01",
status=DomainRequest.DomainRequestStatus.STARTED,
created_at="2024-05-01",
@ -69,7 +69,7 @@ class DomainRequestViewTest(TestWithUser, WebTest):
),
DomainRequest.objects.create(
creator=self.user,
requested_domain=None, # Assuming requested_domain is an optional field
requested_domain=None,
submission_date="2024-09-01",
status=DomainRequest.DomainRequestStatus.STARTED,
created_at="2024-09-01",
@ -98,6 +98,7 @@ class DomainRequestViewTest(TestWithUser, WebTest):
]
def test_get_domain_requests_json_authenticated(self):
""" test that domain requests are returned properly for an authenticated user """
response = self.app.get(reverse("get_domain_requests_json"))
self.assertEqual(response.status_code, 200)
data = response.json
@ -114,6 +115,8 @@ class DomainRequestViewTest(TestWithUser, WebTest):
self.assertNotEqual(domain_request["status"], "Approved")
def test_pagination(self):
""" Test that pagination works properly. There are 11 total non-approved requests and
a page size of 10 """
response = self.app.get(reverse("get_domain_requests_json"), {"page": 1})
self.assertEqual(response.status_code, 200)
data = response.json
@ -135,6 +138,7 @@ class DomainRequestViewTest(TestWithUser, WebTest):
self.assertEqual(data["num_pages"], 2)
def test_sorting(self):
""" test that sorting works properly on the result set """
response = self.app.get(reverse("get_domain_requests_json"), {"sort_by": "submission_date", "order": "desc"})
self.assertEqual(response.status_code, 200)
data = response.json
@ -152,7 +156,9 @@ class DomainRequestViewTest(TestWithUser, WebTest):
self.assertEqual(submission_dates, sorted(submission_dates))
def test_filter_approved_excluded(self):
response = self.app.get(reverse("get_domain_requests_json"))
""" test that approved requests are excluded from result set. """
# sort in reverse chronological order of submission date, since most recent request is approved
response = self.app.get(reverse("get_domain_requests_json"), {"sort_by": "submission_date", "order": "desc"})
self.assertEqual(response.status_code, 200)
data = response.json