mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-31 09:43:54 +02:00
Split out tests
Seem to be running into some kind of flakiness with the exportdatatest class. Splitting this test out
This commit is contained in:
parent
9672def34d
commit
c0a86ce2eb
1 changed files with 62 additions and 50 deletions
|
@ -200,7 +200,9 @@ class CsvReportsTest(MockDb):
|
||||||
self.assertEqual(expected_file_content, response.content)
|
self.assertEqual(expected_file_content, response.content)
|
||||||
|
|
||||||
|
|
||||||
class ExportDataTest(MockDb, MockEppLib):
|
class ExportDataTestUserFacing(MockDb, MockEppLib):
|
||||||
|
"""Tests our data exports for users"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
|
@ -208,6 +210,65 @@ class ExportDataTest(MockDb, MockEppLib):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_domain_data_type_user(self):
|
||||||
|
"""Shows security contacts, domain managers, so for the current user"""
|
||||||
|
self.maxDiff = None
|
||||||
|
# Add security email information
|
||||||
|
self.domain_1.name = "defaultsecurity.gov"
|
||||||
|
self.domain_1.save()
|
||||||
|
# Invoke setter
|
||||||
|
self.domain_1.security_contact
|
||||||
|
self.domain_2.security_contact
|
||||||
|
self.domain_3.security_contact
|
||||||
|
# Add a first ready date on the first domain. Leaving the others blank.
|
||||||
|
self.domain_1.first_ready = get_default_start_date()
|
||||||
|
self.domain_1.save()
|
||||||
|
|
||||||
|
# Create a user and associate it with some domains
|
||||||
|
user = create_user()
|
||||||
|
UserDomainRole.objects.create(user=user, domain=self.domain_1)
|
||||||
|
UserDomainRole.objects.create(user=user, domain=self.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"
|
||||||
|
"defaultsecurity.gov,Ready,2023-11-01,(blank),Federal - Executive,World War I Centennial Commission,,,, ,"
|
||||||
|
',dotgov@cisa.dhs.gov,"meoward@rocks.com, info@example.com, big_lebowski@dude.co, staff@example.com",'
|
||||||
|
"woofwardthethird@rocks.com\n"
|
||||||
|
"adomain2.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,registrar@dotgov.gov,"
|
||||||
|
'"meoward@rocks.com, staff@example.com",squeaker@rocks.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.assertEqual(csv_content, expected_content)
|
||||||
|
|
||||||
|
|
||||||
|
class ExportDataTestAdmin(MockDb, MockEppLib):
|
||||||
|
"""Tests our data exports for admin"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super().tearDown()
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_domain_data_type(self):
|
def test_domain_data_type(self):
|
||||||
"""Shows security contacts, domain managers, so"""
|
"""Shows security contacts, domain managers, so"""
|
||||||
|
@ -263,55 +324,6 @@ class ExportDataTest(MockDb, MockEppLib):
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
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"""
|
|
||||||
self.maxDiff = None
|
|
||||||
# Add security email information
|
|
||||||
self.domain_1.name = "defaultsecurity.gov"
|
|
||||||
self.domain_1.save()
|
|
||||||
# Invoke setter
|
|
||||||
self.domain_1.security_contact
|
|
||||||
self.domain_2.security_contact
|
|
||||||
self.domain_3.security_contact
|
|
||||||
# Add a first ready date on the first domain. Leaving the others blank.
|
|
||||||
self.domain_1.first_ready = get_default_start_date()
|
|
||||||
self.domain_1.save()
|
|
||||||
|
|
||||||
# Create a user and associate it with some domains
|
|
||||||
user = create_user()
|
|
||||||
UserDomainRole.objects.create(user=user, domain=self.domain_1)
|
|
||||||
UserDomainRole.objects.create(user=user, domain=self.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"
|
|
||||||
"defaultsecurity.gov,Ready,2023-11-01,(blank),Federal - Executive,World War I Centennial Commission,,,, ,"
|
|
||||||
',dotgov@cisa.dhs.gov,"meoward@rocks.com, info@example.com, big_lebowski@dude.co, staff@example.com",'
|
|
||||||
"woofwardthethird@rocks.com\n"
|
|
||||||
"adomain2.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,registrar@dotgov.gov,"
|
|
||||||
'"meoward@rocks.com, staff@example.com",squeaker@rocks.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.assertEqual(csv_content, expected_content)
|
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_domain_data_full(self):
|
def test_domain_data_full(self):
|
||||||
"""Shows security contacts, filtered by state"""
|
"""Shows security contacts, filtered by state"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue