示例#1
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 = CategoryFactory(page_languages=["fr"])
        category_en = CategoryFactory(page_languages=["en"])

        course = 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])
示例#2
0
    def test_models_course_get_categories_other_placeholders(self):
        """
        The `get_categories` method should return all categories linked to a course via a plugin
        on whichever placeholder.
        """
        category1, category2 = CategoryFactory.create_batch(2)

        course = CourseFactory(should_publish=True)
        placeholder1 = course.extended_object.placeholders.get(
            slot="course_description")
        placeholder2 = course.extended_object.placeholders.get(
            slot="course_format")

        add_plugin(
            language="en",
            placeholder=placeholder1,
            plugin_type="CategoryPlugin",
            page=category1.extended_object,
        )
        add_plugin(
            language="en",
            placeholder=placeholder2,
            plugin_type="CategoryPlugin",
            page=category2.extended_object,
        )

        self.assertEqual(list(course.get_categories()), [category1, category2])
示例#3
0
 def test_models_course_get_categories_empty(self):
     """
     For a course not linked to any category the method `get_categories` should
     return an empty query.
     """
     course = CourseFactory(should_publish=True)
     self.assertFalse(course.get_categories().exists())
     self.assertFalse(course.public_extension.get_categories().exists())
示例#4
0
    def test_models_course_get_categories(self):
        """
        The `get_categories` method should return all categories linked to a course and
        should respect publication status.
        """
        # The 2 first categories are grouped in one variable name and will be linked to the
        # course in the following, the third category will not be linked so we can check that
        # only the categories linked to the course are retrieved (its name starts with `_`
        # because it is not used and only here for unpacking purposes)
        *draft_categories, _other_draft = CategoryFactory.create_batch(3)
        *published_categories, _other_public = CategoryFactory.create_batch(
            3, should_publish=True)
        course = CourseFactory(fill_categories=draft_categories +
                               published_categories,
                               should_publish=True)

        self.assertEqual(list(course.get_categories()),
                         draft_categories + published_categories)
        self.assertEqual(list(course.public_extension.get_categories()),
                         published_categories)