How to use the richie.apps.core.helpers.create_i18n_page 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 / apps / core / test_helpers.py View on Github external
def test_helpers_create_i18n_page_from_languages_invalid(
        self, mock_page, mock_title
    ):
        """
        Trying to create a multilingual page for languages that don't exist should fail.
        """
        with self.assertRaises(ValueError) as context:
            create_i18n_page("my title", languages=["en", "de"])

        self.assertEqual(
            str(context.exception),
            ("You can't create pages in languages that are not declared: de"),
        )
        self.assertFalse(mock_page.called)
        self.assertFalse(mock_title.called)
github openfun / richie / tests / apps / courses / test_cms_plugins_course.py View on Github external
def test_cms_plugins_course_form_page_choices(self):
        """
        The form to create a course plugin should only list course pages
        in the select box and no snapshot. There shouldn't be any duplicate because
        of published status.
        """

        class CoursePluginModelForm(forms.ModelForm):
            """A form for testing the choices in the select box"""

            class Meta:
                model = CoursePluginModel
                fields = ["page"]

        page = create_i18n_page("A page")
        page.publish("en")
        course = CourseFactory(page_parent=page, should_publish=True)
        other_page_title = "other page"
        create_page(
            other_page_title, "richie/single_column.html", settings.LANGUAGE_CODE
        )
        plugin_form = CoursePluginModelForm()
        rendered_form = plugin_form.as_table()
        self.assertEqual(rendered_form.count(course.extended_object.get_title()), 1)
        self.assertNotIn(other_page_title, plugin_form.as_table())

        # Create a fake course snapshot and make sure it's not available to select
        snapshot = CourseFactory(
            page_parent=course.extended_object, should_publish=True
        )
        self.assertNotIn(snapshot.extended_object.get_title(), plugin_form.as_table())
github openfun / richie / tests / apps / courses / test_templates_category_detail.py View on Github external
def test_templates_category_detail_cms_published_content_max_courses(
        self, _mock_page_url
    ):
        """
        Make sure the category detail page does not display too many courses, even when a large
        number are related to the current category, as this can cause the page to load very slowly
        and is not a great experience for the user anyway.
        """
        # Create our dummy category and the 3 courses we'll attach to it
        meta = CategoryFactory(
            page_parent=create_i18n_page(
                {"en": "Categories", "fr": "Catégories"}, published=True
            ),
            page_reverse_id="subjects",
            page_title={"en": "Subjects", "fr": "Sujets"},
            should_publish=True,
        )
        category = CategoryFactory(
            page_parent=meta.extended_object, should_publish=True
        )
        courses = CourseFactory.create_batch(
            3, fill_categories=[category], should_publish=True
        )
        # Link the 3 courses with our category through the relevant placeholder
        for course in courses:
            add_plugin(
                course.extended_object.placeholders.get(slot="course_categories"),
github openfun / richie / tests / apps / courses / test_cms_plugins_program.py View on Github external
def test_cms_plugins_program_render_on_draft_page(self):
        """
        The program plugin should render as expected on a draft page.
        """
        staff = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=staff.username, password="password")

        # Create a Program
        program = ProgramFactory(page_title="public title")
        program_page = program.extended_object

        # Create a page to add the plugin to
        page = create_i18n_page("A page")
        placeholder = page.placeholders.get(slot="maincontent")
        add_plugin(placeholder, ProgramPlugin, "en", **{"page": program_page})

        program_page.publish("en")
        program_page.unpublish("en")
        program_page.refresh_from_db()

        url = "{:s}?edit".format(page.get_absolute_url(language="en"))

        # The program plugin should still be visible on the draft page
        response = self.client.get(url)
        self.assertContains(response, "public title")

        # Now modify the program to have a draft different from the public version
        title_obj = program_page.get_title_obj(language="en")
        title_obj.title = "draft title"
github openfun / richie / tests / apps / courses / test_cms_plugins_blogpost.py View on Github external
def test_cms_plugins_blogpost_render_template(self):
        """
        The blogpost plugin should render according to variant choice.
        """
        staff = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=staff.username, password="password")

        # Create an blogpost
        blogpost = BlogPostFactory(page_title="public title")
        blogpost_page = blogpost.extended_object

        # Create a page to add the plugin to
        page = create_i18n_page("A page")
        placeholder = page.placeholders.get(slot="maincontent")

        # Add blogpost plugin with default template
        add_plugin(placeholder, BlogPostPlugin, "en", page=blogpost_page)

        url = "{:s}?edit".format(page.get_absolute_url(language="en"))

        # The blogpost-glimpse default variant should be glimpse
        response = self.client.get(url)
        self.assertContains(response, "blogpost-glimpse")

        # Add blogpost plugin with small variant
        add_plugin(
            placeholder, BlogPostPlugin, "en", page=blogpost_page, variant="small",
        )
github openfun / richie / tests / apps / core / test_helpers.py View on Github external
def test_helpers_create_i18n_page_from_invalid_title(self, mock_page, mock_title):
        """
        Trying to create a multilingual page from an invalid title format should fail.
        to differentiate each language
        """
        for title in [["a"], {"a"}, 3]:
            with self.assertRaises(ValueError):
                create_i18n_page(title)

        self.assertFalse(mock_page.called)
        self.assertFalse(mock_title.called)
github openfun / richie / tests / apps / search / test_indexers_categories.py View on Github external
def test_indexers_categories_get_es_documents(self, _mock_picture):
        """
        Happy path: the data is fetched from the models properly formatted
        """
        # Our meta category and its page
        meta = CategoryFactory(
            page_parent=create_i18n_page(
                {"en": "Categories", "fr": "Catégories"}, published=True
            ),
            page_reverse_id="subjects",
            page_title={"en": "Subjects", "fr": "Sujets"},
            fill_icon=True,
            fill_logo=True,
            should_publish=True,
        )
        category1 = CategoryFactory(
            page_parent=meta.extended_object,
            page_title={"en": "my first subject", "fr": "ma première thématique"},
            fill_icon=True,
            fill_logo=True,
            should_publish=True,
        )
        CategoryFactory(
github openfun / richie / tests / apps / core / test_helpers.py View on Github external
def test_helpers_recursive_page_creation_existing_homepage(self):
        """
        Check that `recursive_page_creation` respects an existing home page
        """
        homepage = create_i18n_page("my title", is_homepage=True)
        self.assertTrue(homepage.is_home)
        self.assertEqual(Page.objects.count(), 1)

        site = Site.objects.get(id=1)
        pages_info = {
            "home": {
                "title": "Home",
                "in_navigation": False,
                "is_homepage": True,
                "template": "richie/homepage.html",
            }
        }
        pages = recursive_page_creation(site=site, pages_info=pages_info)

        self.assertEqual(pages["home"], homepage)
github openfun / richie / tests / apps / courses / test_cms_plugins_blogpost.py View on Github external
def test_cms_plugins_blogpost_form_page_choices(self):
        """
        The form to create a blogpost plugin should only list blogpost pages
        in the select box.
        """

        class BlogPostPluginModelForm(forms.ModelForm):
            """A form for testing the choices in the select box"""

            class Meta:
                model = BlogPostPluginModel
                fields = ["page"]

        blog_page = create_i18n_page("my title", published=True)
        blogpost = BlogPostFactory(page_parent=blog_page)
        other_page_title = "other page"
        create_page(
            other_page_title, "richie/single_column.html", settings.LANGUAGE_CODE
        )
        plugin_form = BlogPostPluginModelForm()
        rendered_form = plugin_form.as_table()
        self.assertEqual(rendered_form.count(blogpost.extended_object.get_title()), 1)
        self.assertNotIn(other_page_title, plugin_form.as_table())
github openfun / richie / tests / apps / courses / test_cms_plugins_organization.py View on Github external
def test_cms_plugins_organization_render_instance_variant(self):
        """
        The organization plugin should render according to the variant plugin
        option.
        """
        staff = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=staff.username, password="password")

        # Create an Organization
        organization = OrganizationFactory(page_title="public title")
        organization_page = organization.extended_object

        # Create a page to add the plugin to
        page = create_i18n_page("A page")
        placeholder = page.placeholders.get(slot="maincontent")

        # Add organization plugin with default variant
        add_plugin(placeholder, OrganizationPlugin, "en", page=organization_page)

        url = "{:s}?edit".format(page.get_absolute_url(language="en"))

        # The organization-glimpse default variant should not have the small attribute
        response = self.client.get(url)
        self.assertNotContains(response, "--small")

        # Add organization plugin with small variant
        add_plugin(
            placeholder,
            OrganizationPlugin,
            "en",