diff --git a/src/validators/i18n/fr.py b/src/validators/i18n/fr.py index 5552ef61..04d8cd9e 100644 --- a/src/validators/i18n/fr.py +++ b/src/validators/i18n/fr.py @@ -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 diff --git a/tests/i18n/test_fr.py b/tests/i18n/test_fr.py index f25c87c5..9727a069 100644 --- a/tests/i18n/test_fr.py +++ b/tests/i18n/test_fr.py @@ -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): @@ -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):