Add unit tests and cleanup

This commit is contained in:
zandercymatics 2024-09-16 11:03:14 -06:00
parent eb3850458b
commit ef0e1c081b
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 51 additions and 8 deletions

View file

@ -1,6 +1,7 @@
from unittest import skip
from unittest.mock import Mock
from unittest.mock import Mock, patch
from datetime import datetime
from django.utils import timezone
from django.conf import settings
from django.urls import reverse
from api.tests.common import less_console_noise_decorator
@ -55,6 +56,54 @@ class DomainRequestTests(TestWithUser, WebTest):
intro_page = self.app.get(reverse("domain-request:"))
self.assertContains(intro_page, "Youre about to start your .gov domain request")
@less_console_noise_decorator
def test_template_status_display(self):
"""Tests the display of status-related information in the template."""
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.SUBMITTED, user=self.user)
domain_request.last_submitted_date = datetime.now()
domain_request.save()
response = self.app.get(f"/domain-request/{domain_request.id}")
self.assertContains(response, "Submitted on:")
self.assertContains(response, domain_request.last_submitted_date.strftime("%B %-d, %Y"))
@patch.object(DomainRequest, "get_first_status_set_date")
def test_get_first_status_started_date(self, mock_get_first_status_set_date):
"""Tests retrieval of the first date the status was set to 'started'."""
# Set the mock to return a fixed date
fixed_date = timezone.datetime(2023, 1, 1).date()
mock_get_first_status_set_date.return_value = fixed_date
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.STARTED, user=self.user)
domain_request.last_status_update = None
domain_request.save()
response = self.app.get(f"/domain-request/{domain_request.id}")
# Ensure that the date is still set to None
self.assertIsNone(domain_request.last_status_update)
print(response)
# We should still grab a date for this field in this event - but it should come from the audit log instead
self.assertContains(response, "Started on:")
self.assertContains(response, fixed_date.strftime("%B %-d, %Y"))
# If a status date is set, we display that instead
domain_request.last_status_update = datetime.now()
domain_request.save()
response = self.app.get(f"/domain-request/{domain_request.id}")
# We should still grab a date for this field in this event - but it should come from the audit log instead
self.assertContains(response, "Started on:")
self.assertContains(response, domain_request.last_status_update.strftime("%B %-d, %Y"))
def test_template_new_domain_request_display(self):
"""Tests the display of the new domain request header."""
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.STARTED, user=self.user)
domain_request.requested_domain = None
domain_request.save()
response = self.app.get(f"/domain-request/{domain_request.id}")
self.assertContains(response, "New domain request")
@less_console_noise_decorator
def test_domain_request_form_intro_is_skipped_when_edit_access(self):
"""Tests that user is NOT presented with intro acknowledgement page when accessed through 'edit'"""