Skip to content

Commit

Permalink
Feature: Add factory for AppInstallPage (#12581)
Browse files Browse the repository at this point in the history
* Feature: Add factory for AppInstallPage

* Feature: Delete Video URL and add buttons for AppInstallPage

* Refactor: Move AppInstallPageFactory to a separate file

* Feature: Move AppInstallPage to it's own slug under homepage

* Refactor: Delete unused imports in youtube_regrets_poage.py
  • Loading branch information
AdalbertoMoz committed Jul 9, 2024
1 parent 52a2fdb commit a9fe180
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
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",
)

0 comments on commit a9fe180

Please sign in to comment.