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

New Identification Numbers for several locales. #1875

Closed
wants to merge 10 commits into from
Closed
41 changes: 39 additions & 2 deletions faker/providers/ssn/de_AT/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
from .. import Provider as BaseProvider

import datetime
from faker.utils.checksums import calculate_luhn

class Provider(BaseProvider):
"""
A Faker provider for the Austrian VAT IDs
A Faker provider for Austrian Identification Numbers
"""

def ssn(self) -> str:
"""
https://learn.microsoft.com/en-us/microsoft-365/compliance/sit-defn-austria-social-security-number?view=o365-worldwide
10 digits:
- three digits that correspond to a serial number
- one check digit
- six digits that correspond to the birth month (DDMMYY)
:return: a random Austrian SSN
"""


age = datetime.timedelta(days=self.generator.random.randrange(0, 100))
birthday = datetime.date.today() - age
birthdate = "%02d%02d%s" % (
birthday.day,
birthday.month,
str(birthday.year)[-2:],
)

serial = self.bothify("###")
check = str(calculate_luhn(float(serial + birthdate)))

ssn = serial + check + birthdate

return ssn

tin_formats = ("##-###/####",)

def tin(self) -> str:
"""
https://learn.microsoft.com/en-us/microsoft-365/compliance/sit-defn-austria-tax-identification-number?view=o365-worldwide
:return: a random Austrian TIN
"""

return self.bothify(self.random_element(self.tin_formats))

vat_id_formats = ("ATU########",)

def vat_id(self) -> str:
Expand Down
17 changes: 15 additions & 2 deletions faker/providers/ssn/de_DE/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
from .. import Provider as BaseProvider

from faker.utils.checksums import calculate_luhn

class Provider(BaseProvider):
"""
A Faker provider for the German VAT IDs
A Faker provider for German Identification Numbers
"""

tin_formats = ("##########",)

def tin(self) -> str:
"""
https://learn.microsoft.com/en-us/microsoft-365/compliance/sit-defn-germany-tax-identification-number?view=o365-worldwide
:return: A random German TIN
"""
id = self.bothify(self.random_element(self.tin_formats))
check = str(calculate_luhn(int(id)))

return id + check


vat_id_formats = ("DE#########",)

def vat_id(self) -> str:
Expand Down
3 changes: 3 additions & 0 deletions faker/providers/ssn/ru_RU/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@


class Provider(SsnProvider):
"""
A Faker provider for the Russian SSN
"""
ssn_formats = ("############",)
16 changes: 14 additions & 2 deletions faker/providers/ssn/sl_SI/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
from .. import Provider as BaseProvider

from faker.utils.checksums import calculate_luhn

class Provider(BaseProvider):
"""
A Faker provider for the Slovenian VAT IDs
A Faker provider for the Slovenian Identification Numbers
"""

tin_formats = ("%######",)

def tin(self) -> str:
"""
https://learn.microsoft.com/en-us/microsoft-365/compliance/sit-defn-slovenia-tax-identification-number?view=o365-worldwide
:return: a random Slovenian TIN
"""
tin = self.bothify(self.random_element(self.tin_formats))

return tin + str(calculate_luhn(float(tin)))


vat_id_formats = ("SI########",)

def vat_id(self) -> str:
Expand Down
20 changes: 20 additions & 0 deletions tests/providers/test_ssn.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,32 @@ def test_birth_number(self):
assert birth_number[6] == "/"
assert int(birth_number.replace("/", "")) % 11 == 0

class TestDeDE(unittest.TestCase):
def setUp(self):
self.fake = Faker("de_DE")
Faker.seed(0)

def test_tin(self):
for _ in range(100):
assert re.search(r'^\d{11}$', self.fake.tin())

def test_vat_id(self):
for _ in range(100):
assert re.search(r"^DE\d{9}$", self.fake.vat_id())

class TestDeAT(unittest.TestCase):
def setUp(self):
self.fake = Faker("de_AT")
Faker.seed(0)

def test_ssn(self):
for _ in range(100):
assert re.search(r"^\d{4}(0[1-9]|[1-2][0-9]|3[0-1])(0[1-9]|1[0-2])\d{2}$", self.fake.ssn())

def test_tin(self):
for _ in range(100):
assert re.search(r'^\d{2}-\d{3}/\d{4}$', self.fake.tin())

def test_vat_id(self):
for _ in range(100):
assert re.search(r"^ATU\d{8}$", self.fake.vat_id())
Expand Down