def test_id_of_a_non_option(self): form_data = self.form_data.copy() form_data['response'] = -1 answer_form = MultiChoiceAnswerForm(form_data, initial=self.initial) self.assertFalse(answer_form.is_valid()) message = 'Select a valid choice. That choice is not one of the available choices.' self.assertEqual([message], answer_form.errors['response'])
def test_multiple_form_choice_form_adds_data_instruction_attributes_for_question_options( self): question_option_two = QuestionOption.objects.create( text='Option 2', question=self.question, instructions="Some stuff") question_option_3 = QuestionOption.objects.create( text='Option 3', question=self.question, instructions="Some stuff") question_option_4 = QuestionOption.objects.create( text='Option 4', question=self.question, instructions="Some stuff") answer_form = MultiChoiceAnswerForm(initial=self.initial) query_set = answer_form._get_response_choices(self.initial) widget = answer_form._get_response_widget(query_set) self.assertIsInstance(widget, MultiChoiceAnswerSelectWidget) self.assertEqual(4, widget.question_options.count()) self.assertIn(self.question_option_one, widget.question_options) self.assertIn(question_option_two, widget.question_options) self.assertIn(question_option_3, widget.question_options) self.assertIn(question_option_4, widget.question_options) self.assertEqual("Choose One", answer_form.fields['response'].empty_label)
def test_valid(self): answer_form = MultiChoiceAnswerForm(self.form_data, initial=self.initial) self.assertTrue(answer_form.is_valid()) self.assertIsNone(answer_form.fields['response'].empty_label)