-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4367 from GSA-TTS/main
- Loading branch information
Showing
6 changed files
with
114 additions
and
30 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
backend/audit/intakelib/transforms/xform_resize_award_references.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(""), "") |
60 changes: 30 additions & 30 deletions
60
backend/data_fixtures/audit/test_data_entries/federal-awards-audit-findings-entries.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |