示例#1
0
    def test_models_course_get_root_to_leaf_category_pages_duplicate(self):
        """
        If the course is linked to several categories, the ancestor categories should not get
        duplicated.
        """
        # Create nested categories
        create_page("Categories", "richie/single_column.html", "en")
        meta_category = factories.CategoryFactory(should_publish=True)
        parent_category = factories.CategoryFactory(
            page_parent=meta_category.extended_object, should_publish=True)
        leaf_category1 = factories.CategoryFactory(
            page_parent=parent_category.extended_object, should_publish=True)
        leaf_category2 = factories.CategoryFactory(
            page_parent=parent_category.extended_object, should_publish=True)

        course = factories.CourseFactory(
            fill_categories=[leaf_category1, leaf_category2],
            should_publish=True)

        expected_pages = [
            parent_category.public_extension.extended_object,
            leaf_category1.public_extension.extended_object,
            leaf_category2.public_extension.extended_object,
        ]
        self.assertEqual(expected_pages,
                         list(course.get_root_to_leaf_category_pages()))
示例#2
0
    def test_models_course_get_categories_language(self):
        """
        The `get_categories` method should only return categories linked to a course by
        a plugin in the current language.
        """
        category_fr = factories.CategoryFactory(page_languages=["fr"])
        category_en = factories.CategoryFactory(page_languages=["en"])

        course = factories.CourseFactory(should_publish=True)
        placeholder = course.extended_object.placeholders.get(
            slot="course_categories")

        add_plugin(
            language="en",
            placeholder=placeholder,
            plugin_type="CategoryPlugin",
            page=category_en.extended_object,
        )
        add_plugin(
            language="fr",
            placeholder=placeholder,
            plugin_type="CategoryPlugin",
            page=category_fr.extended_object,
        )

        with translation.override("fr"):
            self.assertEqual(list(course.get_categories()), [category_fr])

        with translation.override("en"):
            self.assertEqual(list(course.get_categories()), [category_en])
示例#3
0
    def test_models_course_get_root_to_leaf_category_pages_parent(self):
        """
        A course linked to a parent category, in a nested category tree, should be associated
        with all the category's ancestors, but not we the child.
        """
        # Create nested categories
        create_page("Categories", "richie/single_column.html", "en")
        meta_category = factories.CategoryFactory(should_publish=True)
        parent_category = factories.CategoryFactory(
            page_parent=meta_category.extended_object, should_publish=True)
        factories.CategoryFactory(page_parent=parent_category.extended_object,
                                  should_publish=True)

        course = factories.CourseFactory(fill_categories=[parent_category],
                                         should_publish=True)

        expected_pages = [parent_category.public_extension.extended_object]
        self.assertEqual(expected_pages,
                         list(course.get_root_to_leaf_category_pages()))