Skip to content

Commit

Permalink
Merge pull request #3032 from raft-tech/fix/cat3-error-cleanup
Browse files Browse the repository at this point in the history
3016 - cat3 error cleanup
  • Loading branch information
jtimpe authored Jul 17, 2024
2 parents ff50f9e + e9c02c8 commit fd5042e
Show file tree
Hide file tree
Showing 5 changed files with 982 additions and 272 deletions.
15 changes: 8 additions & 7 deletions tdrs-backend/tdpservice/data_files/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def assert_error_report_tanf_file_content_matches_with_friendly_names(response):

assert ws.cell(row=1, column=1).value == "Please refer to the most recent versions of the coding " \
+ "instructions (linked below) when looking up items and allowable values during the data revision process"
assert ws.cell(row=8, column=COL_ERROR_MESSAGE).value == ("if Cash Amount :873 validator1 passed then Cash and "
"Cash Equivalents: Number of Months T1 Item -1 (Cash "
"and Cash Equivalents: Number of Months): 0 is not "
"larger than 0.")
assert ws.cell(row=8, column=COL_ERROR_MESSAGE).value == (
"if Cash Amount :873 validator1 passed then Item 21B "
"(Cash and Cash Equivalents: Number of Months) 0 is not larger than 0."
)

@staticmethod
def assert_error_report_ssp_file_content_matches_with_friendly_names(response):
Expand Down Expand Up @@ -134,9 +134,10 @@ def assert_error_report_file_content_matches_without_friendly_names(response):

assert ws.cell(row=1, column=1).value == "Please refer to the most recent versions of the coding " \
+ "instructions (linked below) when looking up items and allowable values during the data revision process"
assert ws.cell(row=8, column=COL_ERROR_MESSAGE).value == ("if CASH_AMOUNT :873 validator1 passed then "
"NBR_MONTHS T1 Item -1 (NBR_MONTHS): 0 is not "
"larger than 0.")
assert ws.cell(row=8, column=COL_ERROR_MESSAGE).value == (
"if CASH_AMOUNT :873 validator1 passed then Item 21B "
"(Cash and Cash Equivalents: Number of Months) 0 is not larger than 0."
)

@staticmethod
def assert_data_file_exists(data_file_data, version, user):
Expand Down
12 changes: 10 additions & 2 deletions tdrs-backend/tdpservice/parsers/row_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Row schema for datafile."""
from .models import ParserErrorCategoryChoices
from .fields import Field, TransformField
from .validators import value_is_empty, format_error_context
from .validators import value_is_empty, format_error_context, ValidationErrorArgs
import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -154,12 +154,20 @@ def run_field_validators(self, instance, generate_error):
)
elif field.required:
is_valid = False
eargs = ValidationErrorArgs(
value=value,
row_schema=self,
friendly_name=field.friendly_name,
item_num=field.item,
error_context_format='prefix'
)

errors.append(
generate_error(
schema=self,
error_category=ParserErrorCategoryChoices.FIELD_VALUE,
error_message=(
f"{format_error_context(self, field.friendly_name, field.item)}: "
f"{format_error_context(eargs)} "
"field is required but a value was not provided."
),
record=instance,
Expand Down
14 changes: 8 additions & 6 deletions tdrs-backend/tdpservice/parsers/test/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,10 +1674,12 @@ def test_parse_m2_cat2_invalid_37_38_39_file(m2_cat2_invalid_37_38_39_file, dfs)

assert parser_errors.count() == 3

error_msgs = {"M2 Item 37 (Educational Level): 00 is not in range [1, 16]. or M2 Item 37 (Educational Level): " +
"00 is not in range [98, 99].",
"M2 Item 38 (Citizenship/Immigration Status): 0 is not in [1, 2, 3, 9].",
"M2 Item 39 (Cooperated with Child Support): 0 is not in [1, 2, 9]."}
error_msgs = {
"Item 37 (Educational Level) 00 is not in range [1, 16]. or "
"Item 37 (Educational Level) 00 is not in range [98, 99].",
"M2 Item 38 (Citizenship/Immigration Status): 0 is not in [1, 2, 3, 9].",
"M2 Item 39 (Cooperated with Child Support): 0 is not in [1, 2, 9]."
}
for e in parser_errors:
assert e.error_message in error_msgs

Expand All @@ -1698,10 +1700,10 @@ def test_parse_m3_cat2_invalid_68_69_file(m3_cat2_invalid_68_69_file, dfs):

assert parser_errors.count() == 4

error_msgs = {"M3 Item 68 (Educational Level): 00 is not in range [1, 16]. or M3 Item 68 (Educational Level): " +
error_msgs = {"Item 68 (Educational Level) 00 is not in range [1, 16]. or Item 68 (Educational Level) " +
"00 is not in range [98, 99].",
"M3 Item 69 (Citizenship/Immigration Status): 0 is not in [1, 2, 3, 9].",
"M3 Item 68 (Educational Level): 00 is not in range [1, 16]. or M3 Item 68 (Educational Level): " +
"Item 68 (Educational Level) 00 is not in range [1, 16]. or Item 68 (Educational Level) " +
"00 is not in range [98, 99].",
"M3 Item 69 (Citizenship/Immigration Status): 0 is not in [1, 2, 3, 9]."}

Expand Down
Loading

0 comments on commit fd5042e

Please sign in to comment.