Skip to content

Commit

Permalink
Merge pull request #3836 from GSA-TTS/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jadudm authored May 15, 2024
2 parents e4a43a5 + b793940 commit 9051aa0
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 11 deletions.
2 changes: 1 addition & 1 deletion backend/audit/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def _scan_file(file):
settings.AV_SCAN_URL,
files={"file": file},
data={"name": file.name},
timeout=30,
timeout=45,
)
# Common upload issues get their own messages. These messages display as form errors.
# Allow other errors to be raised and either caught elsewhere or passed to a 400 page.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,18 @@ def xform_replace_empty_or_invalid_auditee_ein_with_gsa_migration(general_inform
return general_information


def xform_audit_period_other_months(general_information, audit_header):
"""
This method addresses cases where the reporting period spans a non-standard duration, ensuring that
the total number of months covered is accurately accounted for. This is applicable in scenarios
where the covered period could span any number of months, rather than fixed annual or biennial periods.
"""
if string_to_string(audit_header.PERIODCOVERED) == "O":
general_information["audit_period_other_months"] = str(
audit_header.NUMBERMONTHS
).zfill(2)


def xform_replace_empty_zips(general_information):
"""Replaces empty auditor and auditee zipcodes with GSA Migration keyword"""
# Transformation recorded.
Expand Down Expand Up @@ -474,6 +486,7 @@ def general_information(audit_header):
xform_update_entity_type(audit_header)
xform_replace_empty_or_invalid_auditee_uei_with_gsa_migration(audit_header)
general_information = create_json_from_db_object(audit_header, mappings)
xform_audit_period_other_months(general_information, audit_header)
transformations = [
xform_auditee_fiscal_period_start,
xform_auditee_fiscal_period_end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
xform_replace_empty_or_invalid_auditor_ein_with_gsa_migration,
xform_replace_empty_or_invalid_auditee_ein_with_gsa_migration,
xform_replace_empty_zips,
xform_audit_period_other_months,
)
from .exception_utils import (
DataMigrationError,
Expand Down Expand Up @@ -454,3 +455,61 @@ def test_non_empty_auditor_zip(self):
"auditor_zip": "12345",
}
self.assertEqual(xform_replace_empty_zips(input_data), input_data)


class TestXformAuditPeriodOtherMonths(SimpleTestCase):
class MockAuditHeader:
def __init__(self, PERIODCOVERED, NUMBERMONTHS):
self.PERIODCOVERED = PERIODCOVERED
self.NUMBERMONTHS = NUMBERMONTHS

def setUp(self):
self.audit_header = self.MockAuditHeader("", "")

def test_periodcovered_other_zfill(self):
"""Test that audit_period_other_months is set to NUMBERMONTHS with padded zeroes"""
self.audit_header.PERIODCOVERED = "O"
self.audit_header.NUMBERMONTHS = "6"
general_information = {
"audit_period_other_months": "",
}
expected_output = {
"audit_period_other_months": "06",
}
xform_audit_period_other_months(general_information, self.audit_header)
self.assertEqual(
general_information,
expected_output,
)

def test_periodcovered_other_no_zfill(self):
"""Test that audit_period_other_months is set to NUMBERMONTHS without padded zeroes"""
self.audit_header.PERIODCOVERED = "O"
self.audit_header.NUMBERMONTHS = "14"
general_information = {
"audit_period_other_months": "",
}
expected_output = {
"audit_period_other_months": "14",
}
xform_audit_period_other_months(general_information, self.audit_header)
self.assertEqual(
general_information,
expected_output,
)

def test_periodcovered_not_other(self):
"""Test that audit_period_other_months is not set"""
self.audit_header.PERIODCOVERED = "A"
self.audit_header.NUMBERMONTHS = "10"
general_information = {
"audit_period_other_months": "",
}
expected_output = {
"audit_period_other_months": "",
}
xform_audit_period_other_months(general_information, self.audit_header)
self.assertEqual(
general_information,
expected_output,
)
31 changes: 21 additions & 10 deletions backend/census_historical_migration/workbooklib/findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@

logger = logging.getLogger(__name__)

# Transformation Method Change Recording
# For the purpose of recording changes, the transformation methods (i.e., xform_***)
# below track all records related to the federal_awards section that undergoes transformation and
# log these changes in a temporary array called `change_records`.
# However, we only save this data into the InspectionRecord table if at least one of the records has been
# modified by the transformation. If no records related to the given section
# were modified, then we do not save `change_records` into the InspectionRecord.


def xform_sort_compliance_requirement(findings):
"""Sorts and uppercases the compliance requirement string."""
Expand All @@ -40,18 +48,21 @@ def xform_missing_compliance_requirement(findings):
for finding in findings:
compliance_requirement = string_to_string(finding.TYPEREQUIREMENT)
if not compliance_requirement:
track_transformations(
"TYPEREQUIREMENT",
finding.TYPEREQUIREMENT,
"type_requirement",
settings.GSA_MIGRATION,
["xform_missing_compliance_requirement"],
change_records,
)

is_empty_compliance_requirement_found = True
finding.TYPEREQUIREMENT = settings.GSA_MIGRATION
compliance_requirement = settings.GSA_MIGRATION

track_transformations(
"TYPEREQUIREMENT",
finding.TYPEREQUIREMENT,
"type_requirement",
compliance_requirement,
["xform_missing_compliance_requirement"],
change_records,
)

finding.TYPEREQUIREMENT = compliance_requirement

# See Transformation Method Change Recording comment at the top of this file
if change_records and is_empty_compliance_requirement_found:
InspectionRecord.append_finding_changes(change_records)

Expand Down

0 comments on commit 9051aa0

Please sign in to comment.