def test_models_course_get_organizations_language(self): """ The `get_organizations` method should only return organizations linked to a course by a plugin in the current language. """ organization_fr = OrganizationFactory(page_languages=["fr"]) organization_en = OrganizationFactory(page_languages=["en"]) course = CourseFactory(should_publish=True) placeholder = course.extended_object.placeholders.get( slot="course_organizations") add_plugin( language="en", placeholder=placeholder, plugin_type="OrganizationPlugin", page=organization_en.extended_object, ) add_plugin( language="fr", placeholder=placeholder, plugin_type="OrganizationPlugin", page=organization_fr.extended_object, ) with translation.override("fr"): self.assertEqual(list(course.get_organizations()), [organization_fr]) with translation.override("en"): self.assertEqual(list(course.get_organizations()), [organization_en])
def test_models_course_get_organizations_other_placeholders(self): """ The `get_organizations` method should return all organizations linked to a course via a plugin on whichever placeholder. """ organization1, organization2 = OrganizationFactory.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="OrganizationPlugin", page=organization1.extended_object, ) add_plugin( language="en", placeholder=placeholder2, plugin_type="OrganizationPlugin", page=organization2.extended_object, ) self.assertEqual(list(course.get_organizations()), [organization1, organization2])
def test_models_course_get_organizations(self): """ The `get_organizations` method should return all organizations linked to a course and should respect 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( list(course.get_organizations()), draft_organizations + published_organizations, ) self.assertEqual( list(course.public_extension.get_organizations()), published_organizations )
def test_models_course_get_organizations_empty(self): """ For a course not linked to any organzation the method `get_organizations` should return an empty query. """ course = CourseFactory(should_publish=True) self.assertFalse(course.get_organizations().exists()) self.assertFalse(course.public_extension.get_organizations().exists())