How to use the richie.apps.courses.factories.CourseFactory 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_course.py View on Github external
def test_models_course_field_effort_invalid_unit(self):
        """The second value should be a valid time unit choice."""
        with self.assertRaises(ValidationError) as context:
            CourseFactory(effort=[1, "invalid", "month"])
        self.assertEqual(
            context.exception.messages[0],
            "invalid is not a valid choice for a time unit.",
        )
github openfun / richie / tests / apps / courses / test_cms_toolbars.py View on Github external
def test_cms_toolbars_course_has_page_extension_settings_item(self):
        """
        Validate that a new item to edit the course is available only when visiting the page
        in edit mode and for users with permission to edit the page.
        """
        course = CourseFactory()
        url = "/en/admin/courses/course/{id:d}/change/".format(id=course.id)

        for args, method in self.get_cases_for_page_change():
            toolbar = self.get_toolbar_for_page(course.extended_object, *args)
            item = method(toolbar, "Course settings...")
            if item:
                self.assertEqual(item.url, url)
github openfun / richie / tests / apps / courses / test_models_course_run.py View on Github external
def test_models_course_run_get_course_child_of_snapshot(self):
        """
        We should be able to retrieve the course from a course run that is a child of one of
        its snapshots.
        """
        course = CourseFactory(should_publish=True)
        snapshot = CourseFactory(
            page_parent=course.extended_object, should_publish=True
        )
        course_run = CourseRunFactory(
            page_parent=snapshot.extended_object, should_publish=True
        )
        # Add a sibling course to make sure it is not returned
        CourseFactory(should_publish=True)

        self.assertEqual(course_run.get_course(), course)
        self.assertEqual(
            course_run.public_extension.get_course(), course.public_extension
        )
github openfun / richie / tests / apps / courses / test_templates_course_run_detail.py View on Github external
def test_templates_course_run_detail_no_index(self):
        """
        A course run page should not be indexable by search engine robots.
        """
        course = CourseFactory(should_publish=True)
        course_run = CourseRunFactory(
            page_parent=course.extended_object, should_publish=True
        )

        url = course_run.extended_object.get_absolute_url()
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '')
github openfun / richie / tests / apps / courses / test_templates_course_run_detail.py View on Github external
def test_templates_course_run_detail_breadcrumb_below_course(self):
        """
        Validate the format of the breadcrumb on a course run directly placed below the course.
        """
        home_page = PageFactory(
            title__title="home", title__language="en", should_publish=True
        )
        search_page = PageFactory(
            title__title="courses",
            title__language="en",
            parent=home_page,
            should_publish=True,
        )
        course = CourseFactory(
            page_title="course name",
            page_parent=search_page,
            page_in_navigation=True,
            should_publish=True,
        )
        course_run = CourseRunFactory(
            page_title="session 42",
            page_parent=course.extended_object,
            should_publish=True,
        )
        response = self.client.get(course_run.extended_object.get_absolute_url())

        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            (
github openfun / richie / tests / apps / courses / test_templates_person_detail.py View on Github external
def test_templates_person_detail_related_courses(self):
        """
        The courses to which a person has participated should appear on this person's detail page.
        """
        user = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=user.username, password="password")

        person = PersonFactory()
        course = CourseFactory(fill_team=[person])

        url = person.extended_object.get_absolute_url()
        response = self.client.get(url)

        # The course should be present on the page
        self.assertContains(
            response,
            '<p class="course-glimpse__title">{:s}</p>'.format(
                course.extended_object.get_title()
            ),
            html=True,
        )
github openfun / richie / tests / apps / courses / test_cms_wizards_course_run.py View on Github external
def test_cms_wizards_course_run_submit_form_slugify_long_title(self, mock_snapshot):
        """
        When generating the slug from the title, we should respect the slug's "max_length"
        """
        # A course should pre-exist
        course = CourseFactory()

        # Submit a title at max length
        data = {"title": "t" * 255}
        user = UserFactory(is_staff=True, is_superuser=True)
        form = CourseRunWizardForm(
            data=data,
            wizard_language="en",
            wizard_user=user,
            wizard_page=course.extended_object,
        )

        self.assertTrue(form.is_valid())
        page = form.save()
        # Check that the slug has been truncated
        self.assertEqual(page.get_slug(), "t" * 200)
github openfun / richie / tests / apps / search / test_indexers_courses.py View on Github external
def test_indexers_courses_get_es_documents_snapshots(self):
        """
        Course snapshots should not get indexed.
        """
        course = CourseFactory(should_publish=True)
        CourseFactory(page_parent=course.extended_object, should_publish=True)

        indexed_courses = list(
            CoursesIndexer.get_es_documents(index="some_index", action="some_action")
        )
        self.assertEqual(len(indexed_courses), 1)
        self.assertEqual(
            indexed_courses[0]["_id"], str(course.public_extension.extended_object_id)
        )
github openfun / richie / tests / apps / courses / test_cms_wizards_course_run.py View on Github external
def test_cms_wizards_course_run_submit_form_slug_too_long(self, mock_snapshot):
        """
        Trying to set a slug that is too long should make the form invalid
        """
        # A course should pre-exist
        course = CourseFactory()

        # Submit a slug that is too long and a title that is ok
        invalid_data = {"title": "t" * 255, "slug": "s" * 201}

        user = UserFactory(is_staff=True, is_superuser=True)
        form = CourseRunWizardForm(
            data=invalid_data,
            wizard_language="en",
            wizard_user=user,
            wizard_page=course.extended_object,
        )

        self.assertFalse(form.is_valid())
        # Check that the slug being too long is a cause for the invalid form
        self.assertEqual(
            form.errors["slug"],
github openfun / richie / tests / apps / courses / test_models_course.py View on Github external
def test_models_course_create_page_role_public_page(self, *_):
        """
        A page role should not be created for the public version of a course.
        """
        course = CourseFactory(should_publish=True).public_extension
        self.assertIsNone(course.create_page_role())
        self.assertFalse(course.extended_object.roles.exists())