Skip to content

Commit

Permalink
3059 DOB SSN field space filled (#3082)
Browse files Browse the repository at this point in the history
* 3050 checking for None values

* linting and cleaning

* clean up test

* 3059 refactored the logic

* 3059 small clean up

* linting
  • Loading branch information
raftmsohani authored Jul 26, 2024
1 parent 9013e71 commit 03311c6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tdrs-backend/docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3.4"

services:
postgres:
image: postgres:11.6
image: postgres:15.7
environment:
- PGDATA=/var/lib/postgresql/data/
- POSTGRES_DB=tdrs_test
Expand Down
27 changes: 25 additions & 2 deletions tdrs-backend/tdpservice/parsers/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
from datetime import datetime
from ..fields import Field
from ..row_schema import RowSchema, SchemaManager
from ..util import make_generate_parser_error, create_test_datafile, get_years_apart, clean_options_string

from ..util import (
make_generate_parser_error,
create_test_datafile,
get_years_apart,
clean_options_string,
generate_t2_t3_t5_hashes)
import logging

def passing_validator():
"""Fake validator that always returns valid."""
Expand Down Expand Up @@ -553,3 +558,21 @@ def test_clean_options_string(options, expected):
"""Test `clean_options_string` util func."""
result = clean_options_string(options)
assert result == expected


@pytest.mark.django_db()
def test_empty_SSN_DOB_space_filled(caplog):
"""Test empty_SSN_DOB_space_filled."""
line = 'fake_line'

class record:
CASE_NUMBER = 'fake_case_number'
SSN = None
DATE_OF_BIRTH = None
FAMILY_AFFILIATION = 'fake_family_affiliation'
RPT_MONTH_YEAR = '202310'
RecordType = 'T2'

with caplog.at_level(logging.ERROR):
generate_t2_t3_t5_hashes(line, record)
assert caplog.text == ''
7 changes: 4 additions & 3 deletions tdrs-backend/tdpservice/parsers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,15 @@ def remove_case_due_to_errors(self, should_remove, case_hash):
def generate_t1_t4_hashes(line, record):
"""Return hashes for duplicate and partial duplicate detection for T1 & T4 records."""
logger.debug(f"Partial Hash Field Values: {record.RecordType} {str(record.RPT_MONTH_YEAR)} {record.CASE_NUMBER}")
return hash(line), hash(record.RecordType + str(record.RPT_MONTH_YEAR) + record.CASE_NUMBER)
return hash(line), hash(record.RecordType + str(record.RPT_MONTH_YEAR or '') + str(record.CASE_NUMBER or ''))

def generate_t2_t3_t5_hashes(line, record):
"""Return hashes for duplicate and partial duplicate detection for T2 & T3 & T5 records."""
logger.debug(f"Partial Hash Field Values: {record.RecordType} {str(record.RPT_MONTH_YEAR)} {record.CASE_NUMBER} " +
f"{str(record.FAMILY_AFFILIATION)} {record.DATE_OF_BIRTH} {record.SSN}")
return hash(line), hash(record.RecordType + str(record.RPT_MONTH_YEAR) + record.CASE_NUMBER +
str(record.FAMILY_AFFILIATION) + record.DATE_OF_BIRTH + record.SSN)
return hash(line), hash(record.RecordType + str(record.RPT_MONTH_YEAR or '') + str(record.CASE_NUMBER or '') +
str(record.FAMILY_AFFILIATION or '') + str(record.DATE_OF_BIRTH or '') +
str(record.SSN or ''))

def get_t1_t4_partial_hash_members():
"""Return field names used to generate t1/t4 partial hashes."""
Expand Down
2 changes: 1 addition & 1 deletion tdrs-backend/tdpservice/search_indexes/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, field, request, params, model, model_admin, field_path):
self.lookup_choices = self._get_lookup_choices(request)

def _get_lookup_choices(self, request):
"""Filter queryset to guarentee lookup_choices only has STTs associated with the record type."""
"""Filter queryset to guarantee lookup_choices only has STTs associated with the record type."""
record_type = str(request.path).split('/')[-2]
queryset = STT.objects.all()
if 'tribal' in record_type:
Expand Down

0 comments on commit 03311c6

Please sign in to comment.