refactor: use one single Faker object to generate users

This commit is contained in:
Éloi Rivard 2024-04-16 21:43:34 +02:00
parent fa6949e5c6
commit d811c3473d
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184

View file

@ -9,11 +9,16 @@ from canaille.app.i18n import available_language_codes
def fake_users(nb=1):
locales = list(set(available_language_codes()) & set(AVAILABLE_LOCALES))
fakers = [faker.Faker([locale]) for locale in locales]
faker_obj = faker.Faker(locales)
users = list()
# TODO The day faker supports unique profiles,
# we should use them so the different user values would be coherent
# https://github.com/joke2k/faker/issues/1817
for _ in range(nb):
try:
fake = random.choice(fakers)
locale = random.choice(locales)
fake = faker_obj[locale]
name = fake.unique.name()
user = models.User(
formatted_name=name,