コード例 #1
0
    def test_basics(self):
        question = Question()

        question.id = 'some-id'
        question.title = 'my question object'
        question.description = 'fill this in'

        answer1 = Answer()
        answer1.id = 'answer-1'
        answer2 = Answer()
        answer2.id = 'answer-2'

        question.add_answer(answer1)
        question.add_answer(answer2)

        self.assertEquals(question.id, 'some-id')
        self.assertEquals(question.title, 'my question object')
        self.assertEquals(question.description, 'fill this in')
        self.assertIsNone(question.container)
        self.assertEquals(len(question.answers), 2)
        self.assertEquals(question.answers[0], answer1)
        self.assertEquals(question.answers[1], answer2)

        self.assertEquals(answer1.container, question)
        self.assertEquals(answer2.container, question)
コード例 #2
0
    def test_basics(self):
        question = Question()

        question.id = 'some-id'
        question.title = 'my question object'
        question.description = 'fill this in'

        answer1 = Answer()
        answer1.id = 'answer-1'
        answer2 = Answer()
        answer2.id = 'answer-2'

        question.add_answer(answer1)
        question.add_answer(answer2)

        self.assertEqual(question.id, 'some-id')
        self.assertEqual(question.title, 'my question object')
        self.assertEqual(question.description, 'fill this in')
        self.assertIsNone(question.container)
        self.assertEqual(len(question.answers), 2)
        self.assertEqual(question.answers[0], answer1)
        self.assertEqual(question.answers[1], answer2)

        self.assertEqual(answer1.container, question)
        self.assertEqual(answer2.container, question)
コード例 #3
0
    def test_convert_answers(self):
        with self.application.test_request_context():
            user_answer = [create_answer('ABC', '2016-01-01', group_id='group-1', block_id='block-1'),
                           create_answer('DEF', '2016-03-30', group_id='group-1', block_id='block-1')]

            answer_1 = Answer()
            answer_1.id = "ABC"
            answer_1.code = "001"

            answer_2 = Answer()
            answer_2.id = "DEF"
            answer_2.code = "002"

            question = Question()
            question.id = 'question-1'
            question.add_answer(answer_1)
            question.add_answer(answer_2)

            section = Section()
            section.add_question(question)

            block = Block()
            block.id = 'block-1'
            block.add_section(section)

            group = Group()
            group.id = 'group-1'
            group.add_block(block)

            questionnaire = Questionnaire()
            questionnaire.survey_id = "021"
            questionnaire.data_version = "0.0.1"
            questionnaire.add_group(group)

            questionnaire.register(group)
            questionnaire.register(block)
            questionnaire.register(section)
            questionnaire.register(question)
            questionnaire.register(answer_1)
            questionnaire.register(answer_2)

            routing_path = [Location(group_id='group-1', group_instance=0, block_id='block-1')]
            answer_object = convert_answers(metadata, questionnaire, AnswerStore(user_answer), routing_path)

            self.assertEqual(answer_object['type'], 'uk.gov.ons.edc.eq:surveyresponse')
            self.assertEqual(answer_object['version'], '0.0.1')
            self.assertEqual(answer_object['origin'], 'uk.gov.ons.edc.eq')
            self.assertEqual(answer_object['survey_id'], '021')
            self.assertEqual(answer_object['collection']['exercise_sid'], metadata['collection_exercise_sid'])
            self.assertEqual(answer_object['collection']['instrument_id'], metadata['form_type'])
            self.assertEqual(answer_object['collection']['period'], metadata['period_id'])
            self.assertEqual(answer_object['metadata']['user_id'], metadata['user_id'])
            self.assertEqual(answer_object['metadata']['ru_ref'], metadata['ru_ref'])
            self.assertEqual(answer_object['data']['001'], '2016-01-01')
            self.assertEqual(answer_object['data']['002'], '2016-03-30')
コード例 #4
0
    def test_answer_with_multiple_instances(self):
        with self.application.test_request_context():
            user_answer = [create_answer('GHI', 0, group_id='group-1', block_id='block-1'),
                           create_answer('GHI', value=1, answer_instance=1, group_id='group-1', block_id='block-1'),
                           create_answer('GHI', value=2, answer_instance=2, group_id='group-1', block_id='block-1')]

            answer = Answer()
            answer.id = "GHI"
            answer.code = "003"

            question = Question()
            question.id = 'question-2'
            question.add_answer(answer)

            section = Section()
            section.add_question(question)

            block = Block()
            block.id = 'block-1'
            block.add_section(section)

            group = Group()
            group.id = 'group-1'
            group.add_block(block)

            questionnaire = Questionnaire()
            questionnaire.survey_id = "021"
            questionnaire.data_version = "0.0.1"
            questionnaire.add_group(group)
            questionnaire.register(question)
            questionnaire.register(answer)

            routing_path = [Location(group_id='group-1', group_instance=0, block_id='block-1')]

            answer_object = convert_answers(metadata, questionnaire, AnswerStore(user_answer), routing_path)

            # Check the converter correctly
            self.assertEqual(answer_object["data"]["003"], ['0', '1', '2'])
コード例 #5
0
    def test_converter_checkboxes_with_q_codes_and_other_value(self):
        with self.application.test_request_context():
            routing_path = [Location(group_id='favourite food', group_instance=0, block_id='crisps')]
            answers = [create_answer('crisps-answer', ['Ready salted', 'other', 'Bacon'], group_id='favourite food', block_id='crisps')]

            answer = CheckboxAnswer()
            answer.id = "crisps-answer"
            answer.code = ""
            answer.options = [
                {
                    "label": "Ready salted",
                    "value": "Ready salted",
                    "q_code": "1"
                },
                {
                    "label": "Sweet chilli",
                    "value": "Sweet chilli",
                    "q_code": "2"
                },
                {
                    "label": "Cheese and onion",
                    "value": "Cheese and onion",
                    "q_code": "3"
                },
                {
                    "label": "Other",
                    "value": "other",
                    "q_code": "4",
                    "description": "Choose any other flavour",
                    "other": {
                        "label": "Please specify other"
                    }
                }
            ]

            question = Question()
            question.id = 'crisps-question'
            question.add_answer(answer)

            section = Section()
            section.add_question(question)

            block = Block()
            block.id = 'crisps'
            block.add_section(section)

            group = Group()
            group.id = 'favourite food'
            group.add_block(block)

            questionnaire = Questionnaire()
            questionnaire.survey_id = "999"
            questionnaire.data_version = "0.0.1"
            questionnaire.add_group(group)
            questionnaire.register(question)
            questionnaire.register(answer)

            # When
            answer_object = convert_answers(metadata, questionnaire, AnswerStore(answers), routing_path)

            # Then
            self.assertEqual(len(answer_object['data']), 2)
            self.assertEqual(answer_object['data']['1'], 'Ready salted')
            self.assertEqual(answer_object['data']['4'], 'Bacon')