Skip to content

Commit

Permalink
Mshd/fix for award reference case in audit findings workbook (#3081)
Browse files Browse the repository at this point in the history
* Added a check to return a correct error message for wrong award reference

* Fix for award reference lowercase case failure
  • Loading branch information
sambodeme authored Dec 26, 2023
1 parent a660153 commit 6e549dd
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 1 deletion.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import logging
from django.core.exceptions import ValidationError
import re
from audit.intakelib.intermediate_representation import (
get_range_by_name,
)
from audit.intakelib.common import (
get_message,
build_cell_error_tuple,
)

logger = logging.getLogger(__name__)

# A version of these regexes also exists in Base.libsonnet
AWARD_REFERENCES_REGEX = r"^AWARD-(?!0000)[0-9]{4}$"


# DESCRIPTION
# Award references should be of format AWARD-####
# TESTED BY
# has_bad_award_references.xlsx
def award_references_pattern(ir):
award_references = get_range_by_name(ir, "award_reference")
errors = []
for index, award_reference in enumerate(award_references["values"]):
if not re.match(AWARD_REFERENCES_REGEX, str(award_reference)):
errors.append(
build_cell_error_tuple(
ir,
award_references,
index,
get_message("check_award_references_invalid"),
)
)

if len(errors) > 0:
logger.info("Raising a validation error.")
raise ValidationError(errors)
3 changes: 3 additions & 0 deletions backend/audit/intakelib/checks/runners.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.core.exceptions import ValidationError
import logging

from .check_finding_award_references_pattern import award_references_pattern
from .check_cluster_names import check_cluster_names
from audit.fixtures.excel import FORM_SECTIONS
from .check_gsa_migration_keyword import check_for_gsa_migration_keyword
Expand Down Expand Up @@ -93,6 +95,7 @@
has_all_the_named_ranges(FORM_SECTIONS.FINDINGS_UNIFORM_GUIDANCE),
has_all_required_fields(FORM_SECTIONS.FINDINGS_UNIFORM_GUIDANCE),
has_invalid_yorn_field(FORM_SECTIONS.FINDINGS_UNIFORM_GUIDANCE),
award_references_pattern,
prior_references_pattern,
no_repeat_findings,
findings_grid_validation,
Expand Down
1 change: 1 addition & 0 deletions backend/audit/intakelib/common/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"check_missing_aln_three_digit_extension": "Missing ALN (CFDA) three digit extension",
"check_aln_three_digit_extension_invalid": "The three digit extension should follow one of these formats: ###, RD#, or U##, where # represents a number",
"check_prior_references_invalid": "Prior references must be <b>N/A</b> or a comma-separated list of values in the format <b>20##-###</b>, for example, <b>2019-001, 2019-002</b>",
"check_award_references_invalid": "Award references must be of the form <b>AWARD-####</b>, for example, <b>AWARD-0001</b>",
"check_additional_award_identification_present": "Missing additional award identification",
"check_federal_program_total": "Federal program total is {}, but should be {}",
"check_cluster_total": "This cluster total is {}, but should be {}",
Expand Down
4 changes: 3 additions & 1 deletion backend/audit/intakelib/transforms/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from .xform_add_transform_for_cfda_key import generate_cfda_keys
from .xform_uniform_cluster_names import regenerate_uniform_cluster_names
from .xform_reformat_prior_references import reformat_prior_references
from .xform_reformat_award_references import reformat_award_reference

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -73,7 +74,7 @@ def run_all_audit_findings_text_transforms(ir):


def run_all_audit_findings_transforms(ir):
return run_all_transforms(ir, general_transforms)
return run_all_transforms(ir, audit_findings_transforms)


def run_all_corrective_action_plan_transforms(ir):
Expand Down Expand Up @@ -108,5 +109,6 @@ def run_all_secondary_auditors_transforms(ir):
]

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

logger = logging.getLogger(__name__)


# Tested by has_lowercase_award_reference.py
def reformat_award_reference(ir):
references = get_range_by_name(ir, "award_reference")
new_values = list(map(lambda v: v.upper() if v else v, references["values"]))
new_ir = replace_range_by_name(ir, "award_reference", new_values)
return new_ir

0 comments on commit 6e549dd

Please sign in to comment.