def test_element_has_name(self):
        document_schema = self.subnodes_data_handler.get_xsd("name")

        # Retrieving the needed elements
        sequence_xpath = "/xs:schema/xs:complexType/xs:sequence"
        sequence = document_schema.xpath(sequence_xpath, namespaces=self.namespace)[0]

        element_xpath = sequence_xpath + "/xs:element"
        elements = document_schema.xpath(element_xpath, namespaces=self.namespace)

        element_a = elements[0]
        element_b = elements[1]

        # Building resulting and expected structures
        xpath_result = get_nodes_xpath(sequence, document_schema)
        expected_result = [{"name": "a", "element": element_a}, {"name": "b", "element": element_b}]

        # Testing equality
        self.assertEqual(len(xpath_result), len(expected_result))

        for xpath in xpath_result:
            xpath_elem = xpath["element"]

            expected_elem_list = [expect["element"] for expect in expected_result if expect["name"] == xpath["name"]]
            expect_elem = expected_elem_list[0] if len(expected_elem_list) == 1 else None

            self.assertTrue(are_equals(xpath_elem, expect_elem))
    def test_imbricated_elements(self):
        document_schema = self.subnodes_data_handler.get_xsd("imbricated")

        complex_type_xpath = "/xs:schema/xs:complexType"
        complex_type = document_schema.xpath(complex_type_xpath, namespaces=self.namespace)[0]

        sequence_xpath = complex_type_xpath + "/xs:sequence"

        element_xpath = sequence_xpath + "/xs:element"
        element_a = document_schema.xpath(element_xpath, namespaces=self.namespace)[0]

        choice_element_xpath = sequence_xpath + "/xs:choice/xs:element"
        choice_elements = document_schema.xpath(choice_element_xpath, namespaces=self.namespace)

        element_b = choice_elements[0]
        element_c = choice_elements[1]

        xpath_result = get_nodes_xpath(complex_type, document_schema)
        expected_result = [
            {"name": "a", "element": element_a},
            {"name": "b", "element": element_b},
            {"name": "c", "element": element_c},
        ]

        self.assertEqual(len(xpath_result), len(expected_result))

        for xpath in xpath_result:
            xpath_elem = xpath["element"]

            expected_elem_list = [expect["element"] for expect in expected_result if expect["name"] == xpath["name"]]
            expect_elem = expected_elem_list[0] if len(expected_elem_list) == 1 else None

            self.assertTrue(are_equals(xpath_elem, expect_elem))
    def test_element_ref_local(self):
        document_schema = self.subnodes_data_handler.get_xsd("ref_local")

        complex_type_xpath = "/xs:schema/xs:complexType"
        complex_type = document_schema.xpath(complex_type_xpath, namespaces=self.namespace)[0]

        element_a_xpath = complex_type_xpath + "/xs:sequence/xs:element"
        element_a = document_schema.xpath(element_a_xpath, namespaces=self.namespace)[0]

        element_r0_xpath = "/xs:schema/xs:element"
        element_r0 = document_schema.xpath(element_r0_xpath, namespaces=self.namespace)[0]

        xpath_result = get_nodes_xpath(complex_type, document_schema)

        expected_result = [
            {"name": "a", "element": element_a},
            {"name": "r0", "element": element_r0},
            {"name": "r0", "element": element_r0},  # FIXME the 2nd element shouldn't be here (not needed)
        ]

        self.assertEqual(len(xpath_result), len(expected_result))

        for xpath in xpath_result:
            xpath_elem = xpath["element"]

            expected_elem_list = [expect["element"] for expect in expected_result if expect["name"] == xpath["name"]]
            # FIXME Having 2 element with the same content is not useful (>= 1 should be replaced by == 1)
            expect_elem = expected_elem_list[0] if len(expected_elem_list) >= 1 else None

            self.assertTrue(are_equals(xpath_elem, expect_elem))
    def test_not_element(self):
        document_schema = self.subnodes_data_handler.get_xsd("no_element")

        complex_type_xpath = "/xs:schema/xs:complexType"
        complex_type = document_schema.xpath(complex_type_xpath, namespaces=self.namespace)[0]

        xpath_result = get_nodes_xpath(complex_type, document_schema)

        self.assertEqual(xpath_result, [])
