How to use the richie.apps.courses.factories.OrganizationFactory function in richie

To help you get started, we’ve selected a few richie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openfun / richie / tests / apps / courses / test_models_organization.py View on Github external
def test_models_organization_create_page_role_public_page(self, *_):
        """
        A page role should not be created for the public version of an organization.
        """
        organization = OrganizationFactory(should_publish=True).public_extension
        self.assertIsNone(organization.create_page_role())
        self.assertFalse(organization.extended_object.roles.exists())
github openfun / richie / tests / apps / courses / test_models_course.py View on Github external
def test_models_course_create_permissions_for_organization_public_page(self, *_):
        """No permissions should be created for the public version of an course."""
        course = CourseFactory(should_publish=True).public_extension
        organization = OrganizationFactory(should_publish=True).public_extension
        self.assertIsNone(course.create_permissions_for_organization(organization))
        self.assertFalse(PagePermission.objects.exists())
        self.assertFalse(FolderPermission.objects.exists())
github openfun / richie / tests / apps / courses / test_cms_wizards_course.py View on Github external
def test_cms_wizards_course_submit_form_slug_duplicate(self):
        """
        Trying to create a course with a slug that would lead to a duplicate path should
        raise a validation error.
        """
        # An organization and a parent page should pre-exist
        organization = OrganizationFactory()
        parent_page = create_page(
            "Courses",
            "richie/single_column.html",
            "en",
            reverse_id=Course.PAGE["reverse_id"],
        )
        # Create an existing page with a known slug
        CourseFactory(page_parent=parent_page, page_title="My title")

        # Submit a title that will lead to the same slug
        data = {"title": "my title"}

        user = UserFactory(is_staff=True, is_superuser=True)
        form = CourseWizardForm(
            data=data,
            wizard_language="en",
github openfun / richie / tests / apps / search / test_indexers_courses.py View on Github external
def test_indexers_courses_related_objects_consistency(self):
        """
        The organization and category ids in the Elasticsearch course document should be
        the same as the ids with which the corresponding organization and category objects
        are indexed.
        """
        # Create a course with a page in both english and french
        organization = OrganizationFactory(should_publish=True)
        category = CategoryFactory(should_publish=True)
        course = CourseFactory(
            fill_organizations=[organization],
            fill_categories=[category],
            should_publish=True,
        )
        CourseRunFactory(page_parent=course.extended_object, should_publish=True)

        course_document = list(
            CoursesIndexer.get_es_documents(index="some_index", action="some_action")
        )[0]
        self.assertEqual(
            course_document["organizations"],
            [
                next(
                    OrganizationsIndexer.get_es_documents(
github openfun / richie / tests / apps / courses / test_cms_plugins_organizations_by_category.py View on Github external
def test_cms_plugins_organizations_by_category_render_on_draft_page(self):
        """
        The organization plugin should render as expected on a draft page.
        """
        staff = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=staff.username, password="password")

        # Create a category
        category = CategoryFactory(page_title="public title")
        category_page = category.extended_object

        # Create organizations
        organization = OrganizationFactory(
            page_title={"en": "public title", "fr": "titre public"},
            fill_categories=[category],
            fill_logo={"original_filename": "logo.jpg"},
        )

        # Create a page to add the plugin to
        page = create_i18n_page("A page")
        placeholder = page.placeholders.get(slot="maincontent")
        add_plugin(
            placeholder, OrganizationsByCategoryPlugin, "en", **{"page": category_page}
        )

        category_page.publish("en")
        category_page.unpublish("en")
        category_page.refresh_from_db()
github openfun / richie / tests / apps / courses / test_models_course.py View on Github external
"can_move_page": random.choice([True, False]),
                    "can_view": False,  # can_view = True would make it a view restriction...
                    "grant_on": random.randint(1, 5),
                },
                "courses_folder_permissions": {
                    "can_read": random.choice([True, False]),
                    "can_edit": random.choice([True, False]),
                    "can_add_children": random.choice([True, False]),
                    "type": random.randint(0, 2),
                },
            }

        course = CourseFactory()
        PageRoleFactory(page=course.extended_object, role="ADMIN")

        organization = OrganizationFactory()
        organization_role = PageRoleFactory(
            page=organization.extended_object, role="ADMIN"
        )

        role_dict = get_random_role_dict()
        with mock.patch.dict(defaults.ORGANIZATION_ADMIN_ROLE, role_dict):
            course.create_permissions_for_organization(organization)

        # Call the method another time with different permissions to check it has no effect
        with mock.patch.dict(defaults.ORGANIZATION_ADMIN_ROLE, get_random_role_dict()):
            course.create_permissions_for_organization(organization)

        # All expected permissions should have been assigned to the group:
        # - DjangoCMS page permissions
        self.assertEqual(
            PagePermission.objects.filter(group=organization_role.group).count(), 1
github openfun / richie / tests / apps / courses / test_cms_wizards_course.py View on Github external
def test_cms_wizards_course_create_wizards_list_user_with_permissions(self, *_):
        """
        The wizard to create a new course page should be present on the wizards list page
        for a user with the required permissions visiting an organization page that he can
        change.
        """
        organization = OrganizationFactory()

        # Login with a user with just the required permissions
        user = UserFactory(
            is_staff=True,
            permissions=["courses.add_course", "cms.add_page", "cms.change_page"],
        )
        PagePermission.objects.create(
            page=organization.extended_object,
            user=user,
            can_add=True,
            can_change=True,
            can_delete=False,
            can_publish=False,
            can_move_page=False,
        )
        self.client.login(username=user.username, password="password")
github openfun / richie / tests / apps / courses / test_admin_organization.py View on Github external
def test_admin_organization_change_view_post(self):
        """
        Validate that the organization can be updated via the admin.
        """
        user = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=user.username, password="password")

        # Create an organization
        organization = OrganizationFactory()

        # Get the admin change view
        url = reverse("admin:courses_organization_change", args=[organization.id])
        data = {"code": " r5G yç👷学pm 44 "}
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, 302)

        # Check that the organization was updated as expected
        organization.refresh_from_db()
        self.assertEqual(organization.code, "R5G-YÇ学PM-44")
github openfun / richie / tests / apps / courses / test_cms_plugins_organizations_by_category.py View on Github external
The organizations by category plugin should render as expected on a public page.
        """
        # Create a category
        category = CategoryFactory(
            page_title={"en": "category title", "fr": "titre catégorie"}
        )
        category_page = category.extended_object

        # Create organizations
        published_organization = OrganizationFactory(
            page_title={"en": "public title", "fr": "titre public"},
            fill_categories=[category],
            fill_logo={"original_filename": "logo.jpg"},
            should_publish=True,
        )
        OrganizationFactory(
            page_title={"en": "private title", "fr": "titre privé"},
            fill_categories=[category],
            fill_logo={"original_filename": "logo.jpg"},
        )

        # Create a page to add the plugin to
        page = create_i18n_page({"en": "A page", "fr": "Une page"})
        placeholder = page.placeholders.get(slot="maincontent")
        add_plugin(
            placeholder, OrganizationsByCategoryPlugin, "en", **{"page": category_page}
        )
        add_plugin(
            placeholder, OrganizationsByCategoryPlugin, "fr", **{"page": category_page}
        )

        category_page.publish("en")
github openfun / richie / tests / apps / search / test_indexers_courses.py View on Github external
draft_category = CategoryFactory(fill_icon=True)  # L-0003

        main_organization = OrganizationFactory(  # L-0004
            page_title={
                "en": "english main organization title",
                "fr": "titre organisation principale français",
            },
            should_publish=True,
        )
        other_draft_organization = OrganizationFactory(  # L-0005
            page_title={
                "en": "english other organization title",
                "fr": "titre autre organisation français",
            }
        )
        other_published_organization = OrganizationFactory(  # L-0006
            page_title={
                "en": "english other organization title",
                "fr": "titre autre organisation français",
            },
            should_publish=True,
        )

        person1 = PersonFactory(
            page_title={"en": "Eugène Delacroix", "fr": "Eugène Delacroix"},
            should_publish=True,
        )
        person2 = PersonFactory(
            page_title={"en": "Comte de Saint-Germain", "fr": "Earl of Saint-Germain"},
            should_publish=True,
        )
        person_draft = PersonFactory(