예제 #1
0
    def test_should_parse_answer():
        # Load the json file as a dict
        schema_file = open(
            os.path.join(os.path.dirname(__file__),
                         'test_schemas/mci-mini.json'))
        schema = schema_file.read()
        schema = json.loads(schema)

        # create a parser
        parser = SchemaParser(schema)
        questionnaire = parser.parse()

        # Check the answer properties
        group = questionnaire.groups[0]
        block = group.blocks[0]
        section = block.sections[0]
        question = section.questions[0]
        assert len(question.answers) == 1
        assert isinstance(question.answers[0], Answer)
        answer = question.answers[0]
        assert answer.id == "29586b4c-fb0c-4755-b67d-b3cd398cb30a"
        assert answer.code == "110"
        assert answer.label == "Male employees working more than 30 hours per week?"
        assert answer.guidance == "How many men work for your company?"
        assert answer.type == "Integer"

        # check the answer properties on question 2
        question_two = section.questions[1]
        answer = question_two.answers[0]
        assert answer.type == "TextArea"
예제 #2
0
파일: schema.py 프로젝트: qateam123/eq
def load_and_parse_schema(eq_id, form_type, language_code):
    """
    Use the schema loader to get the schema from disk. Then use the parse to construct the object schema
    :param eq_id: the id of the questionnaire
    :param form_type: the form type
    :return: (json, schema) # Tuple of json and schema object from schema file
    """
    # load the schema

    json_schema = load_schema(eq_id, form_type, language_code)
    if json_schema:
        parser = SchemaParser(json_schema)
        schema = parser.parse()
        return json_schema, schema
    else:
        raise ValueError("No schema available")
예제 #3
0
    def setUp(self):
        application = Flask(__name__)
        application.config['TESTING'] = True
        application.secret_key = 'you will not guess'
        application.permanent_session_lifetime = timedelta(seconds=1)

        login_manager.init_app(application)
        self.application = application
        with self.application.test_client() as c:
            with c.session_transaction() as sess:
                sess['user_id'] = '1'

        schema_file = open(
            os.path.join(settings.EQ_SCHEMA_DIRECTORY, "0_star_wars.json"))
        schema = schema_file.read()
        # create a parser
        self.schema_json = json.loads(schema)
        parser = SchemaParser(self.schema_json)
        parser.parse()
예제 #4
0
    def test_should_parse_group():
        # Load the json file as a dict
        schema_file = open(
            os.path.join(os.path.dirname(__file__),
                         'test_schemas/mci-mini.json'))
        schema = schema_file.read()
        schema = json.loads(schema)

        # create a parser
        parser = SchemaParser(schema)
        questionnaire = parser.parse()

        # check the group properties
        assert len(questionnaire.groups) == 1
        assert isinstance(questionnaire.groups[0], Group)
        group = questionnaire.groups[0]

        assert group.id == "14ba4707-321d-441d-8d21-b8367366e766"
        assert group.title == ""
예제 #5
0
    def test_parse_block():
        # Load the json file as a dict
        schema_file = open(
            os.path.join(os.path.dirname(__file__),
                         'test_schemas/mci-mini.json'))
        schema = schema_file.read()
        schema = json.loads(schema)

        # create a parser
        parser = SchemaParser(schema)

        questionnaire = parser.parse()

        # check the block properties
        group = questionnaire.groups[0]
        block = group.blocks[0]
        assert len(group.blocks) == 1
        assert isinstance(group.blocks[0], Block)
        assert block.id == "cd3b74d1-b687-4051-9634-a8f9ce10a27d"
        assert block.title == "Monthly Business Survey"
예제 #6
0
    def test_should_parse_introduction(self):
        # Load the json file as a dict
        schema_file = open(
            os.path.join(os.path.dirname(__file__),
                         'test_schemas/mci-mini-with-intro.json'))
        schema = schema_file.read()
        schema = json.loads(schema)

        # create a parser
        parser = SchemaParser(schema)
        questionnaire = parser.parse()

        # check the questionniare properties
        assert isinstance(questionnaire, Questionnaire)
        self.assertIsNotNone(questionnaire.introduction)
        self.assertIsInstance(questionnaire.introduction, Introduction)
        self.assertEqual(questionnaire.introduction.legal,
                         "<b>This is the legal bit.</b>")
        self.assertEqual(questionnaire.introduction.description,
                         "<p>This is the description.</p>")
예제 #7
0
    def test_should_parse_section():
        # Load the json file as a dict
        schema_file = open(
            os.path.join(os.path.dirname(__file__),
                         'test_schemas/mci-mini.json'))
        schema = schema_file.read()
        schema = json.loads(schema)

        # create a parser
        parser = SchemaParser(schema)
        questionnaire = parser.parse()

        # Check the parser version
        assert parser.get_parser_version() == '0.0.1'

        # check the section properties
        group = questionnaire.groups[0]
        block = group.blocks[0]
        section = block.sections[0]
        assert len(block.sections) == 1
        assert isinstance(block.sections[0], Section)
        assert section.id == "2cd99c83-186d-493a-a16d-17cb3c8bd302"
        assert section.title == ""
예제 #8
0
    def test_should_parse_questionnaire():
        # Load the json file as a dict
        schema_file = open(
            os.path.join(os.path.dirname(__file__),
                         'test_schemas/mci-mini.json'))
        schema = schema_file.read()
        schema = json.loads(schema)

        # create a parser
        parser = SchemaParser(schema)

        questionnaire = parser.parse()

        # Check the parser version
        assert parser.get_parser_version() == '0.0.1'

        # check the questionniare properties
        assert isinstance(questionnaire, Questionnaire)
        assert questionnaire.id == "22"
        assert questionnaire.survey_id == "23"
        assert questionnaire.title == "Monthly Business Survey - Retail Sales Index"
        assert questionnaire.description == "MCI description"
        assert len(questionnaire.groups) == 1
        assert isinstance(questionnaire.groups[0], Group)
예제 #9
0
    def test_should_parse_question():
        # Load the json file as a dict
        schema_file = open(
            os.path.join(os.path.dirname(__file__),
                         'test_schemas/mci-mini.json'))
        schema = schema_file.read()
        schema = json.loads(schema)

        # create a parser
        parser = SchemaParser(schema)
        questionnaire = parser.parse()

        # check the question properties
        group = questionnaire.groups[0]
        block = group.blocks[0]
        section = block.sections[0]
        assert len(section.questions) == 2
        assert isinstance(section.questions[0], Question)
        question = section.questions[0]
        assert question.id == "4ba2ec8a-582f-4985-b4ed-20355deba55a"
        assert question.title == "On 12 January 2016 what was the number of employees for the business named above?"
        assert question.description == "An employee is anyone aged 16 years or over that your organisation directly " \
                                       "pays from its payroll(s), in return for carrying out a full-time or part-time " \
                                       "job or being on a training scheme."