From fc42e6ab0b4fae52fb91e0b5e44fad86174a1bd8 Mon Sep 17 00:00:00 2001 From: Antti Pakkanen Date: Mon, 23 Oct 2023 23:12:09 +0300 Subject: [PATCH] Add handling for finnish ssn where `min_age` and `max_age` are the same (#1937) Co-authored-by: Antti Pakkanen --- faker/providers/ssn/fi_FI/__init__.py | 5 ++++- tests/providers/test_ssn.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/faker/providers/ssn/fi_FI/__init__.py b/faker/providers/ssn/fi_FI/__init__.py index 8e8bba6c8a..016782c09c 100644 --- a/faker/providers/ssn/fi_FI/__init__.py +++ b/faker/providers/ssn/fi_FI/__init__.py @@ -26,7 +26,10 @@ def _checksum(hetu): checksum_characters = "0123456789ABCDEFHJKLMNPRSTUVWXY" return checksum_characters[int(hetu) % 31] - age = datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365)) + if min_age == max_age: + age = datetime.timedelta(days=min_age * 365) + else: + age = datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365)) birthday = datetime.date.today() - age hetu_date = "%02d%02d%s" % ( birthday.day, diff --git a/tests/providers/test_ssn.py b/tests/providers/test_ssn.py index 6765f54cbf..0672c0866d 100644 --- a/tests/providers/test_ssn.py +++ b/tests/providers/test_ssn.py @@ -793,6 +793,18 @@ def test_vat_id(self): for _ in range(100): assert re.search(r"^FI\d{8}$", self.fake.vat_id()) + def test_ssn_without_age_range(self): + current_year = datetime.now().year + age = current_year - 1995 + ssn = self.fake.ssn(min_age=age, max_age=age, artificial=True) + assert "95-" in ssn + age = current_year - 2013 + ssn = self.fake.ssn(min_age=age, max_age=age, artificial=True) + assert "13A" in ssn + age = current_year - 1898 + ssn = self.fake.ssn(min_age=age, max_age=age, artificial=True) + assert "98+" in ssn + class TestFrFR(unittest.TestCase): def setUp(self):