Beispiel #1
0
    def test_course_title_formatting(self):
        """
        Verify that course_title is properly escaped and saved in database while
        updating the course
        """
        course, course_admin = self.setup_course(image=None)
        assert course.title != 'áçã'

        organization = course.organizations.first().id
        course_from_data = {
            'title': 'áçã',
            'number': course.number,
            'organization': organization,
            'team_admin': course_admin.id
        }
        course_form = CourseForm(
            **{
                'data': course_from_data,
                'instance': course,
                'user': course_admin,
                'organization': organization
            })
        assert course_form.is_valid()
        course_form.save()
        course.refresh_from_db()
        assert course.title == 'áçã'
Beispiel #2
0
 def test_valid_course_number(self, valid_number_list):
     """
     Verify that clean_number allows alphanumeric(a-zA-Z0-9) characters, period, underscore and hyphen
     in course number
     """
     course_form = CourseForm()
     for valid_number in valid_number_list:
         course_form.cleaned_data = {'number': valid_number}
         self.assertEqual(course_form.clean_number(), valid_number)
Beispiel #3
0
 def test_invalid_course_number(self, invalid_char_list):
     """
     Verify that clean_number raises 'ValidationError' if the course number consists of special characters
     or spaces other than underscore,hyphen or period
     """
     course_form = CourseForm()
     for invalid_char in invalid_char_list:
         course_form.cleaned_data = {'number': 'course_num{}'.format(invalid_char)}
         with self.assertRaises(ValidationError):
             course_form.clean_number()
Beispiel #4
0
 def setUp(self):
     super(PublisherCustomCourseFormTests, self).setUp()
     self.course_form = CourseForm()
     self.organization = OrganizationFactory()
     self.course = CourseFactory(title='Test',
                                 number='a123',
                                 organizations=[self.organization])
Beispiel #5
0
    def test_invalid_number(self):
        """
        Verify that clean_number raises 'ValidationError' if the course number consists of special characters
        or spaces
        """
        course_form = CourseForm()
        course_form.cleaned_data = {'number': '123 a'}
        with self.assertRaises(ValidationError):
            course_form.clean_number()

        course_form.cleaned_data['number'] = "123.a"
        self.assertEqual(course_form.clean_number(), "123.a")

        course_form.cleaned_data['number'] = "123a"
        self.assertEqual(course_form.clean_number(), "123a")
Beispiel #6
0
    def test_duplicate_course_number(self):
        """
        Verify that clean raises 'ValidationError' if the course number is a duplicate of another course number
        within the same organization
        """
        course_form = CourseForm()
        course_form.cleaned_data = {'title': 'Test2', 'number': 'a123', 'organization': self.organization}
        with self.assertRaises(ValidationError):
            course_form.clean()

        course_form.cleaned_data['number'] = "123a"
        self.assertEqual(course_form.clean(), course_form.cleaned_data)
Beispiel #7
0
    def put(self, _request, history_id):
        """ Update the course version against the given revision id. """
        history_object = get_object_or_404(historicalcourse, pk=history_id)
        course = get_object_or_404(Course, id=history_object.id)
        try:
            for field in CourseForm().fields:
                if field not in ['team_admin', 'organization', 'add_new_run', 'url_slug']:
                    setattr(course, field, getattr(history_object, field))

            course.changed_by = self.request.user
            course.save()
        except Exception:  # pylint: disable=broad-except
            logger.exception('Unable to revert the course [%s] for revision [%s].', course.id, history_id)
            return Response(status=status.HTTP_400_BAD_REQUEST)

        return Response(status=status.HTTP_204_NO_CONTENT)
Beispiel #8
0
 def setUp(self):
     super(UserModelChoiceFieldTests, self).setUp()
     self.course_form = CourseForm()