示例#5
0
    def test_not_element(self):
        document_schema = self.subnodes_data_handler.get_xsd('no_element')

        complex_type_xpath = '/xs:schema/xs:complexType'
        complex_type = document_schema.xpath(complex_type_xpath,
                                             namespaces=self.namespace)[0]

        xpath_result = get_nodes_xpath(complex_type, document_schema)

        self.assertEqual(xpath_result, [])
示例#6
0
    def test_imbricated_elements(self):
        document_schema = self.subnodes_data_handler.get_xsd('imbricated')

        complex_type_xpath = '/xs:schema/xs:complexType'
        complex_type = document_schema.xpath(complex_type_xpath,
                                             namespaces=self.namespace)[0]

        sequence_xpath = complex_type_xpath + '/xs:sequence'

        element_xpath = sequence_xpath + '/xs:element'
        element_a = document_schema.xpath(element_xpath,
                                          namespaces=self.namespace)[0]

        choice_element_xpath = sequence_xpath + '/xs:choice/xs:element'
        choice_elements = document_schema.xpath(choice_element_xpath,
                                                namespaces=self.namespace)

        element_b = choice_elements[0]
        element_c = choice_elements[1]

        xpath_result = get_nodes_xpath(complex_type, document_schema)
        expected_result = [
            {
                'name': 'a',
                'element': element_a
            },
            {
                'name': 'b',
                'element': element_b
            },
            {
                'name': 'c',
                'element': element_c
            },
        ]

        self.assertEqual(len(xpath_result), len(expected_result))

        for xpath in xpath_result:
            xpath_elem = xpath['element']

            expected_elem_list = [
                expect['element'] for expect in expected_result
                if expect['name'] == xpath['name']
            ]
            expect_elem = expected_elem_list[0] if len(
                expected_elem_list) == 1 else None

            self.assertTrue(are_equals(xpath_elem, expect_elem))
示例#7
0
    def test_element_ref_local(self):
        document_schema = self.subnodes_data_handler.get_xsd('ref_local')

        complex_type_xpath = '/xs:schema/xs:complexType'
        complex_type = document_schema.xpath(complex_type_xpath,
                                             namespaces=self.namespace)[0]

        element_a_xpath = complex_type_xpath + '/xs:sequence/xs:element'
        element_a = document_schema.xpath(element_a_xpath,
                                          namespaces=self.namespace)[0]

        element_r0_xpath = '/xs:schema/xs:element'
        element_r0 = document_schema.xpath(element_r0_xpath,
                                           namespaces=self.namespace)[0]

        xpath_result = get_nodes_xpath(complex_type, document_schema)

        expected_result = [
            {
                'name': 'a',
                'element': element_a
            },
            {
                'name': 'r0',
                'element': element_r0
            },
            {  # FIXME the 2nd element shouldn't be here (not needed)
                'name': 'r0',
                'element': element_r0
            }
        ]

        self.assertEqual(len(xpath_result), len(expected_result))

        for xpath in xpath_result:
            xpath_elem = xpath['element']

            expected_elem_list = [
                expect['element'] for expect in expected_result
                if expect['name'] == xpath['name']
            ]
            # FIXME Having 2 element with the same content is not useful (>= 1 should be replaced by == 1)
            expect_elem = expected_elem_list[0] if len(
                expected_elem_list) >= 1 else None

            self.assertTrue(are_equals(xpath_elem, expect_elem))
示例#8
0
    def test_element_has_name(self):
        document_schema = self.subnodes_data_handler.get_xsd('name')

        # Retrieving the needed elements
        sequence_xpath = '/xs:schema/xs:complexType/xs:sequence'
        sequence = document_schema.xpath(sequence_xpath,
                                         namespaces=self.namespace)[0]

        element_xpath = sequence_xpath + '/xs:element'
        elements = document_schema.xpath(element_xpath,
                                         namespaces=self.namespace)

        element_a = elements[0]
        element_b = elements[1]

        # Building resulting and expected structures
        xpath_result = get_nodes_xpath(sequence, document_schema)
        expected_result = [{
            'name': 'a',
            'element': element_a
        }, {
            'name': 'b',
            'element': element_b
        }]

        # Testing equality
        self.assertEqual(len(xpath_result), len(expected_result))

        for xpath in xpath_result:
            xpath_elem = xpath['element']

            expected_elem_list = [
                expect['element'] for expect in expected_result
                if expect['name'] == xpath['name']
            ]
            expect_elem = expected_elem_list[0] if len(
                expected_elem_list) == 1 else None

            self.assertTrue(are_equals(xpath_elem, expect_elem))