From 49d5f6755d23a8bbd095f217218d78c3d7656062 Mon Sep 17 00:00:00 2001 From: Thibault Jouannic Date: Tue, 22 Aug 2023 11:05:20 +0200 Subject: [PATCH] Get rid of a factory-boy deprecation warning See: - https://github.com/FactoryBoy/factory_boy/issues/316 - https://github.com/FactoryBoy/factory_boy/issues/366 --- envergo/evaluations/tests/factories.py | 2 ++ envergo/users/tests/factories.py | 24 +++--------------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/envergo/evaluations/tests/factories.py b/envergo/evaluations/tests/factories.py index 59f4afc40..3a7b6a9c6 100644 --- a/envergo/evaluations/tests/factories.py +++ b/envergo/evaluations/tests/factories.py @@ -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") @@ -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") diff --git a/envergo/users/tests/factories.py b/envergo/users/tests/factories.py index cc6b5e227..e025efa46 100644 --- a/envergo/users/tests/factories.py +++ b/envergo/users/tests/factories.py @@ -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()