-
-
Save brunomichetti/247f8da69ffd805589a84a4fd0b3b00a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# factory.py inside users/test | |
from faker import Faker as FakerClass | |
from typing import Any, Sequence | |
from factory import django, Faker, post_generation | |
from users.models import User, Category | |
CATEGORIES_VALUES = [x[0] for x in Category.choices] | |
class UserFactory(django.DjangoModelFactory): | |
class Meta: | |
model = User | |
username = Faker('user_name') | |
phone_number = Faker('phone_number') | |
category = Faker('random_element', elements=CATEGORIES_VALUES) | |
@post_generation | |
def password(self, create: bool, extracted: Sequence[Any], **kwargs): | |
password = ( | |
extracted | |
if extracted | |
else FakerClass().password( | |
length=30, | |
special_chars=True, | |
digits=True, | |
upper_case=True, | |
lower_case=True, | |
) | |
) | |
self.set_password(password) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment