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()
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")
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)