How to use the richie.apps.courses.factories.CourseRunFactory 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_state.py View on Github external
def create_run_future_not_yet_open(self, course):
        """Create a course run in the future and not yet open for enrollment."""
        return CourseRunFactory(
            page_parent=course.extended_object,
            start=self.now + timedelta(hours=2),
            enrollment_start=self.now + timedelta(hours=1),
        )
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(
                        index="some_index", action="some_action"
                    )
                )["_id"]
            ],
        )
        self.assertEqual(
            course_document["categories"],
github openfun / richie / tests / apps / courses / test_models_course_state.py View on Github external
def create_run_future_closed(self, course):
        """Create a course run in the future and already closed for enrollment."""
        return CourseRunFactory(
            page_parent=course.extended_object,
            start=self.now + timedelta(hours=1),
            enrollment_start=self.now - timedelta(hours=2),
            enrollment_end=self.now - timedelta(hours=1),
        )
github openfun / richie / tests / apps / courses / test_models_course_run.py View on Github external
def test_models_course_run_field_languages_one_invalid(self):
        """
        When used in the `render_model` template tag, it should not break when passed a
        request argument.
        """
        with self.assertRaises(ValidationError) as context:
            CourseRunFactory(languages=["fr", "zzzzz"])
        self.assertEqual(
            context.exception.messages[0], "Value zzzzz is not a valid choice."
        )
github openfun / richie / tests / apps / courses / test_models_course_run.py View on Github external
def test_models_course_run_state_forever_open(self):
        """
        A course run that has no end of enrollement and no end should be forever open.
        """
        course_run = CourseRunFactory(enrollment_end=None, end=None)

        # The course run should be open between its start of enrollment and its start
        now = datetime.utcfromtimestamp(
            random.randrange(
                int(course_run.enrollment_start.timestamp()) + 1,
                int(course_run.start.timestamp()) - 1,
            )
        ).replace(tzinfo=pytz.utc)

        with mock.patch.object(timezone, "now", return_value=now):
            state = course_run.state

        self.assertEqual(
            dict(state),
            {
                "priority": 1,
github openfun / richie / tests / apps / courses / test_api_course_run.py View on Github external
def test_list_course_runs_by_anonymous_user(self):
        """
        The course run API does not support list requests.
        """
        CourseRunFactory.create_batch(2)
        response = self.client.get("/api/v1.0/course-runs/")
        self.assertEqual(response.status_code, 403)
github openfun / richie / tests / apps / courses / test_models_course_state.py View on Github external
def create_run_ongoing_closed(self, course):
        """Create an on-going course run that is closed for enrollment."""
        return CourseRunFactory(
            page_parent=course.extended_object,
            start=self.now - timedelta(hours=1),
            end=self.now + timedelta(hours=1),
            enrollment_end=self.now,
        )
github openfun / richie / tests / apps / courses / test_models_course_run.py View on Github external
def test_models_course_run_state_ongoing_open(self):
        """
        A course run that is on-going and open for enrollment should return a state with a CTA
        to enroll and the date of the end of enrollment.
        """
        course_run = CourseRunFactory(
            enrollment_start=self.now - timedelta(hours=3),
            start=self.now - timedelta(hours=2),
            enrollment_end=self.now + timedelta(hours=1),
            end=self.now + timedelta(hours=2),
        )
        self.assertEqual(
            dict(course_run.state),
            {
                "priority": 0,
                "text": "closing on",
                "call_to_action": "enroll now",
                "datetime": self.now + timedelta(hours=1),
            },
github openfun / richie / tests / apps / courses / test_models_course_run.py View on Github external
def test_models_course_run_field_languages_two_invalid(self):
        """
        When used in the `render_model` template tag, it should not break when passed a
        request argument.
        """
        with self.assertRaises(ValidationError) as context:
            CourseRunFactory(languages=["fr", "zzzzz", "de", "yyyyy"])
        self.assertEqual(
            context.exception.messages[0],
            "Values zzzzz and yyyyy are not valid choices.",
        )
github openfun / richie / tests / apps / courses / test_templates_course_run_detail.py View on Github external
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,
            (
                '<ul class="breadcrumbs__list">'
                '  <li class="breadcrumbs__item">You are here:</li>'
                '  <li class="breadcrumbs__item"><a href="/en/home/">home</a></li>'
                '  <li class="breadcrumbs__item"><a href="/en/home/courses/">courses</a></li>'
                '  <li class="breadcrumbs__item">'
                '    <a href="/en/home/courses/course-name/">course name</a>'</li></ul>