Example #1
0
def validateXMLDocument(xml_string, xsd_string):

    xsd_tree = etree.parse(StringIO(xsd_string.encode('utf-8')))
    xml_tree = etree.parse(StringIO(xml_string.encode('utf-8')))

    errors = validate_xml_data(xsd_tree, xml_tree)
    if errors is not None:
        raise Exception(errors)
def validateXMLDocument(xml_string, xsd_string):

    xsd_tree = etree.parse(StringIO(xsd_string.encode('utf-8')))
    xml_tree = etree.parse(StringIO(xml_string.encode('utf-8')))

    errors = validate_xml_data(xsd_tree, xml_tree)
    if errors is not None:
        raise Exception(errors)
    def test_import_external_nok(self):
        # load template
        template_path = join(RESOURCES_PATH, 'import-external.xsd')
        self.load_template(template_path)

        # load data
        data_path = join(RESOURCES_PATH, 'import_external_nok.xml')
        self.load_data(data_path)

        # test LXML
        if TEST_LXML:
            self.assertNotEquals(_lxml_validate_xml(self.xsd_tree, self.xml_tree), None)
        # test global method
        self.assertNotEquals(validate_xml_data(self.xsd_tree, self.xml_tree), None)
Example #4
0
def validateXMLDocument(xml_string, xsd_string):

    xsd_tree = etree.parse(StringIO(xsd_string.encode('utf-8')))
    xml_tree = etree.parse(StringIO(xml_string.encode('utf-8')))

    errors = validate_xml_data(xsd_tree, xml_tree)
    if errors is not None:
        raise Exception(errors)

    # test no root
    root = xml_tree.getroot()

    if '{http://www.w3.org/2001/XMLSchema-instance}type' in root.attrib:
        if root.attrib['{http://www.w3.org/2001/XMLSchema-instance}type'] != root.tag:
            raise Exception("Unsupported use of xsi:type, type name should match root tag name.")
    def test_no_root_ok(self):
        # load template
        template_path = join(RESOURCES_PATH, 'no_root.xsd')
        self.load_template(template_path)

        # load data
        data_path = join(RESOURCES_PATH, 'no_root_ok.xml')
        self.load_data(data_path)

        # test LXML
        # TODO: LXML fails to validate
        if TEST_LXML:
            self.assertEquals(_lxml_validate_xml(self.xsd_tree, self.xml_tree), None)
        # test global method
        self.assertEquals(validate_xml_data(self.xsd_tree, self.xml_tree), None)
Example #6
0
    def test_import_external_nok(self):
        # load template
        template_path = join(RESOURCES_PATH, 'import-external.xsd')
        self.load_template(template_path)

        # load data
        data_path = join(RESOURCES_PATH, 'import_external_nok.xml')
        self.load_data(data_path)

        # test LXML
        if TEST_LXML:
            self.assertNotEquals(
                _lxml_validate_xml(self.xsd_tree, self.xml_tree), None)
        # test global method
        self.assertNotEquals(validate_xml_data(self.xsd_tree, self.xml_tree),
                             None)
Example #7
0
    def test_no_root_ok(self):
        # load template
        template_path = join(RESOURCES_PATH, 'no_root.xsd')
        self.load_template(template_path)

        # load data
        data_path = join(RESOURCES_PATH, 'no_root_ok.xml')
        self.load_data(data_path)

        # test LXML
        # TODO: LXML fails to validate
        if TEST_LXML:
            self.assertEquals(_lxml_validate_xml(self.xsd_tree, self.xml_tree),
                              None)
        # test global method
        self.assertEquals(validate_xml_data(self.xsd_tree, self.xml_tree),
                          None)
    def test_import_django_nok(self):
        # load type
        type_path = join(RESOURCES_PATH, 'to-import.xsd')
        type_object = self.load_type(type_path)

        # load template
        template_path = join(RESOURCES_PATH, 'import.xsd')
        self.load_template(template_path)

        update_dependencies(self.xsd_tree, {'to-import.xsd': str(type_object.id)})
        self.xsd_string = etree.tostring(self.xsd_tree)

        # load data
        data_path = join(RESOURCES_PATH, 'import_nok.xml')
        self.load_data(data_path)

        # test LXML
        if TEST_LXML:
            self.assertNotEquals(_lxml_validate_xml(self.xsd_tree, self.xml_tree), None)
        # test global method
        self.assertNotEquals(validate_xml_data(self.xsd_tree, self.xml_tree), None)
Example #9
0
    def test_import_django_nok(self):
        # load type
        type_path = join(RESOURCES_PATH, 'to-import.xsd')
        type_object = self.load_type(type_path)

        # load template
        template_path = join(RESOURCES_PATH, 'import.xsd')
        self.load_template(template_path)

        update_dependencies(self.xsd_tree,
                            {'to-import.xsd': str(type_object.id)})
        self.xsd_string = etree.tostring(self.xsd_tree)

        # load data
        data_path = join(RESOURCES_PATH, 'import_nok.xml')
        self.load_data(data_path)

        # test LXML
        if TEST_LXML:
            self.assertNotEquals(
                _lxml_validate_xml(self.xsd_tree, self.xml_tree), None)
        # test global method
        self.assertNotEquals(validate_xml_data(self.xsd_tree, self.xml_tree),
                             None)