Skip to content

Commit

Permalink
Merge branch 'develop' into 3055-exception-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
elipe17 authored Jul 26, 2024
2 parents 9f2c11f + 3342836 commit 37b6e87
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
6 changes: 5 additions & 1 deletion tdrs-backend/tdpservice/parsers/schema_defs/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@
startIndex=22,
endIndex=23,
required=True,
validators=[validators.matches("D")],
validators=[validators.matches("D",
error_func=lambda eargs: ("HEADER Update Indicator must be set to D "
f"instead of {eargs.value}. Please review "
"Exporting Complete Data Using FTANF in the "
"Knowledge Center."))],
),
],
)
34 changes: 34 additions & 0 deletions tdrs-backend/tdpservice/parsers/test/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,37 @@ def test_header_cleanup(test_datafile):

assert header_is_valid
assert header_errors == []

@pytest.mark.parametrize("header_line, is_valid, error", [
# Title error
(" 20204A06 TAN1ED", False, "Your file does not begin with a HEADER record."),
# quarter error
("HEADER20205A06 TAN1ED", False, "HEADER Item 5 (quarter): 5 is not in [1, 2, 3, 4]."),
# Type error
("HEADER20204E06 TAN1ED", False, "HEADER Item 6 (type): E is not in [A, C, G, S]."),
# Fips error
("HEADER20204A07 TAN1ED", False, ("HEADER Item 1 (state fips): 07 is not in [00, 01, 02, 04, 05, 06, 08, 09, "
"10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, "
"30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, "
"50, 51, 53, 54, 55, 56, 66, 72, 78].")),
# Tribe error
("HEADER20204A00 -1TAN1ED", False, "HEADER Item 3 (tribe code): -1 is not in range [0, 999]."),
# Program type error
("HEADER20204A06 BAD1ED", False, "HEADER Item 7 (program type): BAD is not in [TAN, SSP]."),
# Edit error
("HEADER20204A06 TAN3ED", False, "HEADER Item 8 (edit): 3 is not in [1, 2]."),
# Encryption error
("HEADER20204A06 TAN1AD", False, "HEADER Item 9 (encryption): A is not in [ , E]."),
# Update error
("HEADER20204A06 TAN1EA", False, ("HEADER Update Indicator must be set to D instead of A. Please review "
"Exporting Complete Data Using FTANF in the Knowledge Center.")),
])
@pytest.mark.django_db
def test_header_fields(test_datafile, header_line, is_valid, error):
"""Test validate all header fields."""
generate_error = util.make_generate_parser_error(test_datafile, 1)
header, header_is_valid, header_errors = schema_defs.header.parse_and_validate(header_line,
generate_error)

assert is_valid == header_is_valid
assert error == header_errors[0].error_message
5 changes: 4 additions & 1 deletion tdrs-backend/tdpservice/parsers/test/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,10 @@ def test_parse_tanf_section_1_file_with_bad_update_indicator(tanf_section_1_file
error = parser_errors.first()

assert error.error_type == ParserErrorCategoryChoices.FIELD_VALUE
assert error.error_message == "HEADER Item 10 (update indicator): U does not match D."
assert error.error_message == ("HEADER Update Indicator must be set to D "
"instead of U. Please review "
"Exporting Complete Data Using FTANF in the "
"Knowledge Center.")


@pytest.mark.django_db()
Expand Down
2 changes: 1 addition & 1 deletion tdrs-backend/tdpservice/parsers/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def matches(option, error_func=None):
"""Validate that value is equal to option."""
return make_validator(
lambda value: value == option,
lambda eargs: error_func(option)
lambda eargs: error_func(eargs)
if error_func
else f"{format_error_context(eargs)} {eargs.value} does not match {option}.",
)
Expand Down

0 comments on commit 37b6e87

Please sign in to comment.