mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 10:59:21 +02:00
Cleanup
This commit is contained in:
parent
f7208a80ea
commit
5c685a3fd6
2 changed files with 121 additions and 122 deletions
|
@ -746,6 +746,10 @@ class MockDb(TestCase):
|
||||||
DomainInvitation.objects.all().delete()
|
DomainInvitation.objects.all().delete()
|
||||||
FederalAgency.objects.all().delete()
|
FederalAgency.objects.all().delete()
|
||||||
|
|
||||||
|
def get_time_aware_date(self, date=datetime(2023, 11, 1)):
|
||||||
|
"""Returns a time aware date"""
|
||||||
|
return timezone.make_aware(date)
|
||||||
|
|
||||||
|
|
||||||
def mock_user():
|
def mock_user():
|
||||||
"""A simple user."""
|
"""A simple user."""
|
||||||
|
|
|
@ -25,56 +25,6 @@ from registrar.utility.s3_bucket import S3ClientError, S3ClientErrorCodes # typ
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from .common import MockDb, MockEppLib, less_console_noise
|
from .common import MockDb, MockEppLib, less_console_noise
|
||||||
from api.tests.common import less_console_noise_decorator
|
|
||||||
|
|
||||||
|
|
||||||
class HelperFunctions(MockDb):
|
|
||||||
"""This asserts that 1=1. Its limited usefulness lies in making sure the helper methods stay healthy."""
|
|
||||||
|
|
||||||
def get_time_aware_date(self, date=datetime(2023, 11, 1)):
|
|
||||||
"""Returns a time aware date"""
|
|
||||||
return timezone.make_aware(date)
|
|
||||||
|
|
||||||
def test_get_default_start_date(self):
|
|
||||||
expected_date = self.get_time_aware_date()
|
|
||||||
actual_date = get_default_start_date()
|
|
||||||
self.assertEqual(actual_date, expected_date)
|
|
||||||
|
|
||||||
def test_get_default_end_date(self):
|
|
||||||
# Note: You may need to mock timezone.now() for accurate testing
|
|
||||||
expected_date = timezone.now()
|
|
||||||
actual_date = get_default_end_date()
|
|
||||||
self.assertEqual(actual_date.date(), expected_date.date())
|
|
||||||
|
|
||||||
def test_get_sliced_domains(self):
|
|
||||||
"""Should get fitered domains counts sliced by org type and election office."""
|
|
||||||
|
|
||||||
with less_console_noise():
|
|
||||||
filter_condition = {
|
|
||||||
"domain__permissions__isnull": False,
|
|
||||||
"domain__first_ready__lte": self.end_date,
|
|
||||||
}
|
|
||||||
# Test with distinct
|
|
||||||
managed_domains_sliced_at_end_date = get_sliced_domains(filter_condition)
|
|
||||||
expected_content = [3, 2, 1, 0, 0, 0, 0, 0, 0, 0]
|
|
||||||
self.assertEqual(managed_domains_sliced_at_end_date, expected_content)
|
|
||||||
|
|
||||||
# Test without distinct
|
|
||||||
managed_domains_sliced_at_end_date = get_sliced_domains(filter_condition)
|
|
||||||
expected_content = [3, 2, 1, 0, 0, 0, 0, 0, 0, 0]
|
|
||||||
self.assertEqual(managed_domains_sliced_at_end_date, expected_content)
|
|
||||||
|
|
||||||
def test_get_sliced_requests(self):
|
|
||||||
"""Should get fitered requests counts sliced by org type and election office."""
|
|
||||||
|
|
||||||
with less_console_noise():
|
|
||||||
filter_condition = {
|
|
||||||
"status": DomainRequest.DomainRequestStatus.SUBMITTED,
|
|
||||||
"submission_date__lte": self.end_date,
|
|
||||||
}
|
|
||||||
submitted_requests_sliced_at_end_date = get_sliced_requests(filter_condition)
|
|
||||||
expected_content = [2, 2, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
||||||
self.assertEqual(submitted_requests_sliced_at_end_date, expected_content)
|
|
||||||
|
|
||||||
|
|
||||||
class CsvReportsTest(MockDb):
|
class CsvReportsTest(MockDb):
|
||||||
|
@ -244,17 +194,17 @@ class CsvReportsTest(MockDb):
|
||||||
self.assertEqual(expected_file_content, response.content)
|
self.assertEqual(expected_file_content, response.content)
|
||||||
|
|
||||||
|
|
||||||
class ExportDataTest(HelperFunctions, MockEppLib):
|
class ExportDataTest(MockDb, MockEppLib):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@less_console_noise_decorator
|
|
||||||
def test_export_domains_to_writer_security_emails_and_first_ready(self):
|
def test_export_domains_to_writer_security_emails_and_first_ready(self):
|
||||||
"""Test that export_domains_to_writer returns the
|
"""Test that export_domains_to_writer returns the
|
||||||
expected security email and first_ready value"""
|
expected security email and first_ready value"""
|
||||||
|
with less_console_noise:
|
||||||
# Add security email information
|
# Add security email information
|
||||||
self.domain_1.name = "defaultsecurity.gov"
|
self.domain_1.name = "defaultsecurity.gov"
|
||||||
self.domain_1.save()
|
self.domain_1.save()
|
||||||
|
@ -747,3 +697,48 @@ class ExportDataTest(HelperFunctions, MockEppLib):
|
||||||
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
|
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
|
||||||
|
|
||||||
self.assertEqual(csv_content, expected_content)
|
self.assertEqual(csv_content, expected_content)
|
||||||
|
|
||||||
|
|
||||||
|
class HelperFunctions(MockDb):
|
||||||
|
"""This asserts that 1=1. Its limited usefulness lies in making sure the helper methods stay healthy."""
|
||||||
|
|
||||||
|
def test_get_default_start_date(self):
|
||||||
|
expected_date = self.get_time_aware_date()
|
||||||
|
actual_date = get_default_start_date()
|
||||||
|
self.assertEqual(actual_date, expected_date)
|
||||||
|
|
||||||
|
def test_get_default_end_date(self):
|
||||||
|
# Note: You may need to mock timezone.now() for accurate testing
|
||||||
|
expected_date = timezone.now()
|
||||||
|
actual_date = get_default_end_date()
|
||||||
|
self.assertEqual(actual_date.date(), expected_date.date())
|
||||||
|
|
||||||
|
def test_get_sliced_domains(self):
|
||||||
|
"""Should get fitered domains counts sliced by org type and election office."""
|
||||||
|
|
||||||
|
with less_console_noise():
|
||||||
|
filter_condition = {
|
||||||
|
"domain__permissions__isnull": False,
|
||||||
|
"domain__first_ready__lte": self.end_date,
|
||||||
|
}
|
||||||
|
# Test with distinct
|
||||||
|
managed_domains_sliced_at_end_date = get_sliced_domains(filter_condition)
|
||||||
|
expected_content = [3, 2, 1, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
self.assertEqual(managed_domains_sliced_at_end_date, expected_content)
|
||||||
|
|
||||||
|
# Test without distinct
|
||||||
|
managed_domains_sliced_at_end_date = get_sliced_domains(filter_condition)
|
||||||
|
expected_content = [3, 2, 1, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
self.assertEqual(managed_domains_sliced_at_end_date, expected_content)
|
||||||
|
|
||||||
|
def test_get_sliced_requests(self):
|
||||||
|
"""Should get fitered requests counts sliced by org type and election office."""
|
||||||
|
|
||||||
|
with less_console_noise():
|
||||||
|
filter_condition = {
|
||||||
|
"status": DomainRequest.DomainRequestStatus.SUBMITTED,
|
||||||
|
"submission_date__lte": self.end_date,
|
||||||
|
}
|
||||||
|
submitted_requests_sliced_at_end_date = get_sliced_requests(filter_condition)
|
||||||
|
expected_content = [2, 2, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
self.assertEqual(submitted_requests_sliced_at_end_date, expected_content)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue