This commit is contained in:
Rachid Mrad 2024-03-05 14:41:34 -05:00
parent f7856d52fe
commit 2081f5c564
No known key found for this signature in database
4 changed files with 86 additions and 62 deletions

View file

@ -1,4 +1,3 @@
import datetime
import os
import logging
@ -474,6 +473,7 @@ class AuditedAdminMockData:
return application
class MockDb(TestCase):
"""Hardcoded mocks make test case assertions sraightforward."""
@ -535,69 +535,66 @@ class MockDb(TestCase):
organization_type="federal",
federal_agency="World War I Centennial Commission",
federal_type="executive",
is_election_board=True
is_election_board=True,
)
self.domain_information_2, _ = DomainInformation.objects.get_or_create(
creator=self.user,
domain=self.domain_2,
organization_type="interstate",
is_election_board=True
creator=self.user, domain=self.domain_2, organization_type="interstate", is_election_board=True
)
self.domain_information_3, _ = DomainInformation.objects.get_or_create(
creator=self.user,
domain=self.domain_3,
organization_type="federal",
federal_agency="Armed Forces Retirement Home",
is_election_board=True
is_election_board=True,
)
self.domain_information_4, _ = DomainInformation.objects.get_or_create(
creator=self.user,
domain=self.domain_4,
organization_type="federal",
federal_agency="Armed Forces Retirement Home",
is_election_board=True
is_election_board=True,
)
self.domain_information_5, _ = DomainInformation.objects.get_or_create(
creator=self.user,
domain=self.domain_5,
organization_type="federal",
federal_agency="Armed Forces Retirement Home",
is_election_board=False
is_election_board=False,
)
self.domain_information_6, _ = DomainInformation.objects.get_or_create(
creator=self.user,
domain=self.domain_6,
organization_type="federal",
federal_agency="Armed Forces Retirement Home",
is_election_board=False
is_election_board=False,
)
self.domain_information_7, _ = DomainInformation.objects.get_or_create(
creator=self.user,
domain=self.domain_7,
organization_type="federal",
federal_agency="Armed Forces Retirement Home",
is_election_board=False
is_election_board=False,
)
self.domain_information_8, _ = DomainInformation.objects.get_or_create(
creator=self.user,
domain=self.domain_8,
organization_type="federal",
federal_agency="Armed Forces Retirement Home",
is_election_board=False
is_election_board=False,
)
self.domain_information_9, _ = DomainInformation.objects.get_or_create(
creator=self.user,
domain=self.domain_9,
organization_type="federal",
federal_agency="Armed Forces Retirement Home",
is_election_board=False
is_election_board=False,
)
self.domain_information_10, _ = DomainInformation.objects.get_or_create(
creator=self.user,
domain=self.domain_10,
organization_type="federal",
federal_agency="Armed Forces Retirement Home",
is_election_board=False
is_election_board=False,
)
meoward_user = get_user_model().objects.create(
@ -625,11 +622,21 @@ class MockDb(TestCase):
)
with less_console_noise():
self.domain_request_1 = completed_application(status=DomainApplication.ApplicationStatus.STARTED, name="city1.gov")
self.domain_request_2 = completed_application(status=DomainApplication.ApplicationStatus.IN_REVIEW, name="city2.gov")
self.domain_request_3 = completed_application(status=DomainApplication.ApplicationStatus.STARTED, name="city3.gov")
self.domain_request_4 = completed_application(status=DomainApplication.ApplicationStatus.STARTED, name="city4.gov")
self.domain_request_5 = completed_application(status=DomainApplication.ApplicationStatus.APPROVED, name="city5.gov")
self.domain_request_1 = completed_application(
status=DomainApplication.ApplicationStatus.STARTED, name="city1.gov"
)
self.domain_request_2 = completed_application(
status=DomainApplication.ApplicationStatus.IN_REVIEW, name="city2.gov"
)
self.domain_request_3 = completed_application(
status=DomainApplication.ApplicationStatus.STARTED, name="city3.gov"
)
self.domain_request_4 = completed_application(
status=DomainApplication.ApplicationStatus.STARTED, name="city4.gov"
)
self.domain_request_5 = completed_application(
status=DomainApplication.ApplicationStatus.APPROVED, name="city5.gov"
)
self.domain_request_3.submit()
self.domain_request_3.save()
self.domain_request_4.submit()

View file

@ -43,7 +43,7 @@ class CsvReportsTest(MockDb):
expected_file_content = [
call("Domain name,Domain type,Agency,Organization name,City,State,Security contact email\r\n"),
call("cdomain1.gov,Federal - Executive,World War I Centennial Commission,,,, \r\n"),
call('adomain10.gov,Federal,Armed Forces Retirement Home,,,, \r\n'),
call("adomain10.gov,Federal,Armed Forces Retirement Home,,,, \r\n"),
call("ddomain3.gov,Federal,Armed Forces Retirement Home,,,, \r\n"),
]
# We don't actually want to write anything for a test case,
@ -64,7 +64,7 @@ class CsvReportsTest(MockDb):
expected_file_content = [
call("Domain name,Domain type,Agency,Organization name,City,State,Security contact email\r\n"),
call("cdomain1.gov,Federal - Executive,World War I Centennial Commission,,,, \r\n"),
call('adomain10.gov,Federal,Armed Forces Retirement Home,,,, \r\n'),
call("adomain10.gov,Federal,Armed Forces Retirement Home,,,, \r\n"),
call("ddomain3.gov,Federal,Armed Forces Retirement Home,,,, \r\n"),
call("adomain2.gov,Interstate,,,,, \r\n"),
]
@ -600,11 +600,13 @@ class ExportDataTest(MockDb, MockEppLib):
# We expect the READY domain names with the domain managers: Their counts, and listing at end_date.
expected_content = (
"MANAGED DOMAINS COUNTS AT START DATE\n"
"Total,Federal,Interstate,State or territory,Tribal,County,City,Special district,School district,Election office\n"
"Total,Federal,Interstate,State or territory,Tribal,County,City,Special district,"
"School district,Election office\n"
"0,0,0,0,0,0,0,0,0,0\n"
"\n"
"MANAGED DOMAINS COUNTS AT END DATE\n"
"Total,Federal,Interstate,State or territory,Tribal,County,City,Special district,School district,Election office\n"
"Total,Federal,Interstate,State or territory,Tribal,County,City,"
"Special district,School district,Election office\n"
"1,1,0,0,0,0,0,0,0,1\n"
"\n"
"Domain name,Domain type,Domain manager email 1,Domain manager email 2,Domain manager email 3\n"
@ -695,11 +697,13 @@ class ExportDataTest(MockDb, MockEppLib):
# We expect the READY domain names with the domain managers: Their counts, and listing at end_date.
expected_content = (
"UNMANAGED DOMAINS COUNTS AT START DATE\n"
"Total,Federal,Interstate,State or territory,Tribal,County,City,Special district,School district,Election office\n"
"Total,Federal,Interstate,State or territory,Tribal,County,City,Special district,"
"School district,Election office\n"
"0,0,0,0,0,0,0,0,0,0\n"
"\n"
"UNMANAGED DOMAINS COUNTS AT END DATE\n"
"Total,Federal,Interstate,State or territory,Tribal,County,City,Special district,School district,Election office\n"
"Total,Federal,Interstate,State or territory,Tribal,County,City,Special district,"
"School district,Election office\n"
"1,1,0,0,0,0,0,0,0,0\n"
"\n"
"Domain name,Domain type\n"
@ -758,6 +762,7 @@ class ExportDataTest(MockDb, MockEppLib):
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."""
@ -781,9 +786,7 @@ class HelperFunctions(MockDb):
"domain__first_ready__lte": self.end_date,
}
managed_domains_sliced_at_end_date = get_sliced_domains(filter_condition)
expected_content = (
[1, 1, 0, 0, 0, 0, 0, 0, 0, 1]
)
expected_content = [1, 1, 0, 0, 0, 0, 0, 0, 0, 1]
self.assertEqual(managed_domains_sliced_at_end_date, expected_content)
def test_get_sliced_requests(self):
@ -795,7 +798,5 @@ class HelperFunctions(MockDb):
"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]
)
expected_content = [2, 2, 0, 0, 0, 0, 0, 0, 0, 0]
self.assertEqual(submitted_requests_sliced_at_end_date, expected_content)

View file

@ -128,6 +128,7 @@ def _get_security_emails(sec_contact_ids):
return security_emails_dict
def write_domains_csv(
writer,
columns,
@ -253,7 +254,6 @@ def write_requests_csv(
logger.error("csv_export -> Error when parsing row, domain was None")
continue
if should_write_header:
write_header(writer, columns)
writer.writerows(rows)
@ -293,7 +293,9 @@ def export_data_type_to_csv(csv_file):
Domain.State.ON_HOLD,
],
}
write_domains_csv(writer, columns, sort_fields, filter_condition, get_domain_managers=True, should_write_header=True)
write_domains_csv(
writer, columns, sort_fields, filter_condition, get_domain_managers=True, should_write_header=True
)
def export_data_full_to_csv(csv_file):
@ -324,7 +326,9 @@ def export_data_full_to_csv(csv_file):
Domain.State.ON_HOLD,
],
}
write_domains_csv(writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True)
write_domains_csv(
writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True
)
def export_data_federal_to_csv(csv_file):
@ -356,7 +360,9 @@ def export_data_federal_to_csv(csv_file):
Domain.State.ON_HOLD,
],
}
write_domains_csv(writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True)
write_domains_csv(
writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True
)
def get_default_start_date():
@ -424,7 +430,9 @@ def export_data_domain_growth_to_csv(csv_file, start_date, end_date):
"domain__deleted__gte": start_date_formatted,
}
write_domains_csv(writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True)
write_domains_csv(
writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True
)
write_domains_csv(
writer,
columns,
@ -442,14 +450,18 @@ def get_sliced_domains(filter_condition):
domains_count = domains.count()
federal = domains.filter(organization_type=DomainApplication.OrganizationChoices.FEDERAL).distinct().count()
interstate = domains.filter(organization_type=DomainApplication.OrganizationChoices.INTERSTATE).count()
state_or_territory = domains.filter(
organization_type=DomainApplication.OrganizationChoices.STATE_OR_TERRITORY
).distinct().count()
state_or_territory = (
domains.filter(organization_type=DomainApplication.OrganizationChoices.STATE_OR_TERRITORY).distinct().count()
)
tribal = domains.filter(organization_type=DomainApplication.OrganizationChoices.TRIBAL).distinct().count()
county = domains.filter(organization_type=DomainApplication.OrganizationChoices.COUNTY).distinct().count()
city = domains.filter(organization_type=DomainApplication.OrganizationChoices.CITY).distinct().count()
special_district = domains.filter(organization_type=DomainApplication.OrganizationChoices.SPECIAL_DISTRICT).distinct().count()
school_district = domains.filter(organization_type=DomainApplication.OrganizationChoices.SCHOOL_DISTRICT).distinct().count()
special_district = (
domains.filter(organization_type=DomainApplication.OrganizationChoices.SPECIAL_DISTRICT).distinct().count()
)
school_district = (
domains.filter(organization_type=DomainApplication.OrganizationChoices.SCHOOL_DISTRICT).distinct().count()
)
election_board = domains.filter(is_election_board=True).distinct().count()
return [
@ -473,14 +485,18 @@ def get_sliced_requests(filter_condition):
requests_count = requests.count()
federal = requests.filter(organization_type=DomainApplication.OrganizationChoices.FEDERAL).distinct().count()
interstate = requests.filter(organization_type=DomainApplication.OrganizationChoices.INTERSTATE).distinct().count()
state_or_territory = requests.filter(
organization_type=DomainApplication.OrganizationChoices.STATE_OR_TERRITORY
).distinct().count()
state_or_territory = (
requests.filter(organization_type=DomainApplication.OrganizationChoices.STATE_OR_TERRITORY).distinct().count()
)
tribal = requests.filter(organization_type=DomainApplication.OrganizationChoices.TRIBAL).distinct().count()
county = requests.filter(organization_type=DomainApplication.OrganizationChoices.COUNTY).distinct().count()
city = requests.filter(organization_type=DomainApplication.OrganizationChoices.CITY).distinct().count()
special_district = requests.filter(organization_type=DomainApplication.OrganizationChoices.SPECIAL_DISTRICT).distinct().count()
school_district = requests.filter(organization_type=DomainApplication.OrganizationChoices.SCHOOL_DISTRICT).distinct().count()
special_district = (
requests.filter(organization_type=DomainApplication.OrganizationChoices.SPECIAL_DISTRICT).distinct().count()
)
school_district = (
requests.filter(organization_type=DomainApplication.OrganizationChoices.SCHOOL_DISTRICT).distinct().count()
)
election_board = requests.filter(is_election_board=True).distinct().count()
return [