mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-06 19:23:23 +02:00
Fix test
Wrong id check
This commit is contained in:
parent
0633ff9b0c
commit
7fc21ff726
2 changed files with 31 additions and 14 deletions
|
@ -208,12 +208,12 @@ class CsvReportsTest(MockDb):
|
||||||
|
|
||||||
|
|
||||||
# There seems to be a data interference issue with MockDb that affects only
|
# There seems to be a data interference issue with MockDb that affects only
|
||||||
# the entire test suite. For this test, we forgo that for now.
|
# the entire test suite when ran through our actions. For this test, we forgo that for now.
|
||||||
class ExportDataTestUserFacing(TestCase):
|
class ExportDataTestUserFacing(TestCase):
|
||||||
"""Tests our data exports for users"""
|
"""Tests our data exports for users"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.factory = RequestFactory()
|
self.client = Client(HTTP_HOST="localhost:8080")
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
PublicContact.objects.all().delete()
|
PublicContact.objects.all().delete()
|
||||||
|
@ -265,23 +265,40 @@ class ExportDataTestUserFacing(TestCase):
|
||||||
UserDomainRole.objects.create(user=user, domain=new_domain_1)
|
UserDomainRole.objects.create(user=user, domain=new_domain_1)
|
||||||
UserDomainRole.objects.create(user=user, domain=new_domain_2)
|
UserDomainRole.objects.create(user=user, domain=new_domain_2)
|
||||||
|
|
||||||
user.refresh_from_db()
|
p = "userpass"
|
||||||
|
self.client.login(username="staffuser", password=p)
|
||||||
|
response = self.client.get(
|
||||||
|
"/",
|
||||||
|
follow=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Create a request object
|
request = response.wsgi_request
|
||||||
request = self.factory.get("/")
|
|
||||||
request.user = user
|
|
||||||
|
|
||||||
# Create a CSV file in memory
|
# Create a CSV file in memory
|
||||||
csv_file = StringIO()
|
csv_file = StringIO()
|
||||||
|
|
||||||
# Call the export functions
|
# Call the export functions
|
||||||
rows = DomainDataTypeUser.export_data_to_csv(csv_file, request=request)
|
DomainDataTypeUser.export_data_to_csv(csv_file, request=request)
|
||||||
# Extract domain names from the list
|
# Reset the CSV file's position to the beginning
|
||||||
domain_names = [row[0] for row in rows]
|
csv_file.seek(0)
|
||||||
|
# Read the content into a variable
|
||||||
|
csv_content = csv_file.read()
|
||||||
|
|
||||||
self.assertIn("interfere.gov", domain_names)
|
# We expect only domains associated with the user
|
||||||
self.assertIn("somedomain1234.gov", domain_names)
|
expected_content = (
|
||||||
self.assertNotIn("noaccess.gov", domain_names)
|
"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)
|
||||||
|
|
||||||
|
|
||||||
class ExportDataTest(MockDb, MockEppLib):
|
class ExportDataTest(MockDb, MockEppLib):
|
||||||
|
|
|
@ -576,7 +576,7 @@ class DomainDataTypeUser(DomainDataType):
|
||||||
|
|
||||||
user_domain_roles = UserDomainRole.objects.filter(user=request.user)
|
user_domain_roles = UserDomainRole.objects.filter(user=request.user)
|
||||||
domain_ids = user_domain_roles.values_list("domain_id", flat=True)
|
domain_ids = user_domain_roles.values_list("domain_id", flat=True)
|
||||||
return Q(id__in=domain_ids)
|
return Q(domain__id__in=domain_ids)
|
||||||
|
|
||||||
|
|
||||||
class DomainDataFull(DomainExport):
|
class DomainDataFull(DomainExport):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue