-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retirer les CommuneFactory et CountryFactory #5591
Conversation
371a2f6
to
1617c90
Compare
# Job seeker born outside of France | ||
country = CountryOutsideEuropeFactory() | ||
country = Country.objects.order_by("?").exclude(group=Country.Group.FRANCE).first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Est-ce qu'il ne faudrait pas directement fournir un Trait
born_outside_of_france
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
born_in_france=False
avec un Maybe
? Me semble que ça devrais fonctionner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deal !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je ne suis pas trop fan de lui donner forcément un pays de naissance, si c’est bien ta suggestion. Je suis parti sur la solution de Xavier : born_in_france
, born_outside_france
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ce que j'avais en tête :
born_in_france = factory.Maybe('born_in_france', yes_declaration=factory.Trait(
jobseeker_profile__birth_place=factory.LazyAttribute(
lambda instance: Commune.objects.order_by("?")
.filter(
start_date__lte=instance.birthdate,
end_date__gte=instance.birthdate,
)
.first(),
),
jobseeker_profile__birth_country=factory.LazyAttribute(lambda _: Country.objects.get(name="FRANCE")),
), no_declaration=factory.Trait(
jobseeker_profile__birth_country=factory.LazyAttribute(
lambda _: Country.objects.order_by("?").exclude(group=Country.Group.FRANCE).first()
),
))
Mais ça ne fonctionne pas :(, a priori faut faire ça :
born_in_france = factory.Trait(
jobseeker_profile__birth_place=factory.Maybe(
"born_in_france",
factory.LazyAttribute(
lambda instance: Commune.objects.order_by("?")
.filter(
start_date__lte=instance.birthdate,
end_date__gte=instance.birthdate,
)
.first(),
),
),
jobseeker_profile__birth_country=factory.Maybe(
factory.LazyAttribute(lambda _: Country.objects.get(name="FRANCE")),
factory.LazyAttribute(
lambda _: Country.objects.order_by("?").exclude(group=Country.Group.FRANCE).first()
),
),
)
Mais c'est vraiment pas ouf :´(.
tests/users/test_models.py
Outdated
|
||
# Europe and Commune filled | ||
profile.birth_country = asp.CountryEuropeFactory() | ||
profile.birth_country = not_france |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Techniquement cette ligne n'est pas utile, mais si tu veux la garder pour être plus explicite alors je la mettrais après .birth_place = asp.CommuneFactory()
pour avoir le même schéma dans les deux blocs et/ou un petit commentaire pour délimiter le cas testé.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elle a été retirée, c’est du state invalide (un pays de naissance hors de France et une commune).
# Job seeker born outside of France | ||
country = CountryOutsideEuropeFactory() | ||
country = Country.objects.order_by("?").exclude(group=Country.Group.FRANCE).first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
born_in_france=False
avec un Maybe
? Me semble que ça devrais fonctionner
1617c90
to
e4b178a
Compare
bob.jobseeker_profile.save() | ||
dylan.jobseeker_profile.birth_place = CommuneFactory() | ||
dylan.jobseeker_profile.birth_country = CountryFactory() | ||
dylan.jobseeker_profile.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'aime !
@@ -172,7 +167,12 @@ class Params: | |||
) | |||
.first(), | |||
), | |||
jobseeker_profile__birth_country=factory.LazyAttribute(country_france), | |||
jobseeker_profile__birth_country=factory.LazyAttribute(lambda _: Country.objects.get(name="FRANCE")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi ne pas avoir gardé le cache ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parce que je pense qu’il ne sert pas beaucoup (pas d’impact notable sur la durée des tests) et #5591 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤩
# Job seeker born outside of France | ||
country = CountryOutsideEuropeFactory() | ||
country = Country.objects.order_by("?").exclude(group=Country.Group.FRANCE).first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ce que j'avais en tête :
born_in_france = factory.Maybe('born_in_france', yes_declaration=factory.Trait(
jobseeker_profile__birth_place=factory.LazyAttribute(
lambda instance: Commune.objects.order_by("?")
.filter(
start_date__lte=instance.birthdate,
end_date__gte=instance.birthdate,
)
.first(),
),
jobseeker_profile__birth_country=factory.LazyAttribute(lambda _: Country.objects.get(name="FRANCE")),
), no_declaration=factory.Trait(
jobseeker_profile__birth_country=factory.LazyAttribute(
lambda _: Country.objects.order_by("?").exclude(group=Country.Group.FRANCE).first()
),
))
Mais ça ne fonctionne pas :(, a priori faut faire ça :
born_in_france = factory.Trait(
jobseeker_profile__birth_place=factory.Maybe(
"born_in_france",
factory.LazyAttribute(
lambda instance: Commune.objects.order_by("?")
.filter(
start_date__lte=instance.birthdate,
end_date__gte=instance.birthdate,
)
.first(),
),
),
jobseeker_profile__birth_country=factory.Maybe(
factory.LazyAttribute(lambda _: Country.objects.get(name="FRANCE")),
factory.LazyAttribute(
lambda _: Country.objects.order_by("?").exclude(group=Country.Group.FRANCE).first()
),
),
)
Mais c'est vraiment pas ouf :´(.
post_data = { | ||
"email": "[email protected]", | ||
"title": "M", | ||
"first_name": "Bob", | ||
"last_name": "Saint Clar", | ||
"birthdate": birthdate.isoformat(), | ||
"birth_country": birth_country.pk, | ||
"birth_country": user.jobseeker_profile.birth_country_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu pourrais le laisser inchangé non ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En effet. Initialement, je pensais dégager complètement la variable birth_country
, mais elle est utilisée dans le dernier assert du test pour vérifier que le pays de naissance est toujours le même pays.
Je ne suis pas convaincu de la pertinence de cet assert, mais c’est pas le but de cette PR ;)
The JobSeekerFactory and JobSeekerProfileFactory are in use in the application at large. The note about the fixtures is now documented with conftest.py (always load the fixture, for the whole session), so the developer shouldn’t have to worry about it anymore.
The object just got created by the factory, no need to load it from the database.
e4b178a
to
3eaa555
Compare
Ensure the birth_place start_date and end_date attribute are around the birthdate, so that data is realistic. Updated the factory to use actual objects from the ASP and not a fakes, as the application doesn’t manage Commune and Country objects. Remove the with_birth_place trait, as it would setup an incomplete object (birth country isn’t France). It was only used once and was merged into the born_in_france trait.
Use the ASP reference instead to be more realistic, as the application does not create Country objects. Removed tests for impossible or unused scenario: - european country vs world country, as it makes no difference to the application. - filling commune and selecting a world country, that’s invalid state
Use the ASP reference instead to be more realistic, as the application does not create Commune objects.
3eaa555
to
6e58145
Compare
🤔 Pourquoi ?
Être plus proche de la réalité, où nous utilisons le référentiel ASP sans créer ces objets.
Notamment, lors de la création d’un candidat, sa commune de naissance devrait être valide le jour de sa naissance. Au lieu d’apprendre aux factories comment créer ces communes, recherchons une commune existante.