Skip to content

Commit

Permalink
Merge pull request #1746 from cisagov/rh/1556-metadata-update
Browse files Browse the repository at this point in the history
ISSUE #1556: Metadata update
  • Loading branch information
therealslimhsiehdy authored Feb 21, 2024
2 parents f72e81a + a66fb36 commit 13c40cc
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 55 deletions.
1 change: 1 addition & 0 deletions src/registrar/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{% endblock %}
<h1>Manage your domains</h2>


<p class="margin-top-4">
<a href="{% url 'application:' %}" class="usa-button"
>
Expand Down
110 changes: 97 additions & 13 deletions src/registrar/tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from registrar.models.public_contact import PublicContact
from registrar.models.user import User
from django.contrib.auth import get_user_model
from registrar.models.user_domain_role import UserDomainRole
from registrar.tests.common import MockEppLib
from registrar.utility.csv_export import (
write_header,
write_body,
write_csv,
get_default_start_date,
get_default_end_date,
)

from django.core.management import call_command
from unittest.mock import MagicMock, call, mock_open, patch
from api.views import get_current_federal, get_current_full
Expand Down Expand Up @@ -336,11 +337,30 @@ def setUp(self):
federal_agency="Armed Forces Retirement Home",
)

meoward_user = get_user_model().objects.create(
username="meoward_username", first_name="first_meoward", last_name="last_meoward", email="[email protected]"
)

# Test for more than 1 domain manager
_, created = UserDomainRole.objects.get_or_create(
user=meoward_user, domain=self.domain_1, role=UserDomainRole.Roles.MANAGER
)

_, created = UserDomainRole.objects.get_or_create(
user=self.user, domain=self.domain_1, role=UserDomainRole.Roles.MANAGER
)

# Test for just 1 domain manager
_, created = UserDomainRole.objects.get_or_create(
user=meoward_user, domain=self.domain_2, role=UserDomainRole.Roles.MANAGER
)

def tearDown(self):
PublicContact.objects.all().delete()
Domain.objects.all().delete()
DomainInformation.objects.all().delete()
User.objects.all().delete()
UserDomainRole.objects.all().delete()
super().tearDown()

def test_export_domains_to_writer_security_emails(self):
Expand Down Expand Up @@ -383,8 +403,10 @@ def test_export_domains_to_writer_security_emails(self):
}
self.maxDiff = None
# Call the export functions
write_header(writer, columns)
write_body(writer, columns, sort_fields, filter_condition)
write_csv(
writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True
)

# Reset the CSV file's position to the beginning
csv_file.seek(0)
# Read the content into a variable
Expand All @@ -405,7 +427,7 @@ def test_export_domains_to_writer_security_emails(self):
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
self.assertEqual(csv_content, expected_content)

def test_write_body(self):
def test_write_csv(self):
"""Test that write_body returns the
existing domain, test that sort by domain name works,
test that filter works"""
Expand Down Expand Up @@ -440,8 +462,9 @@ def test_write_body(self):
],
}
# Call the export functions
write_header(writer, columns)
write_body(writer, columns, sort_fields, filter_condition)
write_csv(
writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True
)
# Reset the CSV file's position to the beginning
csv_file.seek(0)
# Read the content into a variable
Expand Down Expand Up @@ -489,8 +512,9 @@ def test_write_body_additional(self):
],
}
# Call the export functions
write_header(writer, columns)
write_body(writer, columns, sort_fields, filter_condition)
write_csv(
writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True
)
# Reset the CSV file's position to the beginning
csv_file.seek(0)
# Read the content into a variable
Expand Down Expand Up @@ -567,20 +591,22 @@ def test_write_body_with_date_filter_pulls_domains_in_range(self):
}

# Call the export functions
write_header(writer, columns)
write_body(
write_csv(
writer,
columns,
sort_fields,
filter_condition,
get_domain_managers=False,
should_write_header=True,
)
write_body(
write_csv(
writer,
columns,
sort_fields_for_deleted_domains,
filter_conditions_for_deleted_domains,
get_domain_managers=False,
should_write_header=False,
)

# Reset the CSV file's position to the beginning
csv_file.seek(0)

Expand All @@ -606,6 +632,64 @@ def test_write_body_with_date_filter_pulls_domains_in_range(self):

self.assertEqual(csv_content, expected_content)

def test_export_domains_to_writer_domain_managers(self):
"""Test that export_domains_to_writer returns the
expected domain managers"""
with less_console_noise():
# Create a CSV file in memory
csv_file = StringIO()
writer = csv.writer(csv_file)
# Define columns, sort fields, and filter condition

columns = [
"Domain name",
"Status",
"Expiration date",
"Domain type",
"Agency",
"Organization name",
"City",
"State",
"AO",
"AO email",
"Security contact email",
]
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_csv(
writer, columns, sort_fields, filter_condition, get_domain_managers=True, should_write_header=True
)

# 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,Status,Expiration date,Domain type,Agency,"
"Organization name,City,State,AO,AO email,"
"Security contact email,Domain manager email 1,Domain manager email 2,\n"
"adomain10.gov,Ready,,Federal,Armed Forces Retirement Home,,,, , ,\n"
"adomain2.gov,Dns needed,,Interstate,,,,, , , ,[email protected]\n"
"cdomain1.gov,Ready,,Federal - Executive,World War I Centennial Commission,,,"
", , , ,[email protected],[email protected]\n"
"ddomain3.gov,On hold,,Federal,Armed Forces Retirement Home,,,, , , ,,\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 HelperFunctions(TestCase):
"""This asserts that 1=1. Its limited usefulness lies in making sure the helper methods stay healthy."""
Expand Down
Loading

0 comments on commit 13c40cc

Please sign in to comment.