diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-15 21:01:31 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-15 21:01:31 +0100 |
commit | eeaddb27560d723ca7d61359744ceb2709fccd2d (patch) | |
tree | 04ddbc49ae7b73d5f5a9e1716d7227aecd3b9f85 /alphabetlearning/users/tests/factories.py | |
parent | 7a3044c859043837e6c7c95bb4894d04e9b2cbc2 (diff) |
Renamed from pyblackbird_cc to alphabetlearning - everywhere
Diffstat (limited to 'alphabetlearning/users/tests/factories.py')
-rw-r--r-- | alphabetlearning/users/tests/factories.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/alphabetlearning/users/tests/factories.py b/alphabetlearning/users/tests/factories.py new file mode 100644 index 0000000..c0e94a3 --- /dev/null +++ b/alphabetlearning/users/tests/factories.py @@ -0,0 +1,40 @@ +from collections.abc import Sequence +from typing import Any + +from factory import Faker +from factory import post_generation +from factory.django import DjangoModelFactory + +from alphabetlearning.users.models import User + + +class UserFactory(DjangoModelFactory): + email = Faker("email") + name = Faker("name") + + @post_generation + def password(self, create: bool, extracted: Sequence[Any], **kwargs): # noqa: FBT001 + password = ( + extracted + if extracted + else Faker( + "password", + length=42, + special_chars=True, + digits=True, + upper_case=True, + lower_case=True, + ).evaluate(None, None, extra={"locale": None}) + ) + self.set_password(password) + + @classmethod + def _after_postgeneration(cls, instance, create, results=None): + """Save again the instance if creating and at least one hook ran.""" + if create and results and not cls._meta.skip_postgeneration_save: + # Some post-generation hooks ran, and may have modified us. + instance.save() + + class Meta: + model = User + django_get_or_create = ["email"] |