diff --git a/tdrs-backend/tdpservice/parsers/fields.py b/tdrs-backend/tdpservice/parsers/fields.py index fa4c73101..7d5ad05df 100644 --- a/tdrs-backend/tdpservice/parsers/fields.py +++ b/tdrs-backend/tdpservice/parsers/fields.py @@ -18,7 +18,7 @@ def value_is_empty(value, length): class Field: """Provides a mapping between a field name and its position.""" - def __init__(self, item, name, type, startIndex, endIndex, required=True, validators=[]): + def __init__(self, item, name, type, startIndex, endIndex, can_be_empty=False, required=True, validators=[]): self.item = item self.name = name self.type = type @@ -26,6 +26,7 @@ def __init__(self, item, name, type, startIndex, endIndex, required=True, valida self.endIndex = endIndex self.required = required self.validators = validators + self.can_be_empty = can_be_empty def create(self, item, name, length, start, end, type): """Create a new field.""" @@ -60,8 +61,9 @@ def parse_value(self, line): class TransformField(Field): """Represents a field that requires some transformation before serializing.""" - def __init__(self, transform_func, item, name, type, startIndex, endIndex, required=True, validators=[], **kwargs): - super().__init__(item, name, type, startIndex, endIndex, required, validators) + def __init__(self, transform_func, item, name, type, startIndex, endIndex, can_be_empty=False, required=True, + validators=[], **kwargs): + super().__init__(item, name, type, startIndex, endIndex, can_be_empty, required, validators) self.transform_func = transform_func self.kwargs = kwargs diff --git a/tdrs-backend/tdpservice/parsers/row_schema.py b/tdrs-backend/tdpservice/parsers/row_schema.py index a4faecdf3..c8ca6358d 100644 --- a/tdrs-backend/tdpservice/parsers/row_schema.py +++ b/tdrs-backend/tdpservice/parsers/row_schema.py @@ -114,7 +114,7 @@ def run_field_validators(self, instance, generate_error): else: value = getattr(instance, field.name, None) - if field.required and not value_is_empty(value, field.endIndex-field.startIndex): + if (field.required and not value_is_empty(value, field.endIndex-field.startIndex)) or field.can_be_empty: for validator in field.validators: validator_is_valid, validator_error = validator(value) is_valid = False if not validator_is_valid else is_valid diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t1.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t1.py index 0ba3d002d..d1ce9f6c4 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t1.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t1.py @@ -92,55 +92,19 @@ validators.isNumber(), ]), Field(item="5", name='STRATUM', type='string', startIndex=22, endIndex=24, - required=True, validators=[ + can_be_empty=True, required=True, validators=[ validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()), ]), - Field(item="7", name='ZIP_CODE', type='string', startIndex=24, endIndex=29, - required=True, validators=[ - validators.isNumber(), - ]), - Field(item="8", name='FUNDING_STREAM', type='number', startIndex=29, endIndex=30, - required=True, validators=[ - validators.isInLimits(1, 3), - ]), - Field(item="9", name='DISPOSITION', type='number', startIndex=30, endIndex=31, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="10", name='NEW_APPLICANT', type='number', startIndex=31, endIndex=32, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="11", name='NBR_FAMILY_MEMBERS', type='number', startIndex=32, endIndex=34, - required=True, validators=[ - validators.isLargerThan(0), - ]), - Field(item="12", name='FAMILY_TYPE', type='number', startIndex=34, endIndex=35, - required=True, validators=[ - validators.isInLimits(1, 3), - ]), - Field(item="13", name='RECEIVES_SUB_HOUSING', type='number', startIndex=35, endIndex=36, - required=True, validators=[ - validators.isInLimits(1, 3), - ]), - Field(item="14", name='RECEIVES_MED_ASSISTANCE', type='number', startIndex=36, endIndex=37, - required=True, validators=[ - validators.isInLimits(1, 2), - ]), - Field(item="15", name='RECEIVES_FOOD_STAMPS', type='number', startIndex=37, endIndex=38, - required=True, validators=[ - validators.or_validators(validators.isInLimits(0, 2), - validators.numIsBlank()), - ]), + Field(item="16", name='AMT_FOOD_STAMP_ASSISTANCE', type='number', startIndex=38, endIndex=42, required=True, validators=[ validators.isLargerThanOrEqualTo(0), ]), Field(item="17", name='RECEIVES_SUB_CC', type='number', startIndex=42, endIndex=43, - required=True, validators=[ + can_be_empty=True, required=True, validators=[ validators.or_validators(validators.isInLimits(0, 3), - validators.numIsBlank()), + validators.isBlank()), ]), Field(item="18", name='AMT_SUB_CC', type='number', startIndex=43, endIndex=47, required=True, validators=[ @@ -183,24 +147,24 @@ validators.isLargerThanOrEqualTo(0), ]), Field(item="24A", name='TRANSITION_SERVICES_AMOUNT', type='number', startIndex=78, endIndex=82, - required=True, validators=[ + can_be_empty=True, required=True, validators=[ validators.or_validators(validators.isLargerThanOrEqualTo(0), - validators.numIsBlank()), + validators.isBlank()), ]), Field(item="24B", name='TRANSITION_NBR_MONTHS', type='number', startIndex=82, endIndex=85, - required=True, validators=[ + can_be_empty=True, required=True, validators=[ validators.or_validators(validators.isLargerThanOrEqualTo(0), - validators.numIsBlank()), + validators.isBlank()), ]), Field(item="25A", name='OTHER_AMOUNT', type='number', startIndex=85, endIndex=89, - required=True, validators=[ + can_be_empty=True, required=True, validators=[ validators.or_validators(validators.isLargerThanOrEqualTo(0), - validators.numIsBlank()), + validators.isBlank()), ]), Field(item="25B", name='OTHER_NBR_MONTHS', type='number', startIndex=89, endIndex=92, - required=True, validators=[ + can_be_empty=True, required=True, validators=[ validators.or_validators(validators.isLargerThanOrEqualTo(0), - validators.numIsBlank()), + validators.isBlank()), ]), Field(item="26AI", name='SANC_REDUCTION_AMT', type='number', startIndex=92, endIndex=96, required=True, validators=[ @@ -211,9 +175,9 @@ validators.oneOf([1, 2]), ]), Field(item="26AIII", name='FAMILY_SANC_ADULT', type='number', startIndex=97, endIndex=98, - required=True, validators=[ + can_be_empty=True, required=True, validators=[ validators.or_validators(validators.oneOf([0, 1, 2]), - validators.numIsBlank()), + validators.isBlank()), ]), Field(item="26AIV", name='SANC_TEEN_PARENT', type='number', startIndex=98, endIndex=99, required=True, validators=[ @@ -252,7 +216,7 @@ validators.oneOf([1, 2]), ]), Field(item="27", name='WAIVER_EVAL_CONTROL_GRPS', type='string', startIndex=113, endIndex=114, - required=True, validators=[ + can_be_empty=True, required=True, validators=[ validators.or_validators( validators.and_validators( validators.or_validators(validators.matches('9'), validators.isEmpty()), @@ -266,9 +230,9 @@ 6, 7, 8, 9]) ]), Field(item="29", name='FAMILY_NEW_CHILD', type='number', startIndex=116, endIndex=117, - required=True, validators=[ + can_be_empty=True, required=True, validators=[ validators.or_validators(validators.oneOf([1, 2]), - validators.numIsBlank()), + validators.isBlank()), ]), Field(item="-1", name='BLANK', type='string', startIndex=117, endIndex=156, required=False, validators=[]), diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t2.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t2.py index 5145f69b5..c1150a902 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t2.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t2.py @@ -109,172 +109,191 @@ TransformField(transform_func=tanf_ssn_decryption_func, item="33", name='SSN', type='string', startIndex=29, endIndex=38, required=True, validators=[validators.validateSSN()], is_encrypted=False), - Field(item="34A", name='RACE_HISPANIC', type='number', startIndex=38, endIndex=39, required=True, + Field(item="34A", name='RACE_HISPANIC', type='number', startIndex=38, endIndex=39, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInLimits(0, 2), - validators.numIsBlank()),]), - Field(item="34B", name='RACE_AMER_INDIAN', type='number', startIndex=39, endIndex=40, required=True, + validators.isBlank()),]), + Field(item="34B", name='RACE_AMER_INDIAN', type='number', startIndex=39, endIndex=40, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInLimits(0, 2), - validators.numIsBlank()),]), - Field(item="34C", name='RACE_ASIAN', type='number', startIndex=40, endIndex=41, required=True, + validators.isBlank()),]), + Field(item="34C", name='RACE_ASIAN', type='number', startIndex=40, endIndex=41, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInLimits(0, 2), - validators.numIsBlank()),]), - Field(item="34D", name='RACE_BLACK', type='number', startIndex=41, endIndex=42, required=True, + validators.isBlank()),]), + Field(item="34D", name='RACE_BLACK', type='number', startIndex=41, endIndex=42, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInLimits(0, 2), - validators.numIsBlank()),]), - Field(item="34E", name='RACE_HAWAIIAN', type='number', startIndex=42, endIndex=43, required=True, + validators.isBlank()),]), + Field(item="34E", name='RACE_HAWAIIAN', type='number', startIndex=42, endIndex=43, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInLimits(0, 2), - validators.numIsBlank()),]), - Field(item="34F", name='RACE_WHITE', type='number', startIndex=43, endIndex=44, required=True, + validators.isBlank()),]), + Field(item="34F", name='RACE_WHITE', type='number', startIndex=43, endIndex=44, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInLimits(0, 2), - validators.numIsBlank()),]), + validators.isBlank()),]), Field(item="35", name='GENDER', type='number', startIndex=44, endIndex=45, required=True, validators=[validators.isLargerThanOrEqualTo(0),]), Field(item="36A", name='FED_OASDI_PROGRAM', type='number', startIndex=45, endIndex=46, required=True, validators=[validators.oneOf([1, 2])]), Field(item="36B", name='FED_DISABILITY_STATUS', type='number', startIndex=46, endIndex=47, required=True, validators=[validators.oneOf([1, 2])]), - Field(item="36C", name='DISABLED_TITLE_XIVAPDT', type='string', startIndex=47, endIndex=48, required=True, + Field(item="36C", name='DISABLED_TITLE_XIVAPDT', type='string', startIndex=47, endIndex=48, + can_be_empty=True, required=True, validators=[validators.or_validators(validators.oneOf(["1", "2"]), validators.isBlank())]), - Field(item="36D", name='AID_AGED_BLIND', type='number', startIndex=48, endIndex=49, required=True, + Field(item="36D", name='AID_AGED_BLIND', type='number', startIndex=48, endIndex=49, + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isLargerThanOrEqualTo(0), - validators.numIsBlank()),]), + validators.isBlank()),]), Field(item="36E", name='RECEIVE_SSI', type='number', startIndex=49, endIndex=50, required=True, validators=[validators.oneOf([1, 2]),]), - Field(item="37", name='MARITAL_STATUS', type='number', startIndex=50, endIndex=51, required=True, + Field(item="37", name='MARITAL_STATUS', type='number', startIndex=50, endIndex=51, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInLimits(0, 5), - validators.numIsBlank()),]), + validators.isBlank()),]), Field(item="38", name='RELATIONSHIP_HOH', type='string', startIndex=51, endIndex=53, required=True, validators=[validators.isInStringRange(1, 10),]), - Field(item="39", name='PARENT_WITH_MINOR_CHILD', type='number', startIndex=53, endIndex=54, required=True, + Field(item="39", name='PARENT_WITH_MINOR_CHILD', type='number', startIndex=53, endIndex=54, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInLimits(0, 3), - validators.numIsBlank()),]), - Field(item="40", name='NEEDS_PREGNANT_WOMAN', type='number', startIndex=54, endIndex=55, required=True, + validators.isBlank()),]), + Field(item="40", name='NEEDS_PREGNANT_WOMAN', type='number', startIndex=54, endIndex=55, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInLimits(0, 9), - validators.numIsBlank()),]), - Field(item="41", name='EDUCATION_LEVEL', type='string', startIndex=55, endIndex=57, required=True, + validators.isBlank()),]), + Field(item="41", name='EDUCATION_LEVEL', type='string', startIndex=55, endIndex=57, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInStringRange(0, 16), validators.isInStringRange(98, 99), validators.isBlank())]), - Field(item="42", name='CITIZENSHIP_STATUS', type='number', startIndex=57, endIndex=58, required=True, + Field(item="42", name='CITIZENSHIP_STATUS', type='number', startIndex=57, endIndex=58, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.oneOf([0, 1, 2, 9]), - validators.numIsBlank()),]), + validators.isBlank()),]), Field(item="43", name='COOPERATION_CHILD_SUPPORT', type='number', startIndex=58, endIndex=59, - required=True, validators=[validators.or_validators(validators.oneOf([0, 1, 2, 9]), - validators.numIsBlank()),]), - Field(item="44", name='MONTHS_FED_TIME_LIMIT', type='string', startIndex=59, endIndex=62, required=True, + can_be_empty=True, required=True, validators=[validators.or_validators(validators.oneOf([0, 1, 2, 9]), + validators.isBlank()),]), + Field(item="44", name='MONTHS_FED_TIME_LIMIT', type='string', startIndex=59, endIndex=62, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInStringRange(0, 999), validators.isBlank()),]), - Field(item="45", name='MONTHS_STATE_TIME_LIMIT', type='string', startIndex=62, endIndex=64, required=True, + Field(item="45", name='MONTHS_STATE_TIME_LIMIT', type='string', startIndex=62, endIndex=64, + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="46", name='CURRENT_MONTH_STATE_EXEMPT', type='number', startIndex=64, endIndex=65, - required=True, validators=[validators.or_validators(validators.isInLimits(0, 9), - validators.numIsBlank()),]), - Field(item="47", name='EMPLOYMENT_STATUS', type='number', startIndex=65, endIndex=66, required=True, + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInLimits(0, 9), + validators.isBlank()),]), + Field(item="47", name='EMPLOYMENT_STATUS', type='number', startIndex=65, endIndex=66, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInLimits(0, 3), - validators.numIsBlank()),]), + validators.isBlank()),]), Field(item="48", name='WORK_ELIGIBLE_INDICATOR', type='string', startIndex=66, endIndex=68, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 9), validators.oneOf(('11', '12')) )]), - Field(item="49", name='WORK_PART_STATUS', type='string', startIndex=68, endIndex=70, required=True, + Field(item="49", name='WORK_PART_STATUS', type='string', startIndex=68, endIndex=70, can_be_empty=True, + required=True, validators=[validators.or_validators( validators.oneOf(['01', '02', '05', '07', '09', '15', '16', '17', '18', '19', '99']), validators.isBlank()),]), - Field(item="50", name='UNSUB_EMPLOYMENT', type='string', startIndex=70, endIndex=72, required=True, + Field(item="50", name='UNSUB_EMPLOYMENT', type='string', startIndex=70, endIndex=72, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="51", name='SUB_PRIVATE_EMPLOYMENT', type='string', startIndex=72, endIndex=74, required=True, + Field(item="51", name='SUB_PRIVATE_EMPLOYMENT', type='string', startIndex=72, endIndex=74, can_be_empty=True, + required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="52", name='SUB_PUBLIC_EMPLOYMENT', type='string', startIndex=74, endIndex=76, required=True, + Field(item="52", name='SUB_PUBLIC_EMPLOYMENT', type='string', startIndex=74, endIndex=76, can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="53A", name='WORK_EXPERIENCE_HOP', type='string', startIndex=76, endIndex=78, required=True, + Field(item="53A", name='WORK_EXPERIENCE_HOP', type='string', startIndex=76, endIndex=78, can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="53B", name='WORK_EXPERIENCE_EA', type='string', startIndex=78, endIndex=80, required=True, + Field(item="53B", name='WORK_EXPERIENCE_EA', type='string', startIndex=78, endIndex=80, can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="53C", name='WORK_EXPERIENCE_HOL', type='string', startIndex=80, endIndex=82, required=True, + Field(item="53C", name='WORK_EXPERIENCE_HOL', type='string', startIndex=80, endIndex=82, can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="54", name='OJT', type='string', startIndex=82, endIndex=84, required=True, validators=[ + Field(item="54", name='OJT', type='string', startIndex=82, endIndex=84, can_be_empty=True, required=True, validators=[ validators.or_validators( validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="55A", name='JOB_SEARCH_HOP', type='string', startIndex=84, endIndex=86, required=True, + Field(item="55A", name='JOB_SEARCH_HOP', type='string', startIndex=84, endIndex=86, can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="55B", name='JOB_SEARCH_EA', type='string', startIndex=86, endIndex=88, required=True, + Field(item="55B", name='JOB_SEARCH_EA', type='string', startIndex=86, endIndex=88, can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="55C", name='JOB_SEARCH_HOL', type='string', startIndex=88, endIndex=90, required=True, + Field(item="55C", name='JOB_SEARCH_HOL', type='string', startIndex=88, endIndex=90, can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="56A", name='COMM_SERVICES_HOP', type='string', startIndex=90, endIndex=92, required=True, + Field(item="56A", name='COMM_SERVICES_HOP', type='string', startIndex=90, endIndex=92, can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="56B", name='COMM_SERVICES_EA', type='string', startIndex=92, endIndex=94, required=True, + Field(item="56B", name='COMM_SERVICES_EA', type='string', startIndex=92, endIndex=94, can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), - Field(item="56C", name='COMM_SERVICES_HOL', type='string', startIndex=94, endIndex=96, required=True, + Field(item="56C", name='COMM_SERVICES_HOL', type='string', startIndex=94, endIndex=96, can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="57A", name='VOCATIONAL_ED_TRAINING_HOP', type='string', startIndex=96, endIndex=98, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="57B", name='VOCATIONAL_ED_TRAINING_EA', type='string', startIndex=98, endIndex=100, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="57C", name='VOCATIONAL_ED_TRAINING_HOL', type='string', startIndex=100, endIndex=102, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="58A", name='JOB_SKILLS_TRAINING_HOP', type='string', startIndex=102, endIndex=104, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="58B", name='JOB_SKILLS_TRAINING_EA', type='string', startIndex=104, endIndex=106, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="58C", name='JOB_SKILLS_TRAINING_HOL', type='string', startIndex=106, endIndex=108, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="59A", name='ED_NO_HIGH_SCHOOL_DIPL_HOP', type='string', startIndex=108, endIndex=110, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="59B", name='ED_NO_HIGH_SCHOOL_DIPL_EA', type='string', startIndex=110, endIndex=112, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="59C", name='ED_NO_HIGH_SCHOOL_DIPL_HOL', type='string', startIndex=112, endIndex=114, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="60A", name='SCHOOL_ATTENDENCE_HOP', type='string', startIndex=114, endIndex=116, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="60B", name='SCHOOL_ATTENDENCE_EA', type='string', startIndex=116, endIndex=118, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="60C", name='SCHOOL_ATTENDENCE_HOL', type='string', startIndex=118, endIndex=120, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="61A", name='PROVIDE_CC_HOP', type='string', startIndex=120, endIndex=122, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="61B", name='PROVIDE_CC_EA', type='string', startIndex=122, endIndex=124, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="61C", name='PROVIDE_CC_HOL', type='string', startIndex=124, endIndex=126, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="62", name='OTHER_WORK_ACTIVITIES', type='string', startIndex=126, endIndex=128, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="63", name='DEEMED_HOURS_FOR_OVERALL', type='string', startIndex=128, endIndex=130, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="64", name='DEEMED_HOURS_FOR_TWO_PARENT', type='string', startIndex=130, endIndex=132, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), + can_be_empty=True, required=True, validators=[validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()),]), Field(item="65", name='EARNED_INCOME', type='string', startIndex=132, endIndex=136, required=True, validators=[validators.isInStringRange(0, 9999),]), diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t3.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t3.py index 3315cf49a..1c5d04016 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t3.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t3.py @@ -83,24 +83,24 @@ TransformField(transform_func=tanf_ssn_decryption_func, item="69", name='SSN', type='string', startIndex=28, endIndex=37, required=True, validators=[validators.validateSSN()], is_encrypted=False), - Field(item="70A", name='RACE_HISPANIC', type='number', startIndex=37, endIndex=38, + Field(item="70A", name='RACE_HISPANIC', type='number', startIndex=37, endIndex=38, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), - Field(item="70B", name='RACE_AMER_INDIAN', type='number', startIndex=38, endIndex=39, + validators.isBlank()),]), + Field(item="70B", name='RACE_AMER_INDIAN', type='number', startIndex=38, endIndex=39, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), - Field(item="70C", name='RACE_ASIAN', type='number', startIndex=39, endIndex=40, + validators.isBlank()),]), + Field(item="70C", name='RACE_ASIAN', type='number', startIndex=39, endIndex=40, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), - Field(item="70D", name='RACE_BLACK', type='number', startIndex=40, endIndex=41, + validators.isBlank()),]), + Field(item="70D", name='RACE_BLACK', type='number', startIndex=40, endIndex=41, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), - Field(item="70E", name='RACE_HAWAIIAN', type='number', startIndex=41, endIndex=42, + validators.isBlank()),]), + Field(item="70E", name='RACE_HAWAIIAN', type='number', startIndex=41, endIndex=42, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), - Field(item="70F", name='RACE_WHITE', type='number', startIndex=42, endIndex=43, + validators.isBlank()),]), + Field(item="70F", name='RACE_WHITE', type='number', startIndex=42, endIndex=43, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), + validators.isBlank()),]), Field(item="71", name='GENDER', type='number', startIndex=43, endIndex=44, required=True, validators=[ validators.isInLimits(0, 9) @@ -113,15 +113,15 @@ required=True, validators=[ validators.oneOf([1, 2]) ]), - Field(item="73", name='RELATIONSHIP_HOH', type='string', startIndex=46, endIndex=48, + Field(item="73", name='RELATIONSHIP_HOH', type='string', startIndex=46, endIndex=48, can_be_empty=True, required=True, validators=[ validators.or_validators(validators.isInStringRange(0, 10), validators.isBlank()) ]), - Field(item="74", name='PARENT_MINOR_CHILD', type='number', startIndex=48, endIndex=49, + Field(item="74", name='PARENT_MINOR_CHILD', type='number', startIndex=48, endIndex=49, can_be_empty=True, required=True, validators=[ validators.or_validators(validators.oneOf([0, 2, 3]), - validators.numIsBlank()) + validators.isBlank()) ]), Field(item="75", name='EDUCATION_LEVEL', type='string', startIndex=49, endIndex=51, required=True, validators=[ @@ -130,10 +130,10 @@ validators.isInStringRange(98, 99) ) ]), - Field(item="76", name='CITIZENSHIP_STATUS', type='number', startIndex=51, endIndex=52, + Field(item="76", name='CITIZENSHIP_STATUS', type='number', startIndex=51, endIndex=52, can_be_empty=True, required=True, validators=[ validators.or_validators(validators.oneOf([0, 1, 2, 9]), - validators.numIsBlank()) + validators.isBlank()) ]), Field(item="77A", name='UNEARNED_SSI', type='string', startIndex=52, endIndex=56, required=True, validators=[ @@ -221,24 +221,24 @@ TransformField(transform_func=tanf_ssn_decryption_func, item="69", name='SSN', type='string', startIndex=69, endIndex=78, required=True, validators=[validators.validateSSN()], is_encrypted=False), - Field(item="70A", name='RACE_HISPANIC', type='number', startIndex=78, endIndex=79, + Field(item="70A", name='RACE_HISPANIC', type='number', startIndex=78, endIndex=79, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), - Field(item="70B", name='RACE_AMER_INDIAN', type='number', startIndex=79, endIndex=80, + validators.isBlank()),]), + Field(item="70B", name='RACE_AMER_INDIAN', type='number', startIndex=79, endIndex=80, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), - Field(item="70C", name='RACE_ASIAN', type='number', startIndex=80, endIndex=81, + validators.isBlank()),]), + Field(item="70C", name='RACE_ASIAN', type='number', startIndex=80, endIndex=81, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), - Field(item="70D", name='RACE_BLACK', type='number', startIndex=81, endIndex=82, + validators.isBlank()),]), + Field(item="70D", name='RACE_BLACK', type='number', startIndex=81, endIndex=82, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), - Field(item="70E", name='RACE_HAWAIIAN', type='number', startIndex=82, endIndex=83, + validators.isBlank()),]), + Field(item="70E", name='RACE_HAWAIIAN', type='number', startIndex=82, endIndex=83, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), - Field(item="70F", name='RACE_WHITE', type='number', startIndex=83, endIndex=84, + validators.isBlank()),]), + Field(item="70F", name='RACE_WHITE', type='number', startIndex=83, endIndex=84, can_be_empty=True, required=True, validators=[validators.or_validators(validators.validateRace(), - validators.numIsBlank()),]), + validators.isBlank()),]), Field(item="71", name='GENDER', type='number', startIndex=84, endIndex=85, required=True, validators=[ validators.isInLimits(0, 9) @@ -251,15 +251,15 @@ required=True, validators=[ validators.oneOf([1, 2]) ]), - Field(item="73", name='RELATIONSHIP_HOH', type='string', startIndex=87, endIndex=89, + Field(item="73", name='RELATIONSHIP_HOH', type='string', startIndex=87, endIndex=89, can_be_empty=True, required=True, validators=[ validators.or_validators(validators.isInStringRange(0, 10), validators.isBlank()) ]), - Field(item="74", name='PARENT_MINOR_CHILD', type='number', startIndex=89, endIndex=90, + Field(item="74", name='PARENT_MINOR_CHILD', type='number', startIndex=89, endIndex=90, can_be_empty=True, required=True, validators=[ validators.or_validators(validators.oneOf([0, 2, 3]), - validators.numIsBlank()) + validators.isBlank()) ]), Field(item="75", name='EDUCATION_LEVEL', type='string', startIndex=90, endIndex=92, required=True, validators=[ @@ -268,10 +268,10 @@ validators.oneOf(['98', '99']) ) ]), - Field(item="76", name='CITIZENSHIP_STATUS', type='number', startIndex=92, endIndex=93, + Field(item="76", name='CITIZENSHIP_STATUS', type='number', startIndex=92, endIndex=93, can_be_empty=True, required=True, validators=[ validators.or_validators(validators.oneOf([0, 1, 2, 9]), - validators.numIsBlank()) + validators.isBlank()) ]), Field(item="77A", name='UNEARNED_SSI', type='string', startIndex=93, endIndex=97, required=True, validators=[ diff --git a/tdrs-backend/tdpservice/parsers/test/test_validators.py b/tdrs-backend/tdpservice/parsers/test/test_validators.py index 197467543..ae63a2604 100644 --- a/tdrs-backend/tdpservice/parsers/test/test_validators.py +++ b/tdrs-backend/tdpservice/parsers/test/test_validators.py @@ -1034,7 +1034,7 @@ def test_t1_blank_fields(): stratum_val = validators.or_validators(validators.isInStringRange(0, 99), validators.isBlank()) - tsa_val = validators.or_validators(validators.isLargerThanOrEqualTo(0), validators.numIsBlank()) + tsa_val = validators.or_validators(validators.isLargerThanOrEqualTo(0), validators.isBlank()) assert stratum_val(t1.STRATUM) == (True, None) assert tsa_val(t1.TRANSITION_SERVICES_AMOUNT) == (True, None) @@ -1047,7 +1047,7 @@ def test_t2_blank_fields(): t2.EDUCATION_LEVEL = " " t2.WORK_EXPERIENCE_HOL = " " - race_val = validators.or_validators(validators.isInLimits(0, 2), validators.numIsBlank()) + race_val = validators.or_validators(validators.isInLimits(0, 2), validators.isBlank()) ed_level_val = validators.or_validators(validators.isInStringRange(0, 16), validators.isInStringRange(98, 99), validators.isBlank()) @@ -1065,9 +1065,9 @@ def test_t3_blank_fields(): t3.RELATIONSHIP_HOH = " " t3.CITIZENSHIP_STATUS = None - race_val = validators.or_validators(validators.validateRace(), validators.numIsBlank()) + race_val = validators.or_validators(validators.validateRace(), validators.isBlank()) hoh_val = validators.or_validators(validators.isInStringRange(0, 10), validators.isBlank()) - cit_status_val = validators.or_validators(validators.oneOf([0, 1, 2, 9]), validators.numIsBlank()) + cit_status_val = validators.or_validators(validators.oneOf([0, 1, 2, 9]), validators.isBlank()) assert race_val(t3.RACE_HISPANIC) == (True, None) assert hoh_val(t3.RELATIONSHIP_HOH) == (True, None) diff --git a/tdrs-backend/tdpservice/parsers/validators.py b/tdrs-backend/tdpservice/parsers/validators.py index 3354c49c0..2c81ef1b7 100644 --- a/tdrs-backend/tdpservice/parsers/validators.py +++ b/tdrs-backend/tdpservice/parsers/validators.py @@ -173,19 +173,12 @@ def isAlphaNumeric(): ) def isBlank(): - """Validate that string value is blank.""" + """Validate that value is blank.""" return make_validator( - lambda value: value.isspace(), + lambda value: value.isspace() or value is None, lambda value: f'{value} is not blank.' ) -def numIsBlank(): - """Validate that a number field was all blanks at parse time.""" - return make_validator( - lambda value: value is None, - lambda value: f'{value} is not a blank integer.' - ) - def isInStringRange(lower, upper): """Validate that string value is in a specific range.""" return make_validator(