Skip to content

Commit

Permalink
Merge pull request #4367 from GSA-TTS/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jadudm authored Oct 9, 2024
2 parents 68087f1 + 9a8317c commit 549dbb9
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 30 deletions.
4 changes: 4 additions & 0 deletions backend/audit/intakelib/transforms/runners.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
from copy import deepcopy

from .xform_resize_award_references import resize_award_reference

from .xform_all_amount_expended_need_to_be_integers import (
convert_amount_expended_to_integers,
)
Expand Down Expand Up @@ -112,9 +114,11 @@ def run_all_secondary_auditors_transforms(ir):
regenerate_uniform_cluster_names,
reformat_federal_agency_prefix,
generate_cfda_keys,
resize_award_reference,
]

audit_findings_transforms = general_transforms + [
reformat_award_reference,
reformat_prior_references,
resize_award_reference,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logging
from audit.intakelib.intermediate_representation import (
get_range_by_name,
replace_range_by_name,
)
from audit.intakelib.checks.check_finding_award_references_pattern import (
AWARD_LEN_5_DIGITS,
)

logger = logging.getLogger(__name__)


def resize_award_reference(ir):
references = get_range_by_name(ir, "award_reference")
new_values = list(map(_format_reference, references["values"]))
new_ir = replace_range_by_name(ir, "award_reference", new_values)

return new_ir


def _format_reference(v):

if v and len(v) < AWARD_LEN_5_DIGITS:
parts = v.split("-")
padding = "0" * (AWARD_LEN_5_DIGITS - len(v))
return f"{parts[0]}-{padding}{parts[1]}"
return v
53 changes: 53 additions & 0 deletions backend/audit/test_xform_resize_award_references.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from unittest.mock import patch

from django.test import SimpleTestCase

from audit.intakelib.transforms.xform_resize_award_references import (
_format_reference,
resize_award_reference,
)


class TestResizeAwardReference(SimpleTestCase):

@patch("audit.intakelib.transforms.xform_resize_award_references.get_range_by_name")
@patch(
"audit.intakelib.transforms.xform_resize_award_references.replace_range_by_name"
)
def test_resize_award_reference(
self, mock_replace_range_by_name, mock_get_range_by_name
):
"""Test the resize_award_reference function"""
ir = []
references = {
"values": [
"AWARD-123", # Will need padding
"AWARD-4567", # Will need padding
"AWARD-12345", # Correct length, no padding
None, # No change for None
]
}
expected_new_values = [
"AWARD-00123",
"AWARD-04567",
"AWARD-12345",
None,
]

mock_get_range_by_name.return_value = references
new_ir = resize_award_reference(ir)

mock_get_range_by_name.assert_called_once_with(ir, "award_reference")
mock_replace_range_by_name.assert_called_once_with(
ir, "award_reference", expected_new_values
)

self.assertEqual(new_ir, mock_replace_range_by_name.return_value)

def test_format_reference(self):
"""Test the _format_reference function"""
self.assertEqual(_format_reference("AWARD-123"), "AWARD-00123")
self.assertEqual(_format_reference("AWARD-4567"), "AWARD-04567")
self.assertEqual(_format_reference("AWARD-12345"), "AWARD-12345")
self.assertEqual(_format_reference(None), None)
self.assertEqual(_format_reference(""), "")
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
[
{
"award_reference": "AWARD-0001",
"compliance_requirement": "AB",
"reference_number": "2023-001",
"repeat_prior_reference": "Y",
"prior_references": "2020-001",
"is_valid": "Y",
"questioned_costs": "N",
"significant_deficiency": "N",
"other_matters": "N",
"other_findings": "N",
"modified_opinion": "Y",
"material_weakness": "N"
},
{
"award_reference": "AWARD-0002",
"compliance_requirement": "E",
"reference_number": "2023-001",
"repeat_prior_reference": "N",
"prior_references": "N/A",
"is_valid": "Y",
"questioned_costs": "N",
"significant_deficiency": "N",
"other_matters": "Y",
"other_findings": "N",
"modified_opinion": "N",
"material_weakness": "Y"
}
]
[
{
"award_reference": "AWARD-00001",
"compliance_requirement": "AB",
"reference_number": "2023-001",
"repeat_prior_reference": "Y",
"prior_references": "2020-001",
"is_valid": "Y",
"questioned_costs": "N",
"significant_deficiency": "N",
"other_matters": "N",
"other_findings": "N",
"modified_opinion": "Y",
"material_weakness": "N"
},
{
"award_reference": "AWARD-00002",
"compliance_requirement": "E",
"reference_number": "2023-001",
"repeat_prior_reference": "N",
"prior_references": "N/A",
"is_valid": "Y",
"questioned_costs": "N",
"significant_deficiency": "N",
"other_matters": "Y",
"other_findings": "N",
"modified_opinion": "N",
"material_weakness": "Y"
}
]

0 comments on commit 549dbb9

Please sign in to comment.