Exemplo n.º 1
0
 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'])
Exemplo n.º 2
0
 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'])
Exemplo n.º 3
0
 def test_new_option_is_created_and_saved_as_response_when_specify_field_is_not_empty(self):
     form_data = self.form_data.copy()
     form_data['specified_option'] = 'specified option'
     answer_form = MultiChoiceAnswerForm(form_data, initial=self.initial)
     self.assertTrue(answer_form.is_valid())
     answer_form.save()
     option = QuestionOption.objects.get(text="specified option", question=self.question)
     self.failUnless(MultiChoiceAnswer.objects.filter(response=option, question=self.question))
     as_text = '<input id="id_response" name="response" type="text" value="%d" />' % option.id
     self.assertEqual(as_text, answer_form.visible_fields()[0].as_text())
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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)