mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-20 03:19:24 +02:00
lint
This commit is contained in:
parent
f7856d52fe
commit
2081f5c564
4 changed files with 86 additions and 62 deletions
|
@ -1,4 +1,3 @@
|
||||||
import datetime
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -474,6 +473,7 @@ class AuditedAdminMockData:
|
||||||
|
|
||||||
return application
|
return application
|
||||||
|
|
||||||
|
|
||||||
class MockDb(TestCase):
|
class MockDb(TestCase):
|
||||||
"""Hardcoded mocks make test case assertions sraightforward."""
|
"""Hardcoded mocks make test case assertions sraightforward."""
|
||||||
|
|
||||||
|
@ -535,69 +535,66 @@ class MockDb(TestCase):
|
||||||
organization_type="federal",
|
organization_type="federal",
|
||||||
federal_agency="World War I Centennial Commission",
|
federal_agency="World War I Centennial Commission",
|
||||||
federal_type="executive",
|
federal_type="executive",
|
||||||
is_election_board=True
|
is_election_board=True,
|
||||||
)
|
)
|
||||||
self.domain_information_2, _ = DomainInformation.objects.get_or_create(
|
self.domain_information_2, _ = DomainInformation.objects.get_or_create(
|
||||||
creator=self.user,
|
creator=self.user, domain=self.domain_2, organization_type="interstate", is_election_board=True
|
||||||
domain=self.domain_2,
|
|
||||||
organization_type="interstate",
|
|
||||||
is_election_board=True
|
|
||||||
)
|
)
|
||||||
self.domain_information_3, _ = DomainInformation.objects.get_or_create(
|
self.domain_information_3, _ = DomainInformation.objects.get_or_create(
|
||||||
creator=self.user,
|
creator=self.user,
|
||||||
domain=self.domain_3,
|
domain=self.domain_3,
|
||||||
organization_type="federal",
|
organization_type="federal",
|
||||||
federal_agency="Armed Forces Retirement Home",
|
federal_agency="Armed Forces Retirement Home",
|
||||||
is_election_board=True
|
is_election_board=True,
|
||||||
)
|
)
|
||||||
self.domain_information_4, _ = DomainInformation.objects.get_or_create(
|
self.domain_information_4, _ = DomainInformation.objects.get_or_create(
|
||||||
creator=self.user,
|
creator=self.user,
|
||||||
domain=self.domain_4,
|
domain=self.domain_4,
|
||||||
organization_type="federal",
|
organization_type="federal",
|
||||||
federal_agency="Armed Forces Retirement Home",
|
federal_agency="Armed Forces Retirement Home",
|
||||||
is_election_board=True
|
is_election_board=True,
|
||||||
)
|
)
|
||||||
self.domain_information_5, _ = DomainInformation.objects.get_or_create(
|
self.domain_information_5, _ = DomainInformation.objects.get_or_create(
|
||||||
creator=self.user,
|
creator=self.user,
|
||||||
domain=self.domain_5,
|
domain=self.domain_5,
|
||||||
organization_type="federal",
|
organization_type="federal",
|
||||||
federal_agency="Armed Forces Retirement Home",
|
federal_agency="Armed Forces Retirement Home",
|
||||||
is_election_board=False
|
is_election_board=False,
|
||||||
)
|
)
|
||||||
self.domain_information_6, _ = DomainInformation.objects.get_or_create(
|
self.domain_information_6, _ = DomainInformation.objects.get_or_create(
|
||||||
creator=self.user,
|
creator=self.user,
|
||||||
domain=self.domain_6,
|
domain=self.domain_6,
|
||||||
organization_type="federal",
|
organization_type="federal",
|
||||||
federal_agency="Armed Forces Retirement Home",
|
federal_agency="Armed Forces Retirement Home",
|
||||||
is_election_board=False
|
is_election_board=False,
|
||||||
)
|
)
|
||||||
self.domain_information_7, _ = DomainInformation.objects.get_or_create(
|
self.domain_information_7, _ = DomainInformation.objects.get_or_create(
|
||||||
creator=self.user,
|
creator=self.user,
|
||||||
domain=self.domain_7,
|
domain=self.domain_7,
|
||||||
organization_type="federal",
|
organization_type="federal",
|
||||||
federal_agency="Armed Forces Retirement Home",
|
federal_agency="Armed Forces Retirement Home",
|
||||||
is_election_board=False
|
is_election_board=False,
|
||||||
)
|
)
|
||||||
self.domain_information_8, _ = DomainInformation.objects.get_or_create(
|
self.domain_information_8, _ = DomainInformation.objects.get_or_create(
|
||||||
creator=self.user,
|
creator=self.user,
|
||||||
domain=self.domain_8,
|
domain=self.domain_8,
|
||||||
organization_type="federal",
|
organization_type="federal",
|
||||||
federal_agency="Armed Forces Retirement Home",
|
federal_agency="Armed Forces Retirement Home",
|
||||||
is_election_board=False
|
is_election_board=False,
|
||||||
)
|
)
|
||||||
self.domain_information_9, _ = DomainInformation.objects.get_or_create(
|
self.domain_information_9, _ = DomainInformation.objects.get_or_create(
|
||||||
creator=self.user,
|
creator=self.user,
|
||||||
domain=self.domain_9,
|
domain=self.domain_9,
|
||||||
organization_type="federal",
|
organization_type="federal",
|
||||||
federal_agency="Armed Forces Retirement Home",
|
federal_agency="Armed Forces Retirement Home",
|
||||||
is_election_board=False
|
is_election_board=False,
|
||||||
)
|
)
|
||||||
self.domain_information_10, _ = DomainInformation.objects.get_or_create(
|
self.domain_information_10, _ = DomainInformation.objects.get_or_create(
|
||||||
creator=self.user,
|
creator=self.user,
|
||||||
domain=self.domain_10,
|
domain=self.domain_10,
|
||||||
organization_type="federal",
|
organization_type="federal",
|
||||||
federal_agency="Armed Forces Retirement Home",
|
federal_agency="Armed Forces Retirement Home",
|
||||||
is_election_board=False
|
is_election_board=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
meoward_user = get_user_model().objects.create(
|
meoward_user = get_user_model().objects.create(
|
||||||
|
@ -625,11 +622,21 @@ class MockDb(TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
self.domain_request_1 = completed_application(status=DomainApplication.ApplicationStatus.STARTED, name="city1.gov")
|
self.domain_request_1 = completed_application(
|
||||||
self.domain_request_2 = completed_application(status=DomainApplication.ApplicationStatus.IN_REVIEW, name="city2.gov")
|
status=DomainApplication.ApplicationStatus.STARTED, name="city1.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_2 = completed_application(
|
||||||
self.domain_request_5 = completed_application(status=DomainApplication.ApplicationStatus.APPROVED, name="city5.gov")
|
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.submit()
|
||||||
self.domain_request_3.save()
|
self.domain_request_3.save()
|
||||||
self.domain_request_4.submit()
|
self.domain_request_4.submit()
|
||||||
|
|
|
@ -43,7 +43,7 @@ class CsvReportsTest(MockDb):
|
||||||
expected_file_content = [
|
expected_file_content = [
|
||||||
call("Domain name,Domain type,Agency,Organization name,City,State,Security contact email\r\n"),
|
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("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("ddomain3.gov,Federal,Armed Forces Retirement Home,,,, \r\n"),
|
||||||
]
|
]
|
||||||
# We don't actually want to write anything for a test case,
|
# We don't actually want to write anything for a test case,
|
||||||
|
@ -64,7 +64,7 @@ class CsvReportsTest(MockDb):
|
||||||
expected_file_content = [
|
expected_file_content = [
|
||||||
call("Domain name,Domain type,Agency,Organization name,City,State,Security contact email\r\n"),
|
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("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("ddomain3.gov,Federal,Armed Forces Retirement Home,,,, \r\n"),
|
||||||
call("adomain2.gov,Interstate,,,,, \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.
|
# We expect the READY domain names with the domain managers: Their counts, and listing at end_date.
|
||||||
expected_content = (
|
expected_content = (
|
||||||
"MANAGED DOMAINS COUNTS AT START DATE\n"
|
"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"
|
"0,0,0,0,0,0,0,0,0,0\n"
|
||||||
"\n"
|
"\n"
|
||||||
"MANAGED DOMAINS COUNTS AT END DATE\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"
|
"1,1,0,0,0,0,0,0,0,1\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Domain name,Domain type,Domain manager email 1,Domain manager email 2,Domain manager email 3\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.
|
# We expect the READY domain names with the domain managers: Their counts, and listing at end_date.
|
||||||
expected_content = (
|
expected_content = (
|
||||||
"UNMANAGED DOMAINS COUNTS AT START DATE\n"
|
"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"
|
"0,0,0,0,0,0,0,0,0,0\n"
|
||||||
"\n"
|
"\n"
|
||||||
"UNMANAGED DOMAINS COUNTS AT END DATE\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"
|
"1,1,0,0,0,0,0,0,0,0\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Domain name,Domain type\n"
|
"Domain name,Domain type\n"
|
||||||
|
@ -758,6 +762,7 @@ class ExportDataTest(MockDb, MockEppLib):
|
||||||
|
|
||||||
self.assertEqual(csv_content, expected_content)
|
self.assertEqual(csv_content, expected_content)
|
||||||
|
|
||||||
|
|
||||||
class HelperFunctions(MockDb):
|
class HelperFunctions(MockDb):
|
||||||
"""This asserts that 1=1. Its limited usefulness lies in making sure the helper methods stay healthy."""
|
"""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,
|
"domain__first_ready__lte": self.end_date,
|
||||||
}
|
}
|
||||||
managed_domains_sliced_at_end_date = get_sliced_domains(filter_condition)
|
managed_domains_sliced_at_end_date = get_sliced_domains(filter_condition)
|
||||||
expected_content = (
|
expected_content = [1, 1, 0, 0, 0, 0, 0, 0, 0, 1]
|
||||||
[1, 1, 0, 0, 0, 0, 0, 0, 0, 1]
|
|
||||||
)
|
|
||||||
self.assertEqual(managed_domains_sliced_at_end_date, expected_content)
|
self.assertEqual(managed_domains_sliced_at_end_date, expected_content)
|
||||||
|
|
||||||
def test_get_sliced_requests(self):
|
def test_get_sliced_requests(self):
|
||||||
|
@ -795,7 +798,5 @@ class HelperFunctions(MockDb):
|
||||||
"submission_date__lte": self.end_date,
|
"submission_date__lte": self.end_date,
|
||||||
}
|
}
|
||||||
submitted_requests_sliced_at_end_date = get_sliced_requests(filter_condition)
|
submitted_requests_sliced_at_end_date = get_sliced_requests(filter_condition)
|
||||||
expected_content = (
|
expected_content = [2, 2, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
[2, 2, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
||||||
)
|
|
||||||
self.assertEqual(submitted_requests_sliced_at_end_date, expected_content)
|
self.assertEqual(submitted_requests_sliced_at_end_date, expected_content)
|
|
@ -128,6 +128,7 @@ def _get_security_emails(sec_contact_ids):
|
||||||
|
|
||||||
return security_emails_dict
|
return security_emails_dict
|
||||||
|
|
||||||
|
|
||||||
def write_domains_csv(
|
def write_domains_csv(
|
||||||
writer,
|
writer,
|
||||||
columns,
|
columns,
|
||||||
|
@ -253,7 +254,6 @@ def write_requests_csv(
|
||||||
logger.error("csv_export -> Error when parsing row, domain was None")
|
logger.error("csv_export -> Error when parsing row, domain was None")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
if should_write_header:
|
if should_write_header:
|
||||||
write_header(writer, columns)
|
write_header(writer, columns)
|
||||||
writer.writerows(rows)
|
writer.writerows(rows)
|
||||||
|
@ -293,7 +293,9 @@ def export_data_type_to_csv(csv_file):
|
||||||
Domain.State.ON_HOLD,
|
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):
|
def export_data_full_to_csv(csv_file):
|
||||||
|
@ -324,7 +326,9 @@ def export_data_full_to_csv(csv_file):
|
||||||
Domain.State.ON_HOLD,
|
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):
|
def export_data_federal_to_csv(csv_file):
|
||||||
|
@ -356,7 +360,9 @@ def export_data_federal_to_csv(csv_file):
|
||||||
Domain.State.ON_HOLD,
|
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():
|
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,
|
"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(
|
write_domains_csv(
|
||||||
writer,
|
writer,
|
||||||
columns,
|
columns,
|
||||||
|
@ -442,14 +450,18 @@ def get_sliced_domains(filter_condition):
|
||||||
domains_count = domains.count()
|
domains_count = domains.count()
|
||||||
federal = domains.filter(organization_type=DomainApplication.OrganizationChoices.FEDERAL).distinct().count()
|
federal = domains.filter(organization_type=DomainApplication.OrganizationChoices.FEDERAL).distinct().count()
|
||||||
interstate = domains.filter(organization_type=DomainApplication.OrganizationChoices.INTERSTATE).count()
|
interstate = domains.filter(organization_type=DomainApplication.OrganizationChoices.INTERSTATE).count()
|
||||||
state_or_territory = domains.filter(
|
state_or_territory = (
|
||||||
organization_type=DomainApplication.OrganizationChoices.STATE_OR_TERRITORY
|
domains.filter(organization_type=DomainApplication.OrganizationChoices.STATE_OR_TERRITORY).distinct().count()
|
||||||
).distinct().count()
|
)
|
||||||
tribal = domains.filter(organization_type=DomainApplication.OrganizationChoices.TRIBAL).distinct().count()
|
tribal = domains.filter(organization_type=DomainApplication.OrganizationChoices.TRIBAL).distinct().count()
|
||||||
county = domains.filter(organization_type=DomainApplication.OrganizationChoices.COUNTY).distinct().count()
|
county = domains.filter(organization_type=DomainApplication.OrganizationChoices.COUNTY).distinct().count()
|
||||||
city = domains.filter(organization_type=DomainApplication.OrganizationChoices.CITY).distinct().count()
|
city = domains.filter(organization_type=DomainApplication.OrganizationChoices.CITY).distinct().count()
|
||||||
special_district = domains.filter(organization_type=DomainApplication.OrganizationChoices.SPECIAL_DISTRICT).distinct().count()
|
special_district = (
|
||||||
school_district = domains.filter(organization_type=DomainApplication.OrganizationChoices.SCHOOL_DISTRICT).distinct().count()
|
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()
|
election_board = domains.filter(is_election_board=True).distinct().count()
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -473,14 +485,18 @@ def get_sliced_requests(filter_condition):
|
||||||
requests_count = requests.count()
|
requests_count = requests.count()
|
||||||
federal = requests.filter(organization_type=DomainApplication.OrganizationChoices.FEDERAL).distinct().count()
|
federal = requests.filter(organization_type=DomainApplication.OrganizationChoices.FEDERAL).distinct().count()
|
||||||
interstate = requests.filter(organization_type=DomainApplication.OrganizationChoices.INTERSTATE).distinct().count()
|
interstate = requests.filter(organization_type=DomainApplication.OrganizationChoices.INTERSTATE).distinct().count()
|
||||||
state_or_territory = requests.filter(
|
state_or_territory = (
|
||||||
organization_type=DomainApplication.OrganizationChoices.STATE_OR_TERRITORY
|
requests.filter(organization_type=DomainApplication.OrganizationChoices.STATE_OR_TERRITORY).distinct().count()
|
||||||
).distinct().count()
|
)
|
||||||
tribal = requests.filter(organization_type=DomainApplication.OrganizationChoices.TRIBAL).distinct().count()
|
tribal = requests.filter(organization_type=DomainApplication.OrganizationChoices.TRIBAL).distinct().count()
|
||||||
county = requests.filter(organization_type=DomainApplication.OrganizationChoices.COUNTY).distinct().count()
|
county = requests.filter(organization_type=DomainApplication.OrganizationChoices.COUNTY).distinct().count()
|
||||||
city = requests.filter(organization_type=DomainApplication.OrganizationChoices.CITY).distinct().count()
|
city = requests.filter(organization_type=DomainApplication.OrganizationChoices.CITY).distinct().count()
|
||||||
special_district = requests.filter(organization_type=DomainApplication.OrganizationChoices.SPECIAL_DISTRICT).distinct().count()
|
special_district = (
|
||||||
school_district = requests.filter(organization_type=DomainApplication.OrganizationChoices.SCHOOL_DISTRICT).distinct().count()
|
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()
|
election_board = requests.filter(is_election_board=True).distinct().count()
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue