Skip to content

Commit fe349bb

Browse files
committed
Validate French SSN birthplace widths without a control key
1 parent 22786cc commit fe349bb

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎src/validators/i18n/fr.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ def fr_ssn(value: str):
102102
if department != "99" and not fr_department(department):
103103
# 99 stands for foreign born people
104104
return False
105-
if control_key is None:
106-
# no control key provided, no additional check needed
107-
return True
108105
if len(department) == len(groups[4]):
109106
# if the department number is 3 digits long (overseas departments),
110107
# the town number must be 2 digits long
111108
# and vice versa
112109
return False
110+
if control_key is None:
111+
# no control key provided, no additional check needed
112+
return True
113113
if department in ("2A", "2B"):
114114
# Corsica's department numbers are not in the same range as the others
115115
# thus 2A and 2B are replaced by 19 and 18 respectively to compute the control key

‎tests/i18n/test_fr.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
("2 99 05 2A 202 817 58",),
2222
("2 99 05 2B 202 817 85",),
2323
("2 99 05 971 12 817 70",),
24+
("2 99 05 971 12 817",), # overseas department without control key
25+
("2 99 05 2A 202 817",), # Corsica without control key
26+
("2 99 05 99 202 817",), # foreign birthplace without control key
2427
],
2528
)
2629
def test_returns_true_on_valid_ssn(value: str):
@@ -41,7 +44,10 @@ def test_returns_true_on_valid_ssn(value: str):
4144
("1 84 12 00 451 089",), # invalid department
4245
("1 84 12 2C 451 089",),
4346
("1 84 12 98 451 089",), # invalid department
44-
# ("1 84 12 971 451 089",), # ?
47+
("1 84 12 971 451 089",), # three-digit department needs two-digit town
48+
("1 84 12 76 45 089",), # two-digit department needs three-digit town
49+
("1 84 12 2A 45 089",),
50+
("1 84 12 99 45 089",),
4551
],
4652
)
4753
def test_returns_failed_validation_on_invalid_ssn(value: str):

0 commit comments

Comments
 (0)