Skip to content

Commit

Permalink
Update function naming and length check
Browse files Browse the repository at this point in the history
  • Loading branch information
therealslimhsiehdy committed Feb 15, 2024
1 parent 22cefd6 commit a66fb36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/registrar/tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from registrar.models.user_domain_role import UserDomainRole
from registrar.tests.common import MockEppLib
from registrar.utility.csv_export import (
write_body,
write_csv,
get_default_start_date,
get_default_end_date,
)
Expand Down Expand Up @@ -403,7 +403,7 @@ def test_export_domains_to_writer_security_emails(self):
}
self.maxDiff = None
# Call the export functions
write_body(
write_csv(
writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True
)

Expand All @@ -427,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 @@ -462,7 +462,7 @@ def test_write_body(self):
],
}
# Call the export functions
write_body(
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
Expand Down Expand Up @@ -512,7 +512,7 @@ def test_write_body_additional(self):
],
}
# Call the export functions
write_body(
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
Expand Down Expand Up @@ -591,15 +591,15 @@ def test_write_body_with_date_filter_pulls_domains_in_range(self):
}

# Call the export functions
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,
Expand Down Expand Up @@ -664,7 +664,7 @@ def test_export_domains_to_writer_domain_managers(self):
}
self.maxDiff = None
# Call the export functions
write_body(
write_csv(
writer, columns, sort_fields, filter_condition, get_domain_managers=True, should_write_header=True
)

Expand Down
15 changes: 8 additions & 7 deletions src/registrar/utility/csv_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def update_columns_with_domain_managers(columns, max_dm_count):
columns.append(f"Domain manager email {i}")


def write_body(
def write_csv(
writer,
columns,
sort_fields,
Expand All @@ -161,7 +161,7 @@ def write_body(
# Reduce the memory overhead when performing the write operation
paginator = Paginator(all_domain_infos, 1000)

if get_domain_managers:
if get_domain_managers and len(all_domain_infos) > 0:
# We want to get the max amont of domain managers an
# account has to set the column header dynamically
max_dm_count = max(len(domain_info.domain.permissions.all()) for domain_info in all_domain_infos)
Expand All @@ -179,6 +179,7 @@ def write_body(
# It indicates that DomainInformation.domain is None.
logger.error("csv_export -> Error when parsing row, domain was None")
continue

if should_write_header:
write_header(writer, columns)

Expand Down Expand Up @@ -219,7 +220,7 @@ def export_data_type_to_csv(csv_file):
Domain.State.ON_HOLD,
],
}
write_body(writer, columns, sort_fields, filter_condition, get_domain_managers=True, should_write_header=True)
write_csv(writer, columns, sort_fields, filter_condition, get_domain_managers=True, should_write_header=True)


def export_data_full_to_csv(csv_file):
Expand Down Expand Up @@ -250,7 +251,7 @@ def export_data_full_to_csv(csv_file):
Domain.State.ON_HOLD,
],
}
write_body(writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True)
write_csv(writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True)


def export_data_federal_to_csv(csv_file):
Expand Down Expand Up @@ -282,7 +283,7 @@ def export_data_federal_to_csv(csv_file):
Domain.State.ON_HOLD,
],
}
write_body(writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True)
write_csv(writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True)


def get_default_start_date():
Expand Down Expand Up @@ -349,8 +350,8 @@ def export_data_growth_to_csv(csv_file, start_date, end_date):
"domain__deleted__gte": start_date_formatted,
}

write_body(writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True)
write_body(
write_csv(writer, columns, sort_fields, filter_condition, get_domain_managers=False, should_write_header=True)
write_csv(
writer,
columns,
sort_fields_for_deleted_domains,
Expand Down

0 comments on commit a66fb36

Please sign in to comment.