mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-30 01:10:04 +02:00
Add back deleted unit test
This commit is contained in:
parent
cb7eec6b02
commit
d49b42dacf
2 changed files with 78 additions and 1 deletions
|
@ -7,6 +7,7 @@ from registrar.models.domain import Domain
|
||||||
from registrar.models.public_contact import PublicContact
|
from registrar.models.public_contact import PublicContact
|
||||||
from registrar.models.user import User
|
from registrar.models.user import User
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from registrar.tests.common import MockEppLib
|
||||||
from registrar.utility.csv_export import (
|
from registrar.utility.csv_export import (
|
||||||
write_header,
|
write_header,
|
||||||
write_body,
|
write_body,
|
||||||
|
@ -222,7 +223,7 @@ class CsvReportsTest(TestCase):
|
||||||
self.assertEqual(expected_file_content, response.content)
|
self.assertEqual(expected_file_content, response.content)
|
||||||
|
|
||||||
|
|
||||||
class ExportDataTest(TestCase):
|
class ExportDataTest(MockEppLib):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
username = "test_user"
|
username = "test_user"
|
||||||
|
@ -335,6 +336,80 @@ class ExportDataTest(TestCase):
|
||||||
User.objects.all().delete()
|
User.objects.all().delete()
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
def test_export_domains_to_writer_security_emails(self):
|
||||||
|
"""Test that export_domains_to_writer returns the
|
||||||
|
expected security email"""
|
||||||
|
|
||||||
|
# Add security email information
|
||||||
|
self.domain_1.name = "defaultsecurity.gov"
|
||||||
|
self.domain_1.save()
|
||||||
|
|
||||||
|
# Invoke setter
|
||||||
|
self.domain_1.security_contact
|
||||||
|
|
||||||
|
# Invoke setter
|
||||||
|
self.domain_2.security_contact
|
||||||
|
|
||||||
|
# Invoke setter
|
||||||
|
self.domain_3.security_contact
|
||||||
|
|
||||||
|
# Create a CSV file in memory
|
||||||
|
csv_file = StringIO()
|
||||||
|
writer = csv.writer(csv_file)
|
||||||
|
|
||||||
|
# Define columns, sort fields, and filter condition
|
||||||
|
columns = [
|
||||||
|
"Domain name",
|
||||||
|
"Domain type",
|
||||||
|
"Agency",
|
||||||
|
"Organization name",
|
||||||
|
"City",
|
||||||
|
"State",
|
||||||
|
"AO",
|
||||||
|
"AO email",
|
||||||
|
"Security contact email",
|
||||||
|
"Status",
|
||||||
|
"Expiration date",
|
||||||
|
]
|
||||||
|
sort_fields = ["domain__name"]
|
||||||
|
filter_condition = {
|
||||||
|
"domain__state__in": [
|
||||||
|
Domain.State.READY,
|
||||||
|
Domain.State.DNS_NEEDED,
|
||||||
|
Domain.State.ON_HOLD,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
self.maxDiff = None
|
||||||
|
# Call the export functions
|
||||||
|
write_header(writer, columns)
|
||||||
|
write_body(writer, columns, sort_fields, filter_condition)
|
||||||
|
|
||||||
|
# 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 READY domains,
|
||||||
|
# sorted alphabetially by domain name
|
||||||
|
expected_content = (
|
||||||
|
"Domain name,Domain type,Agency,Organization name,City,State,AO,"
|
||||||
|
"AO email,Security contact email,Status,Expiration date\n"
|
||||||
|
"adomain10.gov,Federal,Armed Forces Retirement Home,Ready\n"
|
||||||
|
"adomain2.gov,Interstate,(blank),Dns needed\n"
|
||||||
|
"ddomain3.gov,Federal,Armed Forces Retirement Home,123@mail.gov,On hold,2023-05-25\n"
|
||||||
|
"defaultsecurity.gov,Federal - Executive,World War I Centennial Commission,dotgov@cisa.dhs.gov,Ready"
|
||||||
|
)
|
||||||
|
|
||||||
|
print(csv_content)
|
||||||
|
# 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)
|
||||||
|
|
||||||
def test_write_body(self):
|
def test_write_body(self):
|
||||||
"""Test that write_body returns the
|
"""Test that write_body returns the
|
||||||
existing domain, test that sort by domain name works,
|
existing domain, test that sort by domain name works,
|
||||||
|
|
|
@ -26,6 +26,7 @@ def get_domain_infos(filter_condition, sort_fields):
|
||||||
|
|
||||||
def write_row(writer, columns, domain_info):
|
def write_row(writer, columns, domain_info):
|
||||||
security_contacts = domain_info.domain.contacts.filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)
|
security_contacts = domain_info.domain.contacts.filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)
|
||||||
|
|
||||||
# For linter
|
# For linter
|
||||||
ao = " "
|
ao = " "
|
||||||
if domain_info.authorizing_official:
|
if domain_info.authorizing_official:
|
||||||
|
@ -61,6 +62,7 @@ def write_row(writer, columns, domain_info):
|
||||||
"First ready": domain_info.domain.first_ready,
|
"First ready": domain_info.domain.first_ready,
|
||||||
"Deleted": domain_info.domain.deleted,
|
"Deleted": domain_info.domain.deleted,
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.writerow([FIELDS.get(column, "") for column in columns])
|
writer.writerow([FIELDS.get(column, "") for column in columns])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue