Esempio n. 1
0
    def test_short_text(self):
        Response.objects.create(submission=self.submission,
                                question=self.short_text, value='yes')

        column = QuestionColumn(self.hierarchy_one, self.short_text)

        # identifier
        identifier = '%s_%s' % (self.hierarchy_one.id, self.short_text.id)
        self.assertEquals(column.identifier(), identifier)

        # key row
        key_row = ['one', identifier, 'Quiz', 'short text', b'short text']
        self.assertEquals(column.metadata(), key_row)

        # user value
        self.assertEquals(column.user_value(self.user), 'yes')
        self.assertEquals(column.user_value(self.user2), None)
Esempio n. 2
0
    def test_single_answer(self):
        Response.objects.create(submission=self.submission,
                                question=self.single_answer,
                                value='0')

        column = QuestionColumn(self.hierarchy_one, self.single_answer)

        # identifier
        identifier = '%s_%s' % (self.hierarchy_one.id, self.single_answer.id)
        self.assertEquals(column.identifier(), identifier)

        # key row
        key_row = ['one', identifier, 'Quiz', 'single choice',
                   b'single answer']
        self.assertEquals(column.metadata(), key_row)

        # user value
        self.assertEquals(column.user_value(self.user),
                          str(self.single_answer_two.id))
        self.assertEquals(column.user_value(self.user2), None)
Esempio n. 3
0
    def test_multiple_answer(self):
        Response.objects.create(submission=self.submission,
                                question=self.multiple_answer, value='0')
        Response.objects.create(submission=self.submission,
                                question=self.multiple_answer, value='1')

        a = self.multiple_answer.answer_set.get(value='1')
        column = QuestionColumn(self.hierarchy_one, self.multiple_answer, a)

        # identifier
        identifier = '%s_%s_%s' % (
            self.hierarchy_one.id, self.multiple_answer.id, a.id)
        self.assertEquals(column.identifier(), identifier)

        # key row
        identifier = '%s_%s' % (self.hierarchy_one.id, self.multiple_answer.id)
        key_row = ['one', identifier, 'Quiz', 'multiple choice',
                   b'multiple answer', a.id, a.label.encode('utf-8')]
        self.assertEquals(column.metadata(), key_row)

        # user value
        self.assertEquals(column.user_value(self.user), str(a.id))
        self.assertEquals(column.user_value(self.user2), None)
Esempio n. 4
0
    def test_user_value_multiple_responses(self):
        alt_single_answer = Question.objects.create(
            quiz=self.quiz, text='single answer 2',
            question_type='single choice')
        alt_answer_one = Answer.objects.create(
            question=alt_single_answer, label='Maybe', value='2')
        Answer.objects.create(
            question=alt_single_answer, label='Never', value='3')

        Response.objects.create(submission=self.submission,
                                question=self.short_text,
                                value='foo bar baz')
        Response.objects.create(submission=self.submission,
                                question=alt_single_answer,
                                value='2')
        Response.objects.create(submission=self.submission,
                                question=self.multiple_answer,
                                value='1')
        Response.objects.create(submission=self.submission,
                                question=self.single_answer,
                                value='0')

        column = QuestionColumn(self.hierarchy_one, self.single_answer)
        self.assertEquals(column.user_value(self.user),
                          str(self.single_answer_two.id))

        column = QuestionColumn(self.hierarchy_one, alt_single_answer)
        self.assertEquals(column.user_value(self.user),
                          str(alt_answer_one.id))

        column = QuestionColumn(self.hierarchy_one, self.multiple_answer,
                                self.multiple_answer_one)
        self.assertEquals(column.user_value(self.user),
                          str(self.multiple_answer_one.id))

        column = QuestionColumn(self.hierarchy_one, self.short_text)
        self.assertEquals(column.user_value(self.user), 'foo bar baz')