diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t6.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t6.py index 233858954..ed4c3748d 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t6.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t6.py @@ -136,30 +136,120 @@ required=True, validators=[validators.isInLimits(0, 99999999)]), Field(item="6C", name='NUM_DENIED', friendly_name='total number of denied applications', type='number', startIndex=71, endIndex=79, required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="7C", name='ASSISTANCE', friendly_name='total amount of assistance', type='number', startIndex=103, endIndex=115, + Field( + item="7C", + name='ASSISTANCE', + friendly_name='total amount of assistance', type='number', startIndex=103, endIndex=115, required=True, validators=[validators.isInLimits(0, 999999999999)]), - Field(item="8C", name='NUM_FAMILIES', friendly_name='total number of families', type='number', startIndex=131, endIndex=139, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="9C", name='NUM_2_PARENTS', friendly_name='total number of two parents families', type='number', startIndex=155, endIndex=163, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="10C", name='NUM_1_PARENTS', friendly_name='total number of one parent families', type='number', startIndex=179, endIndex=187, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="11C", name='NUM_NO_PARENTS', friendly_name='total number of no parent families', type='number', startIndex=203, endIndex=211, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="12C", name='NUM_RECIPIENTS', friendly_name='total number of recipients', type='number', startIndex=227, endIndex=235, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="13C", name='NUM_ADULT_RECIPIENTS', friendly_name='total number of adult recipients', type='number', startIndex=251, endIndex=259, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="14C", name='NUM_CHILD_RECIPIENTS', friendly_name='total number of child recipients', type='number', startIndex=275, endIndex=283, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="15C", name='NUM_NONCUSTODIALS', friendly_name='total number of noncustodial parents', type='number', startIndex=299, endIndex=307, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="16C", name='NUM_BIRTHS', friendly_name='total number of births', type='number', startIndex=323, endIndex=331, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="17C", name='NUM_OUTWEDLOCK_BIRTHS', friendly_name='total number of outwedlock births', type='number', startIndex=347, endIndex=355, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="18C", name='NUM_CLOSED_CASES', friendly_name='total number of closed cases', type='number', startIndex=371, endIndex=379, - required=True, validators=[validators.isInLimits(0, 99999999)]), + Field( + item="8C", + name='NUM_FAMILIES', + friendly_name='total number of families', + type='number', + startIndex=131, + endIndex=139, + required=True, + validators=[validators.isInLimits(0, 99999999)] + ), + Field( + item="9C", + name='NUM_2_PARENTS', + friendly_name='total number of two parents families', + type='number', + startIndex=155, + endIndex=163, + required=True, + validators=[validators.isInLimits(0, 99999999)] + ), + Field( + item="10C", + name='NUM_1_PARENTS', + friendly_name='total number of one parent families', + type='number', + startIndex=179, + endIndex=187, + required=True, + validators=[validators.isInLimits(0, 99999999)] + ), + Field( + item="11C", + name='NUM_NO_PARENTS', + friendly_name='total number of no parent families', + type='number', + startIndex=203, + endIndex=211, + required=True, + validators=[validators.isInLimits(0, 99999999)] + ), + Field( + item="12C", + name='NUM_RECIPIENTS', + friendly_name='total number of recipients', + type='number', + startIndex=227, + endIndex=235, + required=True,validators=[validators.isInLimits(0, 99999999)] + ), + Field( + item="13C", + name='NUM_ADULT_RECIPIENTS', + friendly_name='total number of adult recipients', + type='number', + startIndex=251, + endIndex=259, + required=True, + validators=[validators.isInLimits(0, 99999999)] + ), + Field( + item="14C", + name='NUM_CHILD_RECIPIENTS', + friendly_name='total number of child recipients', + type='number', + startIndex=275, + endIndex=283, + required=True, + validators=[validators.isInLimits(0, 99999999)] + ), + Field( + item="15C", + name='NUM_NONCUSTODIALS', + friendly_name='total number of noncustodial parents', + type='number', + startIndex=299, + endIndex=307, + required=True, + validators=[validators.isInLimits(0, 99999999)] + ), + Field( + item="16C", + name='NUM_BIRTHS', + friendly_name='total number of births', + type='number', + startIndex=323, + endIndex=331, + required=True, + validators=[validators.isInLimits(0, 99999999)] + ), + Field( + item="17C", + name='NUM_OUTWEDLOCK_BIRTHS', + friendly_name='total number of outwedlock births', + type='number', + startIndex=347, + endIndex=355, + required=True, + validators=[validators.isInLimits(0, 99999999)] + ), + Field( + item="18C", + name='NUM_CLOSED_CASES', + friendly_name='total number of closed cases', + type='number', + startIndex=371, + endIndex=379, + required=True, + validators=[validators.isInLimits(0, 99999999)] + ), ], ) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t7.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t7.py index 371d0109a..b92e06436 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t7.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t7.py @@ -28,11 +28,26 @@ ], postparsing_validators=[], fields=[ - Field(item="0", name="RecordType", friendly_name='record type', type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="3", name='CALENDAR_QUARTER', friendly_name='calendar quarter', type='number', startIndex=2, endIndex=7, - required=True, validators=[validators.dateYearIsLargerThan(1998), - validators.quarterIsValid()]), + Field( + item="0", + name="RecordType", + friendly_name='record type', + type='string', + startIndex=0, + endIndex=2, + required=True, + validators=[] + ), + Field( + item="3", + name='CALENDAR_QUARTER', + friendly_name='calendar quarter', + type='number', + startIndex=2, + endIndex=7, + required=True, + validators=[validators.dateYearIsLargerThan(1998), validators.quarterIsValid()] + ), TransformField( transform_func=calendar_quarter_to_rpt_month_year(month_index), item="3A", @@ -46,13 +61,37 @@ validators.dateYearIsLargerThan(1998), validators.dateMonthIsValid() ] - ), - Field(item="4", name='TDRS_SECTION_IND', friendly_name='tdrs section indicator', type='string', startIndex=section_ind_index, - endIndex=section_ind_index + 1, required=True, validators=[validators.oneOf(['1', '2'])]), - Field(item="5", name='STRATUM', friendly_name='stratum', type='string', startIndex=stratum_index, - endIndex=stratum_index + 2, required=True, validators=[validators.isInStringRange(1, 99)]), - Field(item=families_value_item_number, name='FAMILIES_MONTH', friendly_name='total number of families for each month', type='number', startIndex=families_index, - endIndex=families_index + 7, required=True, validators=[validators.isInLimits(0, 9999999)]), + ), + Field( + item="4", + name='TDRS_SECTION_IND', + friendly_name='tdrs section indicator', + type='string', + startIndex=section_ind_index, + endIndex=section_ind_index + 1, + required=True, + validators=[validators.oneOf(['1', '2'])] + ), + Field( + item="5", + name='STRATUM', + friendly_name='stratum', + type='string', + startIndex=stratum_index, + endIndex=stratum_index + 2, + required=True, + validators=[validators.isInStringRange(1, 99)] + ), + Field( + item=families_value_item_number, + name='FAMILIES_MONTH', + friendly_name='total number of families for each month', + type='number', + startIndex=families_index, + endIndex=families_index + 7, + required=True, + validators=[validators.isInLimits(0, 9999999)] + ), ] ) ) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/trailer.py b/tdrs-backend/tdpservice/parsers/schema_defs/trailer.py index ced15e4cf..5ff37722f 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/trailer.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/trailer.py @@ -17,14 +17,41 @@ ], postparsing_validators=[], fields=[ - Field(item="1", name='title', friendly_name='title', type='string', startIndex=0, endIndex=7, required=True, validators=[ - validators.matches('TRAILER') - ]), - Field(item="2", name='record_count', friendly_name='record count', type='number', startIndex=7, endIndex=14, required=True, validators=[ - validators.between(0, 9999999) - ]), - Field(item="-1", name='blank', friendly_name='blank', type='string', startIndex=14, endIndex=23, required=False, validators=[ - validators.matches(' ') - ]), + Field( + item="1", + name='title', + friendly_name='title', + type='string', + startIndex=0, + endIndex=7, + required=True, + validators=[ + validators.matches('TRAILER') + ] + ), + Field( + item="2", + name='record_count', + friendly_name='record count', + type='number', + startIndex=7, + endIndex=14, + required=True, + validators=[ + validators.between(0, 9999999) + ] + ), + Field( + item="-1", + name='blank', + friendly_name='blank', + type='string', + startIndex=14, + endIndex=23, + required=False, + validators=[ + validators.matches(' ') + ] + ), ], ) diff --git a/tdrs-backend/tdpservice/parsers/test/test_util.py b/tdrs-backend/tdpservice/parsers/test/test_util.py index fdbe09a62..e1e9dea9a 100644 --- a/tdrs-backend/tdpservice/parsers/test/test_util.py +++ b/tdrs-backend/tdpservice/parsers/test/test_util.py @@ -65,7 +65,7 @@ def test_parse_line_parses_line_from_schema_to_dict(): ) record = schema.parse_line(line) - + assert record['first'] == '123' assert record['second'] == '4' assert record['third'] == '5' @@ -237,12 +237,30 @@ def test_field_validators_blank_and_required_returns_error(first, second): schema = RowSchema( model=dict, fields=[ - Field(item=1, name='first', friendly_name='first', type='string', startIndex=0, endIndex=1, required=True, validators=[ - passing_validator(), - ]), - Field(item=2, name='second', friendly_name='second', type='string', startIndex=1, endIndex=3, required=True, validators=[ - passing_validator(), - ]), + Field( + item=1, + name='first', + friendly_name='first', + type='string', + startIndex=0, + endIndex=1, + required=True, + validators=[ + passing_validator(), + ] + ), + Field( + item=2, + name='second', + friendly_name='second', + type='string', + startIndex=1, + endIndex=3, + required=True, + validators=[ + passing_validator(), + ] + ), ] ) @@ -267,10 +285,19 @@ def test_field_validators_blank_and_not_required_returns_valid(first): schema = RowSchema( model=dict, fields=[ - Field(item=1, name='first', friendly_name='first', type='string', startIndex=0, endIndex=3, required=False, validators=[ - passing_validator(), - failing_validator() - ]), + Field( + item=1, + name='first', + friendly_name='first', + type='string', + startIndex=0, + endIndex=3, + required=False, + validators=[ + passing_validator(), + failing_validator() + ] + ), ] ) @@ -349,9 +376,15 @@ def test_multi_record_schema_parses_and_validates(): failing_validator() ], fields=[ - Field(item=1, name='first', friendly_name='first', type='string', startIndex=0, endIndex=3, validators=[ - passing_validator() - ]), + Field( + item=1, + name='first', + friendly_name='first', + type='string', + startIndex=0, + endIndex=3, + validators=[passing_validator()] + ), ] ), RowSchema( @@ -363,9 +396,14 @@ def test_multi_record_schema_parses_and_validates(): passing_validator() ], fields=[ - Field(item=2, name='second', friendly_name='first', type='string', startIndex=2, endIndex=4, validators=[ - passing_validator() - ]), + Field( + item=2, + name='second', + friendly_name='first', + type='string', + startIndex=2, + endIndex=4, + validators=[passing_validator()]), ] ), RowSchema( @@ -377,9 +415,15 @@ def test_multi_record_schema_parses_and_validates(): passing_validator() ], fields=[ - Field(item=3, name='third', friendly_name='first', type='string', startIndex=4, endIndex=5, validators=[ - passing_validator() - ]), + Field( + item=3, + name='third', + friendly_name='first', + type='string', + startIndex=4, + endIndex=5, + validators=[passing_validator()] + ), ] ), RowSchema( @@ -391,9 +435,15 @@ def test_multi_record_schema_parses_and_validates(): passing_validator() ], fields=[ - Field(item=4, name='fourth', friendly_name='first', type='string', startIndex=4, endIndex=5, validators=[ - failing_validator() - ]), + Field( + item=4, + name='fourth', + friendly_name='first', + type='string', + startIndex=4, + endIndex=5, + validators=[failing_validator()] + ), ] ) ]