def test_course_form_rejects_invalid_data(self): form = CourseForm(self.bad_data) self.assertFalse(form.is_valid()) # def test_course_form_rejects_invalid_data(self): # form = CourseForm(self.bad_data) # self.assertFalse(form.is_valid())
def course_list(request): course_info = Course.objects.all() if request.method == 'POST': form = CourseForm(request.POST) if form.is_valid(): new_course = form.save(commit=False) new_course = form.save() else: form = CourseForm() return render_to_response('courses.html',{'courses': course_info, 'form': form},context_instance=RequestContext(request))
def test_course_form_accepts_valid_data(self): form = CourseForm(self.data) self.assertTrue(form.is_valid())
def test_introduction_field(self): form = CourseForm() label = form.fields['introduction'].label max_length = form.fields['introduction'].max_length self.assertTrue(label == None or label == '简介') self.assertEqual(max_length, 150)
def test_charge_field(self): form = CourseForm() label = form.fields['charge'].label self.assertTrue(label == None or label == '课程收费')
def test_subject_field(self): form = CourseForm() label = form.fields['subject'].label self.assertTrue(label == None or label == '科目')
def test_grade_course_field(self): form = CourseForm() label = form.fields['grade_course'].label self.assertTrue(label == None or label == '学生年级')
def test_nick_name_field(self): form = CourseForm() label = form.fields['nick_name'].label max_length = form.fields['nick_name'].max_length self.assertTrue(label == None or label == '课程名称') self.assertEqual(max_length, 50)