Skip to content
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

Feature: Add factory for AppInstallPage #12581

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions network-api/networkapi/utility/faker/streamfield_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,18 @@ def generate_mixed_content_field():
)


def generate_app_install_download_button_field():
return generate_field(
"button",
{
"link_to": "external_url",
"external_url": fake.url(schemes=["https"]),
"label": " ".join(fake.words(nb=2)),
"new_window": True,
},
)


class StreamfieldProvider(BaseProvider):
"""
A custom Faker Provider for relative image urls, for use with factory_boy
Expand Down Expand Up @@ -734,6 +746,7 @@ def streamfield(self, fields=None):
"profiles": generate_profiles_field,
"newsletter_signup": generate_newsletter_signup_with_background_field,
"mixed_content": generate_mixed_content_field,
"app_install_download_button": generate_app_install_download_button_field,
}

streamfield_data = []
Expand Down
2 changes: 2 additions & 0 deletions network-api/networkapi/wagtailpages/factory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from networkapi.wagtailpages.factory.libraries import rcc, research_hub

from . import (
app_install_page,
bannered_campaign_page,
blog,
buyersguide,
Expand Down Expand Up @@ -50,6 +51,7 @@ def generate(seed):
rcc.generate(seed)
# homepage_cause_statement_link requires child pages of homepage to exist
homepage_cause_statement_link.generate(seed)
app_install_page.generate(seed)


__all__ = [
Expand Down
39 changes: 39 additions & 0 deletions network-api/networkapi/wagtailpages/factory/app_install_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from factory import Faker, SubFactory
from wagtail_factories import PageFactory

from networkapi.utility.faker.helpers import reseed
from networkapi.wagtailpages import models as pagemodels
from networkapi.wagtailpages.factory import image_factory
from networkapi.wagtailpages.models import AppInstallPage

from .petition import PetitionFactory


class AppInstallPageFactory(PageFactory):
class Meta:
model = AppInstallPage
exclude = (
"title_text",
"header_text",
"header",
)

title = "Regrets Reporter Page"
slug = "regretsreporter"
hero_heading = Faker("text", max_nb_chars=50)
hero_subheading = Faker("text", max_nb_chars=50)
hero_background = SubFactory(image_factory.ImageFactory)
download_buttons = Faker("streamfield", fields=["app_install_download_button"] * 2)
cta = SubFactory(PetitionFactory)
body = Faker("streamfield", fields=["header", "paragraph", "image", "spacer", "image_text", "quote"])


def generate(seed):
reseed(seed)

print("Generating PNI Homepage")
AppInstallPageFactory.create(
parent=pagemodels.Homepage.objects.first(),
title="App Install Page",
slug="app-install-page",
)
Loading