0001-toulouse_axel-normalize-numvoie-fields-40462.patch
passerelle/contrib/toulouse_axel/models.py | ||
---|---|---|
665 | 665 |
continue |
666 | 666 |
child['CONTACT'] = [c for c in child['CONTACT'] if c['NOM'] and c['PRENOM']] |
667 | 667 | |
668 |
# clean NUMVOIE fields |
|
669 |
if 'ADRESSE' in post_data: |
|
670 |
post_data['ADRESSE']['NUMVOIE'] = utils.normalize_numvoie(post_data['ADRESSE']['NUMVOIE']) |
|
671 |
for rl in ['RL1', 'RL2']: |
|
672 |
if rl not in post_data: |
|
673 |
continue |
|
674 |
if 'ADREMPLOYEUR' not in post_data[rl]: |
|
675 |
continue |
|
676 |
post_data[rl]['ADREMPLOYEUR']['NUMVOIE'] = utils.normalize_numvoie( |
|
677 |
post_data[rl]['ADREMPLOYEUR']['NUMVOIE']) |
|
678 | ||
668 | 679 |
# if ENFANT block is empty, remove it |
669 | 680 |
if not post_data['ENFANT']: |
670 | 681 |
post_data.pop('ENFANT') |
passerelle/contrib/toulouse_axel/utils.py | ||
---|---|---|
139 | 139 |
return obj |
140 | 140 | |
141 | 141 | |
142 |
def normalize_numvoie(value): |
|
143 |
if not value: |
|
144 |
return value |
|
145 |
value = value.replace(" ", "") |
|
146 |
result = [] |
|
147 |
for char in str(value): |
|
148 |
try: |
|
149 |
result.append(str(int(char))) |
|
150 |
except ValueError: |
|
151 |
# append first non digit char only |
|
152 |
result.append(char) |
|
153 |
break |
|
154 |
return ''.join(result) |
|
155 | ||
156 | ||
142 | 157 |
def normalize_invoice(invoice, dui, historical=False, vendor_base=None): |
143 | 158 |
vendor = vendor_base or {} |
144 | 159 |
vendor.update(invoice) |
tests/test_toulouse_axel.py | ||
---|---|---|
1039 | 1039 |
assert value is None |
1040 | 1040 | |
1041 | 1041 | |
1042 |
@pytest.mark.parametrize('value, expected', [ |
|
1043 |
(None, None), |
|
1044 |
('', ''), |
|
1045 |
('42', '42'), |
|
1046 |
('42bis', '42b'), |
|
1047 |
('42 bis', '42b'), |
|
1048 |
('42b', '42b'), |
|
1049 |
]) |
|
1050 |
def test_pre_sanitize_update_family_data_numvoie(app, resource, update_params, value, expected): |
|
1051 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
|
1052 | ||
1053 |
# test maj:adresse |
|
1054 |
partial_update_params = copy.deepcopy(update_params) |
|
1055 |
partial_update_params['ADRESSE']['NUMVOIE'] = value |
|
1056 |
partial_update_params['RL1']['ADREMPLOYEUR']['NUMVOIE'] = value |
|
1057 |
partial_update_params['RL2']['ADREMPLOYEUR']['NUMVOIE'] = value |
|
1058 |
resource.pre_sanitize_update_family_data(post_data=partial_update_params) |
|
1059 |
assert partial_update_params['ADRESSE']['NUMVOIE'] == expected |
|
1060 |
assert partial_update_params['RL1']['ADREMPLOYEUR']['NUMVOIE'] == expected |
|
1061 |
assert partial_update_params['RL2']['ADREMPLOYEUR']['NUMVOIE'] == expected |
|
1062 | ||
1063 | ||
1042 | 1064 |
def test_pre_sanitize_update_family_data_revenus(app, resource, update_params): |
1043 | 1065 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
1044 | 1066 | |
1045 |
- |