-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2501 intake add rd and u validations to new workbook vals (#2561)
* #2501 Updated ALN pattern * #2501 Added logic to check ALN pattern and to check if additional award identification is present * Apply suggestions from code review * Update backend/audit/intakelib/checks/runners.py --------- Co-authored-by: Dan Swick <[email protected]>
- Loading branch information
Showing
7 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
Binary file added
BIN
+675 KB
...ixtures/workbooks/should_fail/federal-awards/missing-additional-award-identification.xlsx
Binary file not shown.
34 changes: 34 additions & 0 deletions
34
backend/audit/intakelib/checks/check_additional_award_identification_present.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,34 @@ | ||
import logging | ||
import re | ||
from audit.intakelib.intermediate_representation import ( | ||
get_range_values_by_name, | ||
get_range_by_name, | ||
) | ||
from .check_aln_three_digit_extension_pattern import ( | ||
REGEX_RD_EXTENSION, | ||
REGEX_U_EXTENSION, | ||
) | ||
from .util import get_message, build_cell_error_tuple | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
# DESCRIPTION | ||
# Additional award identification should be present if the ALN three digit extension is RD#, or U## | ||
def additional_award_identification(ir): | ||
extension = get_range_values_by_name(ir, "three_digit_extension") | ||
additional = get_range_values_by_name(ir, "additional_award_identification") | ||
errors = [] | ||
patterns = [REGEX_RD_EXTENSION, REGEX_U_EXTENSION] | ||
for index, (ext, add) in enumerate(zip(extension, additional)): | ||
if any(re.match(pattern, ext) for pattern in patterns) and not add: | ||
errors.append( | ||
build_cell_error_tuple( | ||
ir, | ||
get_range_by_name(ir, "additional_award_identification"), | ||
index, | ||
get_message("check_additional_award_identification_present"), | ||
) | ||
) | ||
|
||
return errors |
45 changes: 45 additions & 0 deletions
45
backend/audit/intakelib/checks/check_aln_three_digit_extension_pattern.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,45 @@ | ||
import logging | ||
import re | ||
from audit.intakelib.intermediate_representation import ( | ||
get_range_values_by_name, | ||
get_range_by_name, | ||
) | ||
from .util import get_message, build_cell_error_tuple | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
# A version of these regexes also exists in Base.libsonnet | ||
REGEX_RD_EXTENSION = r"^RD[0-9]?$" | ||
REGEX_THREE_DIGIT_EXTENSION = r"^[0-9]{3}[A-Za-z]{0,1}$" | ||
REGEX_U_EXTENSION = r"^U[0-9]{2}$" | ||
|
||
|
||
# DESCRIPTION | ||
# The three digit extension should follow one of these formats: ###, RD#, or U##, where # represents a number | ||
def aln_three_digit_extension(ir): | ||
extension = get_range_values_by_name(ir, "three_digit_extension") | ||
errors = [] | ||
# Define regex patterns | ||
patterns = [REGEX_RD_EXTENSION, REGEX_THREE_DIGIT_EXTENSION, REGEX_U_EXTENSION] | ||
for index, ext in enumerate(extension): | ||
# Check if ext is None or does not match any of the regex patterns | ||
if not ext: | ||
errors.append( | ||
build_cell_error_tuple( | ||
ir, | ||
get_range_by_name(ir, "three_digit_extension"), | ||
index, | ||
get_message("check_aln_three_digit_extension_missing"), | ||
) | ||
) | ||
elif not any(re.match(pattern, ext) for pattern in patterns): | ||
errors.append( | ||
build_cell_error_tuple( | ||
ir, | ||
get_range_by_name(ir, "three_digit_extension"), | ||
index, | ||
get_message("check_aln_three_digit_extension_invalid"), | ||
) | ||
) | ||
|
||
return errors |
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
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
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
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