Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added handling for finnish ssn where min age and max age are the same #1937

Merged
Merged
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
5 changes: 4 additions & 1 deletion faker/providers/ssn/fi_FI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions tests/providers/test_ssn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading