Exemple #1
0
    def _parse_block(self, schema, questionnaire):
        """Parse a block element

        :param schema: The block schema

        :returns: A Block object

        :raises: SchemaParserException

        """
        block = Block()

        block.id = ParserUtils.get_required_string(schema, "id")
        block.title = ParserUtils.get_optional_string(schema, "title")
        block.type = ParserUtils.get_optional_string(schema, "type")

        # register the block
        questionnaire.register(block)

        if "sections" in schema.keys():
            for section_schema in schema['sections']:
                block.add_section(
                    self._parse_section(section_schema, questionnaire))
        else:
            raise SchemaParserException(
                'Block must contain at least one section')

        return block
    def _parse_block(self, schema, questionnaire):
        """Parse a block element

        :param schema: The block schema

        :returns: A Block object

        :raises: SchemaParserException

        """
        block = Block()

        try:
            block.id = ParserUtils.get_required_string(schema, "id")
            block.title = ParserUtils.get_optional_string(schema, "title")
            block.routing_rules = ParserUtils.get_optional_array(schema, 'routing_rules')

            # register the block
            questionnaire.register(block)

        except Exception as e:
            logging.error('Error parsing schema')
            logging.info(e)
            raise e

        if "sections" in schema.keys():
            for section_schema in schema['sections']:
                block.add_section(self._parse_section(section_schema, questionnaire))
        else:
            raise SchemaParserException('Block must contain at least one section')

        return block
Exemple #3
0
    def test_basics(self):
        block = Block()

        block.id = 'some-id'
        block.title = 'my block object'

        section1 = Section()
        section1.id = 'section-1'
        section2 = Section()
        section2.id = 'section-2'

        block.add_section(section1)
        block.add_section(section2)

        self.assertEqual(block.id, 'some-id')
        self.assertEqual(block.title, 'my block object')
        self.assertIsNone(block.container)
        self.assertEqual(len(block.sections), 2)
        self.assertEqual(block.sections[0], section1)
        self.assertEqual(block.sections[1], section2)

        self.assertEqual(section1.container, block)
        self.assertEqual(section2.container, block)
    def test_basics(self):
        block = Block()

        block.id = 'some-id'
        block.title = 'my block object'

        section1 = Section()
        section1.id = 'section-1'
        section2 = Section()
        section2.id = 'section-2'

        block.add_section(section1)
        block.add_section(section2)

        self.assertEquals(block.id, 'some-id')
        self.assertEquals(block.title, 'my block object')
        self.assertIsNone(block.container)
        self.assertEquals(len(block.sections), 2)
        self.assertEquals(block.sections[0], section1)
        self.assertEquals(block.sections[1], section2)

        self.assertEquals(section1.container, block)
        self.assertEquals(section2.container, block)