Update test_reports.py

This commit is contained in:
zandercymatics 2024-07-18 13:06:24 -06:00
parent 4f2cedb308
commit e86a16d4d1
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -598,73 +598,6 @@ class ExportDataTest(MockDb, 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)
@less_console_noise_decorator
def test_domain_data_type_user(self):
"""Shows security contacts, domain managers, so for the current user"""
# We add these here due to a data interference issue with MockDB
new_domain_1, _ = Domain.objects.get_or_create(name="interfere.gov", state=Domain.State.READY)
new_domain_2, _ = Domain.objects.get_or_create(name="somedomain123.gov", state=Domain.State.DNS_NEEDED)
new_domain_3, _ = Domain.objects.get_or_create(name="noaccess.gov", state=Domain.State.ON_HOLD)
DomainInformation.objects.get_or_create(
creator=self.user,
domain=new_domain_1,
generic_org_type="federal",
federal_agency=self.federal_agency_1,
federal_type="executive",
is_election_board=False,
)
DomainInformation.objects.get_or_create(
creator=self.user, domain=new_domain_2, generic_org_type="interstate", is_election_board=True
)
DomainInformation.objects.get_or_create(
creator=self.user,
domain=new_domain_3,
generic_org_type="federal",
federal_agency=self.federal_agency_2,
is_election_board=False,
)
# Invoke setter
new_domain_1.security_contact
new_domain_2.security_contact
new_domain_3.security_contact
# Create a user and associate it with some domains
user = create_user()
UserDomainRole.objects.create(user=user, domain=new_domain_1)
UserDomainRole.objects.create(user=user, domain=new_domain_2)
# Create a request object
request = self.factory.get("/")
request.user = user
# Create a CSV file in memory
csv_file = StringIO()
# Call the export functions
DomainDataTypeUser.export_data_to_csv(csv_file, request=request)
# Reset the CSV file's position to the beginning
csv_file.seek(0)
# Read the content into a variable
csv_content = csv_file.read()
# We expect only domains associated with the user
expected_content = (
"Domain name,Status,First ready on,Expiration date,Domain type,Agency,Organization name,City,"
"State,SO,SO email,Security contact email,Domain managers,Invited domain managers\n"
"interfere.gov,Ready,(blank),2023-05-25,Federal - Executive,World War I Centennial Commission,,,"
", ,,security@mail.gov,staff@example.com,\n"
"somedomain123.gov,Dns needed,(blank),2023-05-25,Interstate,,,,, ,,"
"security@mail.gov,staff@example.com,\n"
)
# Normalize line endings and remove commas,
# spaces and leading/trailing whitespace
csv_content = csv_content.replace(",,", "").replace(",", "").replace(" ", "").replace("\r\n", "\n").strip()
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
self.maxDiff = None
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."""