Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/validators/i18n/fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def fr_ssn(value: str):
if department != "99" and not fr_department(department):
# 99 stands for foreign born people
return False
if control_key is None:
# no control key provided, no additional check needed
return True
if len(department) == len(groups[4]):
# if the department number is 3 digits long (overseas departments),
# the town number must be 2 digits long
# and vice versa
return False
if control_key is None:
# no control key provided, no additional check needed
return True
if department in ("2A", "2B"):
# Corsica's department numbers are not in the same range as the others
# thus 2A and 2B are replaced by 19 and 18 respectively to compute the control key
Expand Down
8 changes: 7 additions & 1 deletion tests/i18n/test_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
("2 99 05 2A 202 817 58",),
("2 99 05 2B 202 817 85",),
("2 99 05 971 12 817 70",),
("2 99 05 971 12 817",), # overseas department without control key
("2 99 05 2A 202 817",), # Corsica without control key
("2 99 05 99 202 817",), # foreign birthplace without control key
],
)
def test_returns_true_on_valid_ssn(value: str):
Expand All @@ -41,7 +44,10 @@ def test_returns_true_on_valid_ssn(value: str):
("1 84 12 00 451 089",), # invalid department
("1 84 12 2C 451 089",),
("1 84 12 98 451 089",), # invalid department
# ("1 84 12 971 451 089",), # ?
("1 84 12 971 451 089",), # three-digit department needs two-digit town
("1 84 12 76 45 089",), # two-digit department needs three-digit town
("1 84 12 2A 45 089",),
("1 84 12 99 45 089",),
],
)
def test_returns_failed_validation_on_invalid_ssn(value: str):
Expand Down