示例#1
0
    def test_models_course_get_persons_language(self):
        """
        The `get_persons` method should only return persons linked to a course by a plugin
        in the current language.
        """
        person_fr = PersonFactory(page_languages=["fr"])
        person_en = PersonFactory(page_languages=["en"])

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

        add_plugin(
            language="en",
            placeholder=placeholder,
            plugin_type="PersonPlugin",
            page=person_en.extended_object,
        )
        add_plugin(
            language="fr",
            placeholder=placeholder,
            plugin_type="PersonPlugin",
            page=person_fr.extended_object,
        )

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

        with translation.override("en"):
            self.assertEqual(list(course.get_persons()), [person_en])
示例#2
0
    def test_models_course_get_persons_other_placeholders(self):
        """
        The `get_persons` method should return all persons linked to a course via a plugin
        on whichever placeholder.
        """
        person1, person2 = PersonFactory.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="PersonPlugin",
            page=person1.extended_object,
        )
        add_plugin(
            language="en",
            placeholder=placeholder2,
            plugin_type="PersonPlugin",
            page=person2.extended_object,
        )

        self.assertEqual(list(course.get_persons()), [person1, person2])
示例#3
0
 def test_models_course_get_persons_empty(self):
     """
     For a course not linked to any person the method `get_persons` should
     return an empty query.
     """
     course = CourseFactory(should_publish=True)
     self.assertFalse(course.get_persons().exists())
     self.assertFalse(course.public_extension.get_persons().exists())
示例#4
0
    def test_models_course_get_persons(self):
        """
        The `get_persons` method should return all persons linked to a course and
        should respect publication status.
        """
        # The 2 first persons are grouped in one variable name and will be linked to the
        # course in the following, the third person will not be linked so we can check that
        # only the persons linked to the course are retrieved (its name starts with `_`
        # because it is not used and only here for unpacking purposes)
        *draft_persons, _other_draft = PersonFactory.create_batch(3)
        *published_persons, _other_public = PersonFactory.create_batch(
            3, should_publish=True)
        course = CourseFactory(fill_team=draft_persons + published_persons,
                               should_publish=True)

        self.assertEqual(list(course.get_persons()),
                         draft_persons + published_persons)
        self.assertEqual(list(course.public_extension.get_persons()),
                         published_persons)