示例#1
0
    def test_models_course_get_main_organization(self):
        """
        The `get_main_organization` method should return the first organization linked to a
        course via plugins, respecting publication status.
        """
        # The 2 first organizations 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 organizations linked to the course are retrieved (its name starts with `_`
        # because it is not used and only here for unpacking purposes)
        *draft_organizations, _other_draft = OrganizationFactory.create_batch(
            3)
        *published_organizations, _other_public = OrganizationFactory.create_batch(
            3, should_publish=True)

        # Shuffle all organizations to make sure their order in the placeholder is what
        # determines which one is the main organization
        all_organizations = draft_organizations + published_organizations
        random.shuffle(all_organizations)

        course = CourseFactory(fill_organizations=all_organizations,
                               should_publish=True)

        self.assertEqual(course.get_main_organization(), all_organizations[0])
        self.assertEqual(
            course.public_extension.get_main_organization(),
            # Find the first published organization in this list of organizations
            next(o for o in all_organizations if o in published_organizations),
        )
示例#2
0
 def test_models_course_get_main_organization_empty(self):
     """
     For a course not linked to any organzation the method `get_main_organization` should
     return `None`.
     """
     course = CourseFactory(should_publish=True)
     self.assertIsNone(course.get_main_organization())
     self.assertIsNone(course.public_extension.get_main_organization())
示例#3
0
    def test_models_course_get_main_organization(self):
        """
        The `get_main_organization` method should return the first organization linked to a
        course via plugins, respecting publication status.
        """
        # The 2 first organizations 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 organizations linked to the course are retrieved (its name starts with `_`
        # because it is not used and only here for unpacking purposes)
        *draft_organizations, _other_draft = OrganizationFactory.create_batch(
            3)
        *published_organizations, _other_public = OrganizationFactory.create_batch(
            3, should_publish=True)
        course = CourseFactory(
            fill_organizations=draft_organizations + published_organizations,
            should_publish=True,
        )

        self.assertEqual(course.get_main_organization(),
                         draft_organizations[0])
        self.assertEqual(course.public_extension.get_main_organization(),
                         published_organizations[0])