Skip to content

Commit

Permalink
Get rid of a factory-boy deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault committed Aug 24, 2023
1 parent fafd396 commit 49d5f67
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
2 changes: 2 additions & 0 deletions envergo/evaluations/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class EvaluationFactory(DjangoModelFactory):
class Meta:
model = Evaluation
skip_postgeneration_save = True

application_number = factory.Sequence(lambda n: f"PC05112321D{n:04}")
evaluation_file = factory.django.FileField(filename="eval.pdf", data=b"Hello")
Expand Down Expand Up @@ -48,6 +49,7 @@ class Meta:
class RequestFactory(DjangoModelFactory):
class Meta:
model = Request
skip_postgeneration_save = True

reference = factory.Sequence(lambda n: f"ABC{n:03}")
address = factory.Sequence(lambda n: f"{n} rue de l'example, Testville")
Expand Down
24 changes: 3 additions & 21 deletions envergo/users/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
from typing import Any, Sequence

from django.contrib.auth import get_user_model
from factory import Faker, post_generation
from factory.django import DjangoModelFactory
from factory import Faker
from factory.django import DjangoModelFactory, Password


class UserFactory(DjangoModelFactory):

email = Faker("email")
name = Faker("name")

@post_generation
def password(self, create: bool, extracted: Sequence[Any], **kwargs):
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)
password = Password("password")

class Meta:
model = get_user_model()
Expand Down

0 comments on commit 49d5f67

Please sign in to comment.