Skip to content

Commit

Permalink
Sk/3697 invalid cluster names (#3785)
Browse files Browse the repository at this point in the history
* Added xform_cluster_names function

* Added test cases for xform_cluster_names function

* Added xform_cluster_names function

* Update backend/census_historical_migration/workbooklib/federal_awards.py

Co-authored-by: Hassan D. M. Sambo <[email protected]>

* Update per review comments

---------

Co-authored-by: Hassan D. M. Sambo <[email protected]>
  • Loading branch information
gsa-suk and sambodeme authored May 2, 2024
1 parent 8b30d69 commit 967ddfa
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
23 changes: 23 additions & 0 deletions backend/census_historical_migration/test_federal_awards_xforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
xform_program_name,
xform_is_passthrough_award,
is_valid_extension,
xform_cluster_names,
)


Expand Down Expand Up @@ -608,3 +609,25 @@ def test_with_missing_program_name(self):
xform_program_name(audits)

self.assertEqual(audits[0].FEDERALPROGRAMNAME, settings.GSA_MIGRATION)


class TestXformClusterNames(SimpleTestCase):
class MockAudit:
def __init__(self, cluster_name):
self.CLUSTERNAME = cluster_name

def test_cluster_name_not_other_cluster(self):
audits = []
audits.append(self.MockAudit("STUDENT FINANCIAL ASSISTANCE"))
audits.append(self.MockAudit("RESEARCH AND DEVELOPMENT"))
result = xform_cluster_names(audits)
for index in range(len(result)):
self.assertEqual(result[index].CLUSTERNAME, audits[index].CLUSTERNAME)

def test_cluster_name_other_cluster(self):
audits = []
audits.append(self.MockAudit("OTHER CLUSTER"))
audits.append(self.MockAudit("OTHER CLUSTER"))
result = xform_cluster_names(audits)
for audit in result:
self.assertEqual(audit.CLUSTERNAME, settings.OTHER_CLUSTER)
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,32 @@ def xform_populate_default_passthrough_amount(audits):
return passthrough_amounts


def xform_cluster_names(audits):
"""
If 'OTHER CLUSTER' is present in the clustername,
replace audit.CLUSTERNAME with settings.OTHER_CLUSTER and track transformation.
"""
change_records = []
is_other_cluster_found = False
for audit in audits:
cluster_name = string_to_string(audit.CLUSTERNAME)
if cluster_name and cluster_name.upper() == "OTHER CLUSTER":
is_other_cluster_found = True
track_transformations(
"CLUSTERNAME",
audit.CLUSTERNAME,
"cluster_name",
settings.OTHER_CLUSTER,
["xform_cluster_names"],
change_records,
)
audit.CLUSTERNAME = settings.OTHER_CLUSTER

if change_records and is_other_cluster_found:
InspectionRecord.append_federal_awards_changes(change_records)
return audits


def generate_federal_awards(audit_header, outfile):
"""
Generates a federal awards workbook for all awards associated with a given audit header.
Expand All @@ -546,6 +572,7 @@ def generate_federal_awards(audit_header, outfile):
uei = xform_retrieve_uei(audit_header.UEI)
set_workbook_uei(wb, uei)
audits = get_audits(audit_header.DBKEY, audit_header.AUDITYEAR)
audits = xform_cluster_names(audits)

(
cluster_names,
Expand Down Expand Up @@ -597,7 +624,7 @@ def generate_federal_awards(audit_header, outfile):
set_range(
wb,
"award_reference",
[f"AWARD-{n+1:04}" for n in range(len(audits))],
[f"AWARD-{n + 1:04}" for n in range(len(audits))],
)

# passthrough amount
Expand Down

0 comments on commit 967ddfa

Please sign in to comment.