def test_import_delete_pre_exiting_entrance_exam(self):
        """
        Check that pre existed entrance exam content should be overwrite with the imported course.
        """
        exam_url = '/course/{}/entrance_exam/'.format(six.text_type(self.course.id))
        resp = self.client.post(exam_url, {'entrance_exam_minimum_score_pct': 0.5}, http_accept='application/json')
        self.assertEqual(resp.status_code, 201)

        # Reload the test course now that the exam module has been added
        self.course = modulestore().get_course(self.course.id)
        metadata = CourseMetadata.fetch_all(self.course)
        self.assertTrue(metadata['entrance_exam_enabled'])
        self.assertIsNotNone(metadata['entrance_exam_minimum_score_pct'])
        self.assertEqual(metadata['entrance_exam_minimum_score_pct']['value'], 0.5)
        self.assertTrue(len(milestones_helpers.get_course_milestones(six.text_type(self.course.id))))
        content_milestones = milestones_helpers.get_course_content_milestones(
            six.text_type(self.course.id),
            metadata['entrance_exam_id']['value'],
            milestones_helpers.get_milestone_relationship_types()['FULFILLS']
        )
        self.assertTrue(len(content_milestones))

        # Now import entrance exam course
        with open(self.entrance_exam_tar, 'rb') as gtar:  # pylint: disable=open-builtin
            args = {"name": self.entrance_exam_tar, "course-data": [gtar]}
            resp = self.client.post(self.url, args)
        self.assertEqual(resp.status_code, 200)
        course = self.store.get_course(self.course.id)
        self.assertIsNotNone(course)
        self.assertEqual(course.entrance_exam_enabled, True)
        self.assertEqual(course.entrance_exam_minimum_score_pct, 0.7)
예제 #2
0
    def test_contentstore_views_entrance_exam_post(self):
        """
        Unit Test: test_contentstore_views_entrance_exam_post
        """
        resp = self.client.post(self.exam_url, {},
                                http_accept='application/json')
        self.assertEqual(resp.status_code, 201)
        resp = self.client.get(self.exam_url)
        self.assertEqual(resp.status_code, 200)

        # Reload the test course now that the exam module has been added
        self.course = modulestore().get_course(self.course.id)
        metadata = CourseMetadata.fetch_all(self.course)
        self.assertTrue(metadata['entrance_exam_enabled'])
        self.assertIsNotNone(metadata['entrance_exam_minimum_score_pct'])
        self.assertIsNotNone(metadata['entrance_exam_id']['value'])
        self.assertTrue(
            len(
                milestones_helpers.get_course_milestones(
                    six.text_type(self.course.id))))
        content_milestones = milestones_helpers.get_course_content_milestones(
            six.text_type(self.course.id),
            metadata['entrance_exam_id']['value'],
            self.milestone_relationship_types['FULFILLS'])
        self.assertTrue(len(content_milestones))
예제 #3
0
    def get(self, request: Request, course_id: str):
        """
        Get an object containing all the advanced settings in a course.

        **Example Request**

            GET /api/contentstore/v0/advanced_settings/{course_id}

        **Response Values**

        If the request is successful, an HTTP 200 "OK" response is returned.

        The HTTP 200 response contains a single dict that contains keys that
        are the course's advanced settings. For each setting a dictionary is
        returned that contains the following fields:

        * **deprecated**: This is true for settings that are deprecated.
        * **display_name**: This is a friendly name for the setting.
        * **help**: Contains help text that explains how the setting works.
        * **value**: Contains the value of the setting. The exact format
          depends on the setting and is often explained in the ``help`` field
          above.

        There may be other fields returned by the response.

        **Example Response**

        ```json
        {
            "display_name": {
                "value": "Demonstration Course",
                "display_name": "Course Display Name",
                "help": "Enter the name of the course as it should appear in the course list.",
                "deprecated": false,
                "hide_on_enabled_publisher": false
            },
            "course_edit_method": {
                "value": "Studio",
                "display_name": "Course Editor",
                "help": "Enter the method by which this course is edited (\"XML\" or \"Studio\").",
                "deprecated": true,
                "hide_on_enabled_publisher": false
            },
            "days_early_for_beta": {
                "value": null,
                "display_name": "Days Early for Beta Users",
                "help": "Enter the number of days before the start date that beta users can access the course.",
                "deprecated": false,
                "hide_on_enabled_publisher": false
            },
            ...
        }
        ```
        """
        filter_query_data = AdvancedCourseSettingsView.FilterQuery(
            request.query_params)
        if not filter_query_data.is_valid():
            raise ValidationError(filter_query_data.errors)
        course_key = CourseKey.from_string(course_id)
        if not has_studio_read_access(request.user, course_key):
            self.permission_denied(request)
        course_module = modulestore().get_course(course_key)
        return Response(
            CourseMetadata.fetch_all(
                course_module,
                filter_fields=filter_query_data.cleaned_data['filter_fields'],
            ))