def test_repeat_course(self): # Initially course shouldn't be authorized self.assertFalse(EmbargoedCourse.is_embargoed(self.course.id)) # Test authorizing the course, which should totally work form = EmbargoedCourseForm(data=self.true_form_data) # Validation should work self.assertTrue(form.is_valid()) form.save() # Check that this course is authorized self.assertTrue(EmbargoedCourse.is_embargoed(self.course.id)) # Now make a new course authorization with the same course id that tries to turn email off form = EmbargoedCourseForm(data=self.false_form_data) # Validation should not work because course_id field is unique self.assertFalse(form.is_valid()) self.assertEquals( "Embargoed course with this Course id already exists.", form._errors['course_id'][0] # pylint: disable=protected-access ) with self.assertRaisesRegexp( ValueError, "The EmbargoedCourse could not be created because the data didn't validate." ): form.save() # Course should still be authorized (invalid attempt had no effect) self.assertTrue(EmbargoedCourse.is_embargoed(self.course.id))
def test_embargo_course(self): self.assertFalse(EmbargoedCourse.is_embargoed(self.course.id)) # Test adding embargo to this course form = EmbargoedCourseForm(data=self.true_form_data) # Validation should work self.assertTrue(form.is_valid()) form.save() # Check that this course is embargoed self.assertTrue(EmbargoedCourse.is_embargoed(self.course.id))
def test_repeat_course(self): # Initially course shouldn't be authorized self.assertFalse(EmbargoedCourse.is_embargoed(self.course.id)) # Test authorizing the course, which should totally work form = EmbargoedCourseForm(data=self.true_form_data) # Validation should work self.assertTrue(form.is_valid()) form.save() # Check that this course is authorized self.assertTrue(EmbargoedCourse.is_embargoed(self.course.id)) # Now make a new course authorization with the same course id that tries to turn email off form = EmbargoedCourseForm(data=self.false_form_data) # Validation should not work because course_id field is unique self.assertFalse(form.is_valid()) self.assertEquals( "Embargoed course with this Course id already exists.", form._errors["course_id"][0], # pylint: disable=protected-access ) with self.assertRaisesRegexp( ValueError, "The EmbargoedCourse could not be created because the data didn't validate." ): form.save() # Course should still be authorized (invalid attempt had no effect) self.assertTrue(EmbargoedCourse.is_embargoed(self.course.id))
def test_invalid_location(self): # Munge course id bad_id = self.course.id.to_deprecated_string().split('/')[-1] form_data = {'course_id': bad_id, 'embargoed': True} form = EmbargoedCourseForm(data=form_data) # Validation shouldn't work self.assertFalse(form.is_valid()) msg = 'COURSE NOT FOUND' msg += u' --- Entered course id was: "{0}". '.format(bad_id) 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 EmbargoedCourse could not be created because the data didn't validate."): form.save()
def test_invalid_location(self): # Munge course id bad_id = self.course.id.to_deprecated_string().split('/')[-1] form_data = {'course_id': bad_id, 'embargoed': True} form = EmbargoedCourseForm(data=form_data) # Validation shouldn't work self.assertFalse(form.is_valid()) msg = 'COURSE NOT FOUND' self.assertIn(msg, form._errors['course_id'][0]) # pylint: disable=protected-access with self.assertRaisesRegexp( ValueError, "The EmbargoedCourse could not be created because the data didn't validate." ): form.save()
def test_form_typo(self): # Munge course id bad_id = self.course.id + "_typo" form_data = {"course_id": bad_id, "embargoed": True} form = EmbargoedCourseForm(data=form_data) # Validation shouldn't work self.assertFalse(form.is_valid()) msg = "COURSE NOT FOUND" msg += u' --- Entered course id was: "{0}". '.format(bad_id) 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 EmbargoedCourse could not be created because the data didn't validate." ): form.save()