Skip to content

Commit

Permalink
Merge pull request #519 from pipermerriam/piper/issue-513-strip-leadi…
Browse files Browse the repository at this point in the history
…ng-zeros

Strip leading zeros off of tax ids
  • Loading branch information
mmclark committed Dec 8, 2015
2 parents fd8b802 + be24d48 commit f924be3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
10 changes: 9 additions & 1 deletion seed/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,15 @@ def map_row_chunk(chunk, file_pk, source_type, prog_key, increment, *args, **kwa


def _normalize_tax_lot_id(value):
return value.strip().upper().replace('-', '').replace(' ', '').replace('/', '').replace('\\', '')
return value.strip().lstrip('0').upper().replace(
'-', ''
).replace(
' ', ''
).replace(
'/', ''
).replace(
'\\', ''
)


def split(value, delimiters):
Expand Down
19 changes: 10 additions & 9 deletions seed/tests/test_tax_lot_id_splitting_and_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,24 @@ class ExtractTaxLotIDTests(TestCase):

# test name, input, expected output
cases = [
('single_with_hyphen', '0344-0962', ['03440962']),
('single_with_hyphen', '1344-0962', ['13440962']),
('single_with_space', '2193 0011', ['21930011']),
('single_no_space', '0248F0084', ['0248F0084']),
('single_no_space', '1248F0084', ['1248F0084']),
('single_no_space_with_alpha', 'NNN08120459', ['NNN08120459']),
('double_1', '0312 0523; 0312 0524', ['03120523', '03120524']),
('double_2', '0534 0022;0634 0753', ['05340022', '06340753']),
('double_3', '0094-5001;0053-8005', ['00945001', '00538005']),
('double_1', '1312 0523; 1312 0524', ['13120523', '13120524']),
('double_2', '1534 0022;1634 0753', ['15340022', '16340753']),
('double_3', '1094-5001;1053-8005', ['10945001', '10538005']),
('double_4', '2648-0011; 5942-0057', ['26480011', '59420057']),
('double_5', '94624834;94624512', ['94624834', '94624512']),
('double_6', '02460501; NNN02460501', ['02460501', 'NNN02460501']),
('double_6', '12460501; NNN02460501', ['12460501', 'NNN02460501']),
('double_7', 'NNN 06200094;1369 0004', ['NNN06200094', '13690004']),
('triple_1', '33366555; 33366125; 33366148', ['33366555', '33366125', '33366148']),
('triple_2', '0250 0703, 0250 0755, 0250 0651', ['02500703', '02500755', '02500651']),
('triple_3', '05840022, 06490020', ['05840022', '06490020']),
('triple_2', '1250 0703, 1250 0755, 1250 0651', ['12500703', '12500755', '12500651']),
('triple_3', '50840022, 60490020', ['50840022', '60490020']),
('quad_1', '2219-0008, 2445-0001, 6055-0005, 2098-0003', ['22190008', '24450001', '60550005', '20980003']),
('compound_1', '1234-5678;9876 5432, 1048 5938', ['12345678', '98765432', '10485938']),
# Non string values
('non_string_value', 123456789, ['123456789']),
# Leading zeroes
('leading_zeros', '0001-1234', ['11234']),
]

0 comments on commit f924be3

Please sign in to comment.