Beispiel #1
0
    def test_models_course_copy_relations_cloning(self):
        """When cloning a page, the course runs should not be copied."""
        course = factories.CourseFactory(page_title="my course title")
        page = course.extended_object
        TitleFactory(page=course.extended_object,
                     language="fr",
                     title="mon titre de cours")
        course_run = factories.CourseRunFactory(direct_course=course,
                                                title="my run")
        CourseRunTranslation.objects.create(master=course_run,
                                            language_code="fr",
                                            title="ma session")

        # Copy the course page as its own child
        copy_page = page.copy(page.node.site,
                              parent_node=page.node,
                              translations=True,
                              extensions=True)

        self.assertEqual(Course.objects.count(), 2)
        self.assertEqual(CourseRun.objects.count(), 1)
        self.assertEqual(CourseRunTranslation.objects.count(), 2)
        self.assertEqual(Title.objects.count(), 4)

        self.assertIsNone(copy_page.course.runs.first())
Beispiel #2
0
    def test_models_course_copy_relations_publish(self):
        """
        When publishing a draft course, the draft course run should be copied to a newly created
        course run with its parler translations.

        In a second part of the test, we check that when publishing a course that was already
        published, the draft course run should be copied to the existing public course run with its
        parler translations.

        """
        # 1- Publishing a draft course

        course = factories.CourseFactory(page_title="my course title")
        TitleFactory(page=course.extended_object,
                     language="fr",
                     title="mon titre de cours")
        course_run = factories.CourseRunFactory(direct_course=course,
                                                title="my run")
        CourseRunTranslation.objects.create(master=course_run,
                                            language_code="fr",
                                            title="ma session")
        self.assertEqual(Course.objects.count(), 1)
        self.assertEqual(CourseRun.objects.count(), 1)
        self.assertEqual(CourseRunTranslation.objects.count(), 2)
        self.assertEqual(Title.objects.count(), 2)

        self.assertTrue(course.extended_object.publish("fr"))

        self.assertEqual(Course.objects.count(), 2)
        self.assertEqual(CourseRun.objects.count(), 2)
        self.assertEqual(CourseRunTranslation.objects.count(), 3)
        self.assertEqual(Title.objects.count(), 3)

        # 2- Publishing a course that was already published
        self.assertTrue(course.extended_object.publish("en"))

        self.assertEqual(CourseRunTranslation.objects.count(), 4)
        self.assertEqual(Title.objects.count(), 4)

        course_run.refresh_from_db()

        public_course_run = course_run.public_course_run
        self.assertEqual(public_course_run.title, "my run")
        with switch_language(public_course_run, "fr"):
            self.assertEqual(public_course_run.title, "ma session")
Beispiel #3
0
    def test_views_redirect_edx_courses_success_with_old_course_uri(self):
        """Old OpenEdX course urls are redirected to the corresponding page in richie."""
        course = CourseFactory(code="abc",
                               page_title="Physique 101",
                               should_publish=True)
        TitleFactory(page=course.extended_object,
                     language="en",
                     title="Physics 101")
        course.extended_object.publish("en")

        response = self.client.get("/courses/sorbonne/abc/001/about/")

        self.assertRedirects(
            response,
            "/fr/physique-101/",
            status_code=301,
            target_status_code=200,
            fetch_redirect_response=True,
        )
Beispiel #4
0
    def test_models_course_copy_relations_publish_recursive_loop(self):
        """
        In a previous version of the the CourseRun method "copy_translations" in which we
        used instances instead of update queries, this test was generating an infinite
        recursive loop.
        """
        course = CourseFactory(page_title="my course title")
        TitleFactory(page=course.extended_object,
                     language="fr",
                     title="mon titre de cours")
        course_run = CourseRunFactory(direct_course=course, title="my run")
        course_run_translation_fr = CourseRunTranslation.objects.create(
            master=course_run, language_code="fr", title="ma session")
        self.assertTrue(course.extended_object.publish("fr"))

        course_run_translation_fr.title = "ma session modifiée"
        course_run_translation_fr.save()

        self.assertTrue(course.extended_object.publish("fr"))
Beispiel #5
0
    def test_views_redirect_edx_organization_success(self):
        """OpenEdX organization urls are redirected to the corresponding page in richie."""
        organization = OrganizationFactory(
            code="sorbonne",
            page_title="Sorbonne",
            should_publish=True,
        )
        TitleFactory(
            page=organization.extended_object,
            language="en",
            title="Sorbonne",
        )
        organization.extended_object.publish("en")

        response = self.client.get("/universities/sorbonne")

        self.assertRedirects(
            response,
            "/fr/sorbonne/",
            status_code=301,
            target_status_code=200,
            fetch_redirect_response=True,
        )
Beispiel #6
0
    def test_views_redirect_edx_courses_no_fallback(self):
        """
        OpenEdX course urls are not redirected if the french version of the page is not
        published (english is not yet activated on the public site).
        """
        course = CourseFactory(code="abc",
                               page_title="Mon titre",
                               should_publish=True)
        TitleFactory(page=course.extended_object,
                     language="en",
                     title="My title")
        course.extended_object.publish("en")
        course.extended_object.unpublish("fr")

        response = self.client.get("/courses/course-v1:org+abc+001/about/")

        self.assertRedirects(
            response,
            "/fr/courses/course-v1:org+abc+001/about/",
            status_code=302,
            target_status_code=404,
            fetch_redirect_response=True,
        )