示例#1
0
    def test_validation_error_if_no_choice_in_given_chain(self):
        chain1, chain2 = mommy.make(Chain, _quantity=2)
        seed = mommy.make(Message, chain=chain1)
        other_seed = mommy.make(Message, chain=chain2)

        gen1 = mommy.make(Message, parent=seed, chain=chain1)

        survey = mommy.make(Survey)
        choices = [other_seed, ]
        question_data = {
            'survey': survey.id,
            'given': gen1.id,
            'choices': [message.id for message in choices]
        }
        question_form = CreateQuestionForm(question_data)
        with self.assertRaises(Message.DoesNotExist):
            question_form.save()
示例#2
0
    def test_validation_error_if_no_choice_in_given_chain(self):
        chain1, chain2 = mommy.make(Chain, _quantity=2)
        seed = mommy.make(Message, chain=chain1)
        other_seed = mommy.make(Message, chain=chain2)

        gen1 = mommy.make(Message, parent=seed, chain=chain1)

        survey = mommy.make(Survey)
        choices = [
            other_seed,
        ]
        question_data = {
            'survey': survey.id,
            'given': gen1.id,
            'choices': [message.id for message in choices]
        }
        question_form = CreateQuestionForm(question_data)
        with self.assertRaises(Message.DoesNotExist):
            question_form.save()
示例#3
0
    def test_delete_question_if_answer_not_found_in_choices(self):
        chain1, chain2 = mommy.make(Chain, _quantity=2)
        seed = mommy.make(Message, chain=chain1)
        other_seed = mommy.make(Message, chain=chain2)

        gen1 = mommy.make(Message, parent=seed, chain=chain1)

        survey = mommy.make(Survey)
        self.assertEquals(survey.questions.count(), 0)

        choices = [other_seed, ]
        question_data = {
            'survey': survey.id,
            'given': gen1.id,
            'choices': [message.id for message in choices],
            'determine_correct_answer': True,
        }
        question_form = CreateQuestionForm(question_data)
        with self.assertRaises(Message.DoesNotExist):
            question_form.save()

        self.assertEquals(survey.questions.count(), 0)
示例#4
0
    def test_select_answer_from_choices(self):
        chain1, chain2 = mommy.make(Chain, _quantity=2)
        seed = mommy.make(Message, chain=chain1)
        other_seed = mommy.make(Message, chain=chain2)

        gen1 = mommy.make(Message, parent=seed, chain=chain1)

        survey = mommy.make(Survey)
        choices = [seed, other_seed]
        question_data = {
            'survey': survey.id,
            'given': gen1.id,
            'choices': [message.id for message in choices]
        }
        question_form = CreateQuestionForm(question_data)
        self.assertTrue(question_form.is_valid())

        question = question_form.save()
        self.assertEquals(list(question.choices.all()), choices)
        self.assertEquals(question.answer, seed)
示例#5
0
    def test_select_answer_from_choices(self):
        chain1, chain2 = mommy.make(Chain, _quantity=2)
        seed = mommy.make(Message, chain=chain1)
        other_seed = mommy.make(Message, chain=chain2)

        gen1 = mommy.make(Message, parent=seed, chain=chain1)

        survey = mommy.make(Survey)
        choices = [seed, other_seed]
        question_data = {
            'survey': survey.id,
            'given': gen1.id,
            'choices': [message.id for message in choices]
        }
        question_form = CreateQuestionForm(question_data)
        self.assertTrue(question_form.is_valid())

        question = question_form.save()
        self.assertEquals(list(question.choices.all()), choices)
        self.assertEquals(question.answer, seed)