Try a different test approach

This commit is contained in:
zandercymatics 2024-07-19 10:28:50 -06:00
parent 0aa1309843
commit 7d88a13676
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 15 additions and 31 deletions

View file

@ -225,7 +225,7 @@ class ExportDataTestUserFacing(TestCase):
DomainInvitation.objects.all().delete()
FederalAgency.objects.all().delete()
# @less_console_noise_decorator
@less_console_noise_decorator
def test_domain_data_type_user(self):
"""Shows security contacts, domain managers, so for the current user"""
@ -269,32 +269,17 @@ class ExportDataTestUserFacing(TestCase):
request = self.factory.get("/")
request.user = user
print(f"what is the request? {request}")
# 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()
rows = DomainDataTypeUser.export_data_to_csv(csv_file, request=request)
# Extract domain names from the list
domain_names = [row[0] for row in rows]
# 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),(blank),Federal - Executive,,,"
", ,,(blank),staff@example.com,\n"
"somedomain1234.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,"
"(blank),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)
self.assertIn("interfere.gov", domain_names)
self.assertIn("somedomain1234.gov", domain_names)
self.assertNotIn("noaccess.gov", domain_names)
class ExportDataTest(MockDb, MockEppLib):