-
Notifications
You must be signed in to change notification settings - Fork 153
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
Fixed some factory issues to address Percy's false positive flags #11771
base: main
Are you sure you want to change the base?
Changes from 8 commits
5cd4015
6b53875
dac1db5
6323908
d6fc39e
e156704
54e1212
c5cf7b9
df4517d
245ac11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from datetime import timezone | ||
from datetime import datetime, timezone | ||
|
||
from factory import Faker, LazyAttribute, Trait, post_generation | ||
from factory import Faker, LazyAttribute, post_generation | ||
from factory.django import DjangoModelFactory | ||
from wagtail_factories import ImageFactory | ||
|
||
|
@@ -18,17 +18,12 @@ class Meta: | |
"footer_sentence", | ||
) | ||
|
||
class Params: | ||
unpublished = Trait(publish_after=Faker("future_datetime", end_date="+30d", tzinfo=timezone.utc)) | ||
has_expiry = Trait(expires=Faker("future_datetime", end_date="+30d", tzinfo=timezone.utc)) | ||
expired = Trait(expires=Faker("past_datetime", start_date="-30d", tzinfo=timezone.utc)) | ||
|
||
title = LazyAttribute(lambda o: o.title_sentence.rstrip(".")) | ||
description = Faker("paragraph", nb_sentences=5, variable_nb_sentences=True) | ||
link_label = LazyAttribute(lambda o: " ".join(o.link_label_words)) | ||
footer = LazyAttribute(lambda o: o.footer_sentence.rstrip(".")) | ||
link_url = Faker("uri") | ||
publish_after = Faker("past_datetime", start_date="-30d", tzinfo=timezone.utc) | ||
publish_after = Faker("past_datetime", start_date=datetime(2020, 1, 1), tzinfo=timezone.utc) | ||
expires = None | ||
Comment on lines
-31
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how this would solve the problem though... 🤔 we would still get a random date but now between Jan 1st 2020 and the current date instead of the last 30 days. We might need a different approach |
||
order = 0 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from datetime import timezone | ||
from datetime import datetime, timezone | ||
from random import shuffle | ||
|
||
from django.conf import settings | ||
|
@@ -32,34 +32,15 @@ class Meta: | |
exclude = ("headline_sentence",) | ||
|
||
class Params: | ||
unpublished = Trait( | ||
publish_after=Faker("date_time", tzinfo=timezone.utc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, these details seem a bit unnecessary to me. I'm deleting them to avoid complication. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to keep these as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will add them back! |
||
if RANDOM_SEED and not TESTING | ||
else Faker("future_datetime", end_date="+30d", tzinfo=timezone.utc) | ||
) | ||
has_expiry = Trait( | ||
expires=Faker("date_time", tzinfo=timezone.utc) | ||
if RANDOM_SEED and not TESTING | ||
else Faker("future_datetime", end_date="+30d", tzinfo=timezone.utc) | ||
) | ||
expired = Trait( | ||
expires=Faker("date_time", tzinfo=timezone.utc) | ||
if RANDOM_SEED and not TESTING | ||
else Faker("past_datetime", start_date="-30d", tzinfo=timezone.utc) | ||
) | ||
video = Trait(is_video=True) | ||
|
||
headline = LazyAttribute(lambda o: o.headline_sentence.rstrip(".")) | ||
outlet = Faker("company") | ||
date = Faker("date") if RANDOM_SEED and not TESTING else Faker("past_date", start_date="-30d") | ||
date = Faker("past_date", start_date=datetime(2020, 1, 1), tzinfo=timezone.utc) | ||
link = Faker("url") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure why we needed to have two ways to generate values for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure... it seems to be generating a random date in the past 30 days for testing while for all other generations it uses a random date with no restrictions |
||
excerpt = Faker("paragraph", nb_sentences=3, variable_nb_sentences=True) | ||
author = Faker("name") | ||
publish_after = ( | ||
Faker("date_time", tzinfo=timezone.utc) | ||
if RANDOM_SEED and not TESTING | ||
else Faker("past_datetime", start_date="-30d", tzinfo=timezone.utc) | ||
) | ||
publish_after = Faker("past_datetime", start_date=datetime(2020, 1, 1), tzinfo=timezone.utc) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here. I'm curious why RANDOM_SEED and TESTING matter when it comes to generating value for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure either. I think we're safe to simplify this if the Python tests pass. |
||
# LazyAttribute helper value | ||
headline_sentence = Faker("sentence", nb_words=4) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from datetime import timezone | ||
from datetime import datetime, timezone | ||
from random import choice | ||
|
||
from django.conf import settings | ||
|
@@ -88,11 +88,7 @@ class Meta: | |
|
||
title = LazyAttribute(lambda o: o.title_text.rstrip(".")) | ||
body = Faker("streamfield", fields=blog_body_streamfield_fields) | ||
first_published_at = ( | ||
Faker("date_time", tzinfo=timezone.utc) | ||
if RANDOM_SEED and not TESTING | ||
else Faker("past_datetime", start_date="-30d", tzinfo=timezone.utc) | ||
) | ||
first_published_at = Faker("past_datetime", start_date=datetime(2020, 1, 1), tzinfo=timezone.utc) | ||
search_description = Faker("paragraph", nb_sentences=5, variable_nb_sentences=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same q as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
live = True | ||
|
||
|
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.
These details seem a bit unnecessary to me. I'm deleting them to avoid complication.
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.
These are helpful if creating these in a test. Instead of doing something like
HighlightFactory(publish_after=timedelta(datetime.now() + 1))
to indicate an unpublished highlight, we can just doHighlightFactory(unpublished=True)
and it will create it for us with apublish_after
in the future.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.
I don't think it's worth deleting them, they are helpful factory traits
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.
Cool I'll add them back!