How to use the richie.apps.core.factories.PageFactory function in richie

To help you get started, we’ve selected a few richie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openfun / richie / tests / plugins / html_sitemap / test_cms_plugins.py View on Github external
def test_cms_plugins_htmlsitemap_in_navigation(self):
        """Pages excluded from navigation can be excluded from a sitemap page."""
        self.create_page_tree(parent_kwargs={"in_navigation": False})

        page = PageFactory(title__title="Sitemap")
        placeholder = Placeholder.objects.create(slot="maincontent")
        page.placeholders.add(placeholder)

        context = self.get_practical_plugin_context()
        parent_instance = add_plugin(placeholder, HTMLSitemapPlugin, "en")
        add_plugin(
            placeholder,
            plugin_type="HTMLSitemapPagePlugin",
            language="en",
            target=parent_instance,
            in_navigation=True,
        )

        html = context["cms_content_renderer"].render_placeholder(
            placeholder, context=context, language="en"
        )
github openfun / richie / tests / plugins / html_sitemap / test_cms_plugins.py View on Github external
def test_cms_plugins_htmlsitemap_root_page_exclude(self):
        """
        A sitemap page targeted to a root page in "exclude" mode should display the descendants
        of the root page.
        """
        _root, parent_page, _page = self.create_page_tree()

        page = PageFactory(title__title="Sitemap")
        placeholder = Placeholder.objects.create(slot="maincontent")
        page.placeholders.add(placeholder)

        context = self.get_practical_plugin_context()
        parent_instance = add_plugin(placeholder, HTMLSitemapPlugin, "en")
        add_plugin(
            placeholder,
            plugin_type="HTMLSitemapPagePlugin",
            language="en",
            target=parent_instance,
            root_page=parent_page,
            include_root_page=False,
        )

        html = context["cms_content_renderer"].render_placeholder(
            placeholder, context=context, language="en"
github openfun / richie / tests / plugins / html_sitemap / test_cms_plugins.py View on Github external
def create_page_tree(parent_kwargs=None):
        """
        Not a test.
        Create a minimal site structure on which to test the sitemap plugin.
        """
        root = PageFactory(title__title="Root")
        parent = PageFactory(
            title__title="Parent", parent=root, **(parent_kwargs or {})
        )
        page = PageFactory(title__title="Uncle", parent=root)
        PageFactory(title__title="Page", parent=parent)
        PageFactory(title__title="Sibling", parent=parent)
        return root, parent, page
github openfun / richie / tests / apps / courses / test_templates_blogpost_list.py View on Github external
def test_templates_blogpost_list_related_categories(self):
        """
        The top of the page should list all categories related to at least one of the blog
        posts on the blog posts list page.
        """
        page = PageFactory(
            template="courses/cms/blogpost_list.html",
            title__language="en",
            should_publish=True,
        )

        post1, post2 = BlogPostFactory.create_batch(
            2, page_parent=page, should_publish=True
        )

        category1, category2, category12, category_alone = CategoryFactory.create_batch(
            4, should_publish=True
        )

        # Attach categories to post1
        placeholder = post1.extended_object.get_public_object().placeholders.all()[0]
        add_plugin(placeholder, "CategoryPlugin", "en", page=category1.extended_object)
github openfun / richie / tests / apps / core / test_pages.py View on Github external
def test_page_includes_frontend_context(self):
        """
        Create a page and make sure it includes the frontend context as included
        in `base.html`.
        """
        page = PageFactory(should_publish=True, template="richie/single_column.html")
        response = self.client.get(page.get_public_url())
        self.assertContains(response, '"environment": "test_pages"')
        self.assertContains(response, '"release": "9.8.7"')
        self.assertContains(response, '"sentry_dsn": "https://example.com/sentry/dsn"')
github openfun / richie / tests / plugins / html_sitemap / test_cms_plugins.py View on Github external
def test_cms_plugins_htmlsitemap_public_page(self):
        """Unpublished or draft pages should be excluded from a public sitemap page."""
        root = PageFactory(
            title__title="Root", title__language="en", should_publish=True
        )
        parent = PageFactory(
            title__title="Parent",
            parent=root,
            title__language="en",
            should_publish=True,
        )
        PageFactory(
            title__title="Uncle", parent=root, title__language="en", should_publish=True
        )
        PageFactory(
            title__title="Page",
            parent=parent,
            title__language="en",
            should_publish=True,
        )
        PageFactory(
            title__title="Sibling",
github openfun / richie / tests / plugins / html_sitemap / test_cms_plugins.py View on Github external
def create_page_tree(parent_kwargs=None):
        """
        Not a test.
        Create a minimal site structure on which to test the sitemap plugin.
        """
        root = PageFactory(title__title="Root")
        parent = PageFactory(
            title__title="Parent", parent=root, **(parent_kwargs or {})
        )
        page = PageFactory(title__title="Uncle", parent=root)
        PageFactory(title__title="Page", parent=parent)
        PageFactory(title__title="Sibling", parent=parent)
        return root, parent, page
github openfun / richie / tests / plugins / html_sitemap / test_cms_plugins.py View on Github external
def test_cms_plugins_htmlsitemap_root_page_exclude_max_depth(self):
        """
        A site map page targeted to a root page in "exclude" mode can be limited in depth (number
        of nesting levels displayed).
        """
        root_page, _parent, _page = self.create_page_tree()

        page = PageFactory(title__title="Sitemap")
        placeholder = Placeholder.objects.create(slot="maincontent")
        page.placeholders.add(placeholder)

        context = self.get_practical_plugin_context()
        parent_instance = add_plugin(placeholder, HTMLSitemapPlugin, "en")
        add_plugin(
            placeholder,
            plugin_type="HTMLSitemapPagePlugin",
            language="en",
            target=parent_instance,
            root_page=root_page,
            include_root_page=False,
            max_depth=1,
        )

        html = context["cms_content_renderer"].render_placeholder(