Skip to content

Commit

Permalink
- Integrating Jans changes. Parametrizing values_is_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
elipe17 committed Dec 11, 2023
1 parent 55ce817 commit 58e3324
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tdrs-backend/tdpservice/parsers/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def parse_datafile(datafile):
return errors

is_encrypted = field_values["encryption"] == "E"
is_tribal = util.is_string_field_valid(field_values["tribe_code"], 3)
is_tribal = not validators.value_is_empty(field_values["tribe_code"], 3, extra_vals={'0'*3})

logger.debug(f"Datafile has encrypted fields: {is_encrypted}.")
logger.debug(f"Datafile: {datafile.__repr__()}, is Tribal: {is_tribal}.")
Expand Down
4 changes: 0 additions & 4 deletions tdrs-backend/tdpservice/parsers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ def update_encrypted_fields(self, is_encrypted):
if type(field) == TransformField and "is_encrypted" in field.kwargs:
field.kwargs['is_encrypted'] = is_encrypted

def is_string_field_valid(val, field_length):
"""Determine if the field's value is valid."""
return val not in {" "*field_length, None, "0"*field_length}

def get_schema_options(program, section, query=None, model=None, model_name=None):
"""Centralized function to return the appropriate schema for a given program, section, and query.
Expand Down
15 changes: 8 additions & 7 deletions tdrs-backend/tdpservice/parsers/validators.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
"""Generic parser validator functions for use in schema definitions."""

from .models import ParserErrorCategoryChoices
from .util import is_string_field_valid
from datetime import date
import logging

logger = logging.getLogger(__name__)


def value_is_empty(value, length):
def value_is_empty(value, length, extra_vals={}):
"""Handle 'empty' values as field inputs."""
empty_values = [
empty_values = {
'',
' '*length, # ' '
'#'*length, # '#####'
'_'*length, # '_____'
]
}

empty_values = empty_values.union(extra_vals)

return value is None or value in empty_values

Expand Down Expand Up @@ -554,10 +555,10 @@ def validate_tribe_fips_program_agree(program_type, tribe_code, state_fips_code,
"""Validate tribe code, fips code, and program type all agree with eachother."""
is_valid = False

if program_type == 'TAN' and (not is_string_field_valid(state_fips_code, 2)):
is_valid = is_string_field_valid(tribe_code, 3)
if program_type == 'TAN' and value_is_empty(state_fips_code, 2, extra_vals={'0'*2}):
is_valid = not value_is_empty(tribe_code, 3, extra_vals={'0'*3})
else:
is_valid = not is_string_field_valid(tribe_code, 3)
is_valid = value_is_empty(tribe_code, 3, extra_vals={'0'*3})

error = None
if not is_valid:
Expand Down

0 comments on commit 58e3324

Please sign in to comment.