Skip to content

Commit

Permalink
- Error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
elipe17 committed Sep 20, 2023
1 parent 0750677 commit c63ba74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions tdrs-backend/tdpservice/parsers/test/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,19 @@ def test_parse_tanf_section3_file(tanf_section3_file):
assert first.NUM_CLOSED_CASES == 3884
assert second.NUM_CLOSED_CASES == 3881
assert third.NUM_CLOSED_CASES == 5453

@pytest.fixture
def tanf_section1_file_with_blanks(stt_user, stt):
"""Fixture for ADS.E2J.FTP3.TS06."""
return create_test_datafile('tanf_section1_blanks.txt', stt_user, stt)

@pytest.mark.django_db()
def test_parse_tanf_section1_blanks_file(tanf_section1_file_with_blanks):
parse.parse_datafile(tanf_section1_file_with_blanks)

parser_errors = ParserError.objects.filter(file=tanf_section1_file_with_blanks)

for e in parser_errors:
print(e.error_message)

assert False
9 changes: 5 additions & 4 deletions tdrs-backend/tdpservice/parsers/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def validator(value):
return (True, None)
return (False, error_func(value))
except Exception as e:
logger.debug(f"Caught exception in make_validator. Exception: {e}")
logger.debug(f"Caught exception in validator. Exception: {e}")
return (False, error_func(value))
return validator

Expand Down Expand Up @@ -71,7 +71,8 @@ def sumIsEqual(condition_field, sum_fields=[]):
def sumIsEqualFunc(value):
sum = 0
for field in sum_fields:
sum += value[field] if type(value) is dict else getattr(value, field)
val = value[field] if type(value) is dict else getattr(value, field)
sum += 0 if val is None else val

condition_val = value[condition_field] if type(value) is dict else getattr(value, condition_field)
return (True, None) if sum == condition_val else (False,
Expand All @@ -84,8 +85,8 @@ def sumIsLarger(fields, val):
def sumIsLargerFunc(value):
sum = 0
for field in fields:
val = value[field] if type(value) is dict else getattr(value, field)
sum += 0 if val is None else val
temp_val = value[field] if type(value) is dict else getattr(value, field)
sum += 0 if temp_val is None else temp_val

return (True, None) if sum > val else (False, f"The sum of {fields} is not larger than {val}.")

Expand Down

0 comments on commit c63ba74

Please sign in to comment.