Example #1
0
    def test_form_typo(self):
        # Munge course id
        bad_id = SlashSeparatedCourseKey(
            u'Broken{}'.format(self.course.id.org), 'hello',
            self.course.id.run + '_typo')

        form_data = {
            'course_id': bad_id.to_deprecated_string(),
            'email_enabled': True
        }
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u'COURSE NOT FOUND'
        msg += u' --- Entered course id was: "{0}". '.format(
            bad_id.to_deprecated_string())
        msg += 'Please recheck that you have supplied a valid course id.'
        self.assertEquals(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(
                ValueError,
                "The CourseAuthorization could not be created because the data didn't validate."
        ):
            form.save()
Example #2
0
    def test_repeat_course(self):
        # Initially course shouldn't be authorized
        self.assertFalse(BulkEmailFlag.feature_enabled(self.course.id))
        # Test authorizing the course, which should totally work
        form_data = {
            'course_id': text_type(self.course.id),
            'email_enabled': True
        }
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation should work
        self.assertTrue(form.is_valid())
        form.save()
        # Check that this course is authorized
        self.assertTrue(BulkEmailFlag.feature_enabled(self.course.id))

        # Now make a new course authorization with the same course id that tries to turn email off
        form_data = {
            'course_id': text_type(self.course.id),
            'email_enabled': False
        }
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation should not work because course_id field is unique
        self.assertFalse(form.is_valid())
        self.assertEquals(
            "Course authorization with this Course id already exists.",
            form._errors['course_id'][0]  # pylint: disable=protected-access
        )
        with self.assertRaisesRegexp(
                ValueError,
                "The CourseAuthorization could not be created because the data didn't validate."
        ):
            form.save()

        # Course should still be authorized (invalid attempt had no effect)
        self.assertTrue(BulkEmailFlag.feature_enabled(self.course.id))
Example #3
0
 def test_authorize_mongo_course(self):
     # Initially course shouldn't be authorized
     self.assertFalse(BulkEmailFlag.feature_enabled(self.course.id))
     # Test authorizing the course, which should totally work
     form_data = {'course_id': self.course.id.to_deprecated_string(), 'email_enabled': True}
     form = CourseAuthorizationAdminForm(data=form_data)
     # Validation should work
     self.assertTrue(form.is_valid())
     form.save()
     # Check that this course is authorized
     self.assertTrue(BulkEmailFlag.feature_enabled(self.course.id))
Example #4
0
 def test_authorize_mongo_course(self):
     # Initially course shouldn't be authorized
     self.assertFalse(CourseAuthorization.instructor_email_enabled(self.course.id))
     # Test authorizing the course, which should totally work
     form_data = {'course_id': self.course.id.to_deprecated_string(), 'email_enabled': True}
     form = CourseAuthorizationAdminForm(data=form_data)
     # Validation should work
     self.assertTrue(form.is_valid())
     form.save()
     # Check that this course is authorized
     self.assertTrue(CourseAuthorization.instructor_email_enabled(self.course.id))
Example #5
0
 def test_authorize_mongo_course(self):
     # Initially course shouldn't be authorized
     self.assertFalse(BulkEmailFlag.feature_enabled(self.course.id))
     # Test authorizing the course, which should totally work
     form_data = {'course_id': text_type(self.course.id), 'email_enabled': True}
     form = CourseAuthorizationAdminForm(data=form_data)
     # Validation should work
     self.assertTrue(form.is_valid())
     form.save()
     # Check that this course is authorized
     self.assertTrue(BulkEmailFlag.feature_enabled(self.course.id))
Example #6
0
 def test_authorize_mongo_course(self):
     # Initially course shouldn't be authorized
     self.assertFalse(CourseAuthorization.instructor_email_enabled(self.course.id))
     # Test authorizing the course, which should totally work
     form_data = {'course_id': self.course.id, 'email_enabled': True}
     form = CourseAuthorizationAdminForm(data=form_data)
     # Validation should work
     self.assertTrue(form.is_valid())
     form.save()
     # Check that this course is authorized
     self.assertTrue(CourseAuthorization.instructor_email_enabled(self.course.id))
Example #7
0
    def test_course_name_only(self):
        # Munge course id - common
        form_data = {'course_id': self.course.id.run, 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        error_msg = form._errors['course_id'][0]
        self.assertIn(u'--- Entered course id was: "{0}". '.format(self.course.id.run), error_msg)
        self.assertIn(u'Please recheck that you have supplied a valid course id.', error_msg)

        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()
Example #8
0
    def test_form_invalid_key(self):
        form_data = {'course_id': "asd::**!@#$%^&*())//foobar!!", 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u'Course id invalid.'
        msg += u' --- Entered course id was: "asd::**!@#$%^&*())//foobar!!". '
        msg += 'Please recheck that you have supplied a valid course id.'
        self.assertEquals(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()
Example #9
0
    def test_form_invalid_key(self):
        form_data = {'course_id': "asd::**!@#$%^&*())//foobar!!", 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u'Course id invalid.'
        msg += u' --- Entered course id was: "asd::**!@#$%^&*())//foobar!!". '
        msg += 'Please recheck that you have supplied a valid course id.'
        self.assertEquals(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()
Example #10
0
    def test_course_name_only(self):
        # Munge course id - common
        form_data = {'course_id': self.course.id.run, 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        error_msg = form._errors['course_id'][0]
        self.assertIn(u'--- Entered course id was: "{0}". '.format(self.course.id.run), error_msg)
        self.assertIn(u'Please recheck that you have supplied a valid course id.', error_msg)

        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()
Example #11
0
    def test_repeat_course(self):
        # Initially course shouldn't be authorized
        self.assertFalse(CourseAuthorization.instructor_email_enabled(self.course.id))
        # Test authorizing the course, which should totally work
        form_data = {'course_id': self.course.id.to_deprecated_string(), 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation should work
        self.assertTrue(form.is_valid())
        form.save()
        # Check that this course is authorized
        self.assertTrue(CourseAuthorization.instructor_email_enabled(self.course.id))

        # Now make a new course authorization with the same course id that tries to turn email off
        form_data = {'course_id': self.course.id.to_deprecated_string(), 'email_enabled': False}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation should not work because course_id field is unique
        self.assertFalse(form.is_valid())
        self.assertEquals(
            "Course authorization with this Course id already exists.",
            form._errors['course_id'][0]  # pylint: disable=protected-access
        )
        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()

        # Course should still be authorized (invalid attempt had no effect)
        self.assertTrue(CourseAuthorization.instructor_email_enabled(self.course.id))
Example #12
0
    def test_course_name_only(self):
        # Munge course id - common
        form_data = {'course_id': self.course.id.run, 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        error_msg = form._errors['course_id'][0]  # pylint: disable=protected-access
        self.assertIn(u'Entered course id was: "{0}".'.format(self.course.id.run), error_msg)

        with self.assertRaisesRegex(
            ValueError,
            "The CourseAuthorization could not be created because the data didn't validate."
        ):
            form.save()
Example #13
0
    def test_xml_course_authorization(self):
        course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
        # Assert this is an XML course
        self.assertEqual(modulestore().get_modulestore_type(course_id), XML_MODULESTORE_TYPE)

        form_data = {'course_id': course_id.to_deprecated_string(), 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u"Course Email feature is only available for courses authored in Studio. "
        msg += u'"{0}" appears to be an XML backed course.'.format(course_id.to_deprecated_string())
        self.assertEquals(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()
Example #14
0
    def test_xml_course_authorization(self):
        course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
        # Assert this is an XML course
        self.assertEqual(modulestore().get_modulestore_type(course_id), ModuleStoreEnum.Type.xml)

        form_data = {'course_id': course_id.to_deprecated_string(), 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u"Course Email feature is only available for courses authored in Studio. "
        msg += u'"{0}" appears to be an XML backed course.'.format(course_id.to_deprecated_string())
        self.assertEquals(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()
Example #15
0
    def test_course_name_only(self):
        # Munge course id - common
        bad_id = self.course.id.split('/')[-1]

        form_data = {'course_id': bad_id, 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u'Error encountered (Need more than 1 value to unpack)'
        msg += ' --- Entered course id was: "{0}". '.format(bad_id)
        msg += 'Please recheck that you have supplied a course id in the format: ORG/COURSE/RUN'
        self.assertEquals(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()
Example #16
0
    def test_form_typo(self):
        # Munge course id
        bad_id = SlashSeparatedCourseKey(u'Broken{}'.format(self.course.id.org), '', self.course.id.run + '_typo')

        form_data = {'course_id': bad_id.to_deprecated_string(), 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u'COURSE NOT FOUND'
        msg += u' --- Entered course id was: "{0}". '.format(bad_id.to_deprecated_string())
        msg += 'Please recheck that you have supplied a valid course id.'
        self.assertEquals(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()
Example #17
0
    def test_course_name_only(self):
        # Munge course id - common
        bad_id = self.course.id.split('/')[-1]

        form_data = {'course_id': bad_id, 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u'Error encountered (Need more than 1 value to unpack)'
        msg += ' --- Entered course id was: "{0}". '.format(bad_id)
        msg += 'Please recheck that you have supplied a course id in the format: ORG/COURSE/RUN'
        self.assertEquals(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()
Example #18
0
    def test_xml_course_authorization(self):
        course_id = 'edX/toy/2012_Fall'
        # Assert this is an XML course
        self.assertTrue(modulestore().get_modulestore_type(course_id) != MONGO_MODULESTORE_TYPE)

        form_data = {'course_id': course_id, 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u"Course Email feature is only available for courses authored in Studio. "
        msg += '"{0}" appears to be an XML backed course.'.format(course_id)
        self.assertEquals(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(ValueError, "The CourseAuthorization could not be created because the data didn't validate."):
            form.save()
Example #19
0
    def test_form_typo(self):
        # Munge course id
        bad_id = CourseLocator(u'Broken{}'.format(self.course.id.org), 'hello', self.course.id.run + '_typo')

        form_data = {'course_id': text_type(bad_id), 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u'Course not found.'
        msg += u' Entered course id was: "{0}".'.format(text_type(bad_id))
        self.assertEqual(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegex(
            ValueError,
            "The CourseAuthorization could not be created because the data didn't validate."
        ):
            form.save()
Example #20
0
    def test_form_typo(self):
        # Munge course id
        bad_id = CourseLocator(u'Broken{}'.format(self.course.id.org), 'hello', self.course.id.run + '_typo')

        form_data = {'course_id': text_type(bad_id), 'email_enabled': True}
        form = CourseAuthorizationAdminForm(data=form_data)
        # Validation shouldn't work
        self.assertFalse(form.is_valid())

        msg = u'Course not found.'
        msg += u' Entered course id was: "{0}".'.format(text_type(bad_id))
        self.assertEquals(msg, form._errors['course_id'][0])  # pylint: disable=protected-access

        with self.assertRaisesRegexp(
            ValueError,
            "The CourseAuthorization could not be created because the data didn't validate."
        ):
            form.save()