-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdevdata.py
More file actions
91 lines (76 loc) · 2.52 KB
/
devdata.py
File metadata and controls
91 lines (76 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import random
from datetime import timezone
from faker import Faker
import factory
import wagtail_factories
from blog.models import BlogAuthor, BlogPage, BlogIndexPage
from common.tests.factories import OrganizationPageFactory
from common.tests.utils import StreamfieldProvider
from menus.factories import MainMenuItemFactory
fake = Faker()
factory.Faker.add_provider(StreamfieldProvider)
class BlogIndexPageFactory(wagtail_factories.PageFactory):
class Meta:
model = BlogIndexPage
title = "PFT Blog"
about_blog_title = "The blog of the press freedom tracker"
body = factory.Faker("streamfield", fields=["raw_html", "rich_text"])
class Params:
main_menu = factory.Trait(
menu=factory.RelatedFactory(MainMenuItemFactory, "link_page", for_page=True)
)
with_image = factory.Trait(
body=factory.Faker(
"streamfield", fields=["bare_image", "raw_html", "rich_text"]
)
)
class BlogPageFactory(wagtail_factories.PageFactory):
class Meta:
model = BlogPage
teaser_graphic = factory.Faker(
"streamfield",
fields=["bare_image"],
)
body = factory.Faker(
"streamfield",
fields=[
"heading1",
"heading2",
"heading3",
"styled_text_paragraphs",
"raw_html",
"styled_text",
"blockquote",
"styled_text",
"aside",
"list",
"styled_text",
"vertical_bar_chart",
],
)
title = factory.Sequence(
lambda n: fake.text(random.randint(5, 58))[:-1] + " ({})".format(n)
)
teaser_text = factory.Faker(
"paragraph",
nb_sentences=3,
variable_nb_sentences=True,
)
publication_datetime = factory.Faker(
"date_time_this_month", after_now=False, before_now=True, tzinfo=timezone.utc
)
first_published_at = factory.LazyAttribute(lambda o: o.publication_datetime)
organization = factory.SubFactory(OrganizationPageFactory)
@factory.post_generation
def authors(self, create, extracted, **kwargs):
if extracted:
for author in extracted:
BlogAuthorFactory(
parent_page=self,
author=author,
)
class BlogAuthorFactory(factory.django.DjangoModelFactory):
class Meta:
model = BlogAuthor
parent_page = factory.SubFactory(BlogPageFactory)
author = factory.SubFactory(wagtail_factories.PageFactory)