class ParserCreateRestrictionTestSuite(TestCase): """""" def setUp(self): restriction_data = join(RESOURCES_PATH, "parser", "restriction") self.restriction_data_handler = DataHandler(restriction_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser() def _run_test(self, xsd_files): xsd_tree = self.restriction_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath("/xs:schema/xs:simpleType/xs:restriction", namespaces=self.namespaces)[0] result_dict = self.parser.generate_restriction(xsd_element, xsd_tree, full_path="/root") expected_dict = self.restriction_data_handler.get_json(xsd_files) return result_dict, expected_dict def test_enumeration(self): xsd_files = join("enumeration", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_simple_type(self): xsd_files = join("simple_type", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict)
def setUp(self): restriction_data = join(RESOURCES_PATH, "parser", "restriction") self.restriction_data_handler = DataHandler(restriction_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser()
def setUp(self): element_data = join(RESOURCES_PATH, 'parser', 'element') self.element_data_handler = DataHandler(element_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {'xs': SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser()
def setUp(self): # Setup data handler complex_type_data = join(RESOURCES_PATH, "parser", "complex_type") self.complex_type_data_handler = DataHandler(complex_type_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser()
def setUp(self): choice_data = join(RESOURCES_PATH, "parser", "choice") self.choice_data_handler = DataHandler(choice_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser() self.parser.editing = True
def setUp(self): # Init data path element_data = join(RESOURCES_PATH, 'parser', 'element') self.element_data_handler = DataHandler(element_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {'xs': SCHEMA_NAMESPACE} # Get an instance of the XSDParser with editing enabled self.parser = XSDParser() self.parser.editing = True
def setUp(self): # Init data path retriction_data = join(RESOURCES_PATH, "parser", "restriction") self.restriction_data_handler = DataHandler(retriction_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser with editing enabled self.parser = XSDParser() self.parser.editing = True
class ParserReloadRestrictionTestSuite(TestCase): """""" def setUp(self): # Init data path retriction_data = join(RESOURCES_PATH, "parser", "restriction") self.restriction_data_handler = DataHandler(retriction_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser with editing enabled self.parser = XSDParser() self.parser.editing = True def _run_test(self, xsd_files): xsd_tree = self.restriction_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath("/xs:schema/xs:simpleType/xs:restriction", namespaces=self.namespaces)[0] xml_tree = self.restriction_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_restriction( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree, default_value=edit_data_tree.text, ) # Load expected dictionary and compare with result expected_dict = self.restriction_data_handler.get_json(xsd_files + ".reload") return result_dict, expected_dict def test_enumeration(self): xsd_files = join("enumeration", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_simple_type(self): xsd_files = join("simple_type", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(expected_dict, result_dict)
class ParserCreateComplexContentTestSuite(TestCase): """""" maxDiff = None def setUp(self): # Setup data handler complex_content_data = join(RESOURCES_PATH, "parser", "complex_content") self.complex_content_data_handler = DataHandler(complex_content_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser() def test_create_extension_basic(self): xsd_files = join("extension", "basic") xsd_tree = self.complex_content_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element/xs:complexType/xs:complexContent", namespaces=self.namespaces, )[0] result_string = self.parser.generate_complex_content(xsd_element, xsd_tree, full_path="/root") expected_dict = self.complex_content_data_handler.get_json(xsd_files) self.assertDictEqual(result_string, expected_dict) def test_create_restriction_basic(self): xsd_files = join("restriction", "basic") xsd_tree = self.complex_content_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element/xs:complexType/xs:complexContent", namespaces=self.namespaces, )[0] # Generate result dict result_string = self.parser.generate_complex_content(xsd_element, xsd_tree, full_path="/root") # Load expected dictionary and compare with result expected_dict = self.complex_content_data_handler.get_json(xsd_files) self.assertDictEqual(result_string, expected_dict)
class ParserReloadExtensionTestSuite(TestCase): """""" def setUp(self): # Init data path extension_data = join(RESOURCES_PATH, "parser", "extension") self.extension_data_handler = DataHandler(extension_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser with editing enabled self.parser = XSDParser() self.parser.editing = True def test_generate_extension_with_multiple_children_returns_expected_json_dict( self): xsd_files = join("multiple", "basic") xsd_tree = self.extension_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension", namespaces=self.namespaces, )[0] xml_tree = self.extension_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_extension( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree, default_value=edit_data_tree, ) # Load expected dictionary and compare with result expected_dict = self.extension_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_dict, result_dict) def test_generate_extension_with_single_child_attribute_returns_expected_json_dict( self, ): xsd_files = join("attribute", "single") xsd_tree = self.extension_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element/xs:complexType/xs:simpleContent/xs:extension", namespaces=self.namespaces, )[0] xml_tree = self.extension_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_extension( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree, default_value="entry0", ) # Load expected dictionary and compare with result expected_dict = self.extension_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_dict, result_dict) def test_generate_extension_with_single_child_choice_returns_expected_json_dict( self, ): xsd_files = join("choice", "single") xsd_tree = self.extension_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension", namespaces=self.namespaces, )[0] xml_tree = self.extension_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_extension( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree) # Load expected dictionary and compare with result expected_dict = self.extension_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_dict, result_dict) def test_generate_extension_with_single_child_sequence_returns_expected_json_dict( self, ): xsd_files = join("sequence", "single") xsd_tree = self.extension_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension", namespaces=self.namespaces, )[0] xml_tree = self.extension_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_extension( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree) # Load expected dictionary and compare with result expected_dict = self.extension_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_dict, result_dict)
class ParserReloadElementTestSuite(TestCase): maxDiff = None def setUp(self): # Init data path element_data = join(RESOURCES_PATH, 'parser', 'element') self.element_data_handler = DataHandler(element_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {'xs': SCHEMA_NAMESPACE} # Get an instance of the XSDParser with editing enabled self.parser = XSDParser() self.parser.editing = True def test_reload_simple_type_basic(self): xsd_files = join('simple_type', 'basic') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath('/xs:schema/xs:element', namespaces=self.namespaces)[0] xml_tree = self.element_data_handler.get_xml(xsd_files) xml_data = etree.tostring(xml_tree) edit_data_tree = etree.XML(str(xml_data.encode('utf-8'))) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path='', edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files+".reload") self.assertDictEqual(expected_dict, result_dict) def test_reload_simple_type_basic_ns(self): xsd_files = join('simple_type', 'basic_ns') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath('/xs:schema/xs:element', namespaces=self.namespaces)[0] xml_tree = self.element_data_handler.get_xml(xsd_files.replace("_ns", "")) xml_data = etree.tostring(xml_tree) edit_data_tree = etree.XML(str(xml_data.encode('utf-8'))) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path='', edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files+".reload") self.assertDictEqual(expected_dict, result_dict) def test_reload_simple_type_unbounded(self): xsd_files = join('simple_type', 'unbounded') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( '/xs:schema/xs:complexType/xs:sequence/xs:element', namespaces=self.namespaces )[0] xml_tree = self.element_data_handler.get_xml(xsd_files) xml_data = etree.tostring(xml_tree) edit_data_tree = etree.XML(str(xml_data.encode('utf-8'))) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path='/ex:root[1]', edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files+".reload") self.assertDictEqual(expected_dict, result_dict) def test_reload_simple_type_unbounded_ns(self): xsd_files = join('simple_type', 'unbounded_ns') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( '/xs:schema/xs:complexType/xs:sequence/xs:element', namespaces=self.namespaces )[0] xml_tree = self.element_data_handler.get_xml(xsd_files) xml_data = etree.tostring(xml_tree) edit_data_tree = etree.XML(str(xml_data.encode('utf-8'))) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path='/root[1]', edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files+".reload") self.assertDictEqual(expected_dict, result_dict) def test_reload_complex_type_basic(self): xsd_files = join('complex_type', 'basic') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath('/xs:schema/xs:element', namespaces=self.namespaces)[0] xml_tree = self.element_data_handler.get_xml(xsd_files) xml_data = etree.tostring(xml_tree) edit_data_tree = etree.XML(str(xml_data.encode('utf-8'))) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path='', edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files+".reload") self.assertDictEqual(expected_dict, result_dict) def test_create_complex_type_unbounded(self): xsd_files = join('complex_type', 'unbounded') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( '/xs:schema/xs:complexType/xs:sequence/xs:element', namespaces=self.namespaces )[0] xml_tree = self.element_data_handler.get_xml(xsd_files) xml_data = etree.tostring(xml_tree) edit_data_tree = etree.XML(str(xml_data.encode('utf-8'))) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path='/root', edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files+".reload") self.assertDictEqual(expected_dict, result_dict)
class ParserReloadSequenceTestSuite(TestCase): """""" maxDiff = None def setUp(self): # Init data path sequence_data = join(RESOURCES_PATH, "parser", "sequence") self.sequence_data_handler = DataHandler(sequence_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser with editing enabled self.parser = XSDParser() self.parser.editing = True def _run_test(self, xsd_files): xsd_tree = self.sequence_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath("/xs:schema/xs:complexType/xs:sequence", namespaces=self.namespaces)[0] xml_tree = self.sequence_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_sequence( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree) # Load expected dictionary and compare with result expected_dict = self.sequence_data_handler.get_json(xsd_files + ".reload") return result_dict, expected_dict def test_reload_element_basic(self): xsd_files = join("element", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_reload_element_unbounded(self): # fixme correct bug xsd_files = join("element", "unbounded") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_reload_choice_basic(self): xsd_files = join("choice", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_reload_choice_unbounded(self): xsd_files = join("choice", "unbounded") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_reload_sequence_basic(self): xsd_files = join("sequence", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_reload_sequence_unbounded(self): xsd_files = join("sequence", "unbounded") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_reload_multiple_basic(self): xsd_files = join("multiple", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_reload_multiple_unbounded(self): xsd_files = join("multiple", "unbounded") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict)
class ParserReloadElementTestSuite(TestCase): def setUp(self): # Init data path element_data = join(RESOURCES_PATH, "parser", "element") self.element_data_handler = DataHandler(element_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser with editing enabled self.parser = XSDParser() self.parser.editing = True def test_reload_simple_type_basic(self): xsd_files = join("simple_type", "basic") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element", namespaces=self.namespaces )[0] xml_tree = self.element_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path="", edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_dict, result_dict) def test_reload_simple_type_basic_ns(self): xsd_files = join("simple_type", "basic_ns") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element", namespaces=self.namespaces )[0] xml_tree = self.element_data_handler.get_xml(xsd_files.replace("_ns", "")) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path="", edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_dict, result_dict) def test_reload_simple_type_unbounded(self): xsd_files = join("simple_type", "unbounded") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType/xs:sequence/xs:element", namespaces=self.namespaces, )[0] xml_tree = self.element_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path="/ex:root[1]", edit_data_tree=edit_data_tree, ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_dict, result_dict) def test_reload_simple_type_unbounded_ns(self): xsd_files = join("simple_type", "unbounded_ns") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType/xs:sequence/xs:element", namespaces=self.namespaces, )[0] xml_tree = self.element_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path="/root[1]", edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_dict, result_dict) def test_reload_complex_type_basic(self): xsd_files = join("complex_type", "basic") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element", namespaces=self.namespaces )[0] xml_tree = self.element_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path="", edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_dict, result_dict) def test_create_complex_type_unbounded(self): xsd_files = join("complex_type", "unbounded") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType/xs:sequence/xs:element", namespaces=self.namespaces, )[0] xml_tree = self.element_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_dict, result_dict)
class ParserCreateComplexTypeTestSuite(TestCase): """Element creation unit tests""" def setUp(self): # Setup data handler complex_type_data = join(RESOURCES_PATH, "parser", "complex_type") self.complex_type_data_handler = DataHandler(complex_type_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser() def test_create_choice_basic(self): xsd_files = join("choice", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root" ) expected_dict = self.complex_type_data_handler.get_json(xsd_files) self.assertDictEqual(result_string, expected_dict) def test_create_sequence_basic(self): xsd_files = join("sequence", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root" ) expected_dict = self.complex_type_data_handler.get_json(xsd_files) self.assertDictEqual(result_string, expected_dict) def test_create_simple_content_basic(self): xsd_files = join("simple_content", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root" ) expected_dict = self.complex_type_data_handler.get_json(xsd_files) self.assertDictEqual(result_string, expected_dict) def test_create_complex_content_basic(self): xsd_files = join("complex_content", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root" ) expected_dict = self.complex_type_data_handler.get_json(xsd_files) self.assertDictEqual(result_string, expected_dict) def test_create_attribute_basic(self): xsd_files = join("attribute", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root" ) expected_dict = self.complex_type_data_handler.get_json(xsd_files) self.assertDictEqual(result_string, expected_dict) def test_create_multiple_basic(self): xsd_files = join("multiple", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root" ) expected_dict = self.complex_type_data_handler.get_json(xsd_files) self.assertDictEqual(result_string, expected_dict)
class ParserGenerateElementTestSuite(TestCase): maxDiff = None def setUp(self): element_data = join(RESOURCES_PATH, 'parser', 'element') self.element_data_handler = DataHandler(element_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {'xs': SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser() def test_create_simple_type_basic(self): xsd_files = join('simple_type', 'basic') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath('/xs:schema/xs:element', namespaces=self.namespaces)[0] # Generate result dict result_dict = self.parser.generate_element(xsd_element, xsd_tree, full_path='') # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_create_simple_type_basic_ns(self): xsd_files = join('simple_type', 'basic_ns') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath('/xs:schema/xs:element', namespaces=self.namespaces)[0] # Generate result dict result_dict = self.parser.generate_element(xsd_element, xsd_tree, full_path='') # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_create_simple_type_unbounded(self): xsd_files = join('simple_type', 'unbounded') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( '/xs:schema/xs:complexType/xs:sequence/xs:element', namespaces=self.namespaces )[0] # Generate result dict result_dict = self.parser.generate_element(xsd_element, xsd_tree, full_path='/ex:root[1]') # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_create_simple_type_unbounded_ns(self): xsd_files = join('simple_type', 'unbounded_ns') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( '/xs:schema/xs:complexType/xs:sequence/xs:element', namespaces=self.namespaces )[0] # Generate result dict result_dict = self.parser.generate_element(xsd_element, xsd_tree, full_path='/root[1]') # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_create_complex_type_basic(self): xsd_files = join('complex_type', 'basic') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath('/xs:schema/xs:element', namespaces=self.namespaces)[0] # generate result dict result_dict = self.parser.generate_element(xsd_element, xsd_tree, full_path='') # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_create_complex_type_unbounded(self): xsd_files = join('complex_type', 'unbounded') xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( '/xs:schema/xs:complexType/xs:sequence/xs:element', namespaces=self.namespaces )[0] # Generate result dict result_dict = self.parser.generate_element(xsd_element, xsd_tree, full_path='/root') # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict)
class ParserCreateExtensionTestSuite(TestCase): """""" def setUp(self): extension_data = join(RESOURCES_PATH, "parser", "extension") self.extension_data_handler = DataHandler(extension_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser() def test_generate_extension_with_multiple_children_returns_expected_json_dict( self): xsd_files = join("multiple", "basic") xsd_tree = self.extension_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension", namespaces=self.namespaces, )[0] result_dict = self.parser.generate_extension(xsd_element, xsd_tree, full_path="/root") expected_dict = self.extension_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_generate_extension_with_single_child_attribute_returns_expected_json_dict( self, ): xsd_files = join("attribute", "single") xsd_tree = self.extension_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element/xs:complexType/xs:simpleContent/xs:extension", namespaces=self.namespaces, )[0] result_dict = self.parser.generate_extension(xsd_element, xsd_tree, full_path="/root") expected_dict = self.extension_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_generate_extension_with_single_child_choice_returns_expected_json_dict( self, ): xsd_files = join("choice", "single") xsd_tree = self.extension_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension", namespaces=self.namespaces, )[0] result_dict = self.parser.generate_extension(xsd_element, xsd_tree, full_path="/root") expected_dict = self.extension_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_generate_extension_with_single_child_sequence_returns_expected_json_dict( self, ): xsd_files = join("sequence", "single") xsd_tree = self.extension_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension", namespaces=self.namespaces, )[0] result_dict = self.parser.generate_extension(xsd_element, xsd_tree, full_path="/root") expected_dict = self.extension_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict)
class ParserGenerateElementTestSuite(TestCase): def setUp(self): element_data = join(RESOURCES_PATH, "parser", "element") self.element_data_handler = DataHandler(element_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser() def test_create_simple_type_basic(self): xsd_files = join("simple_type", "basic") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element", namespaces=self.namespaces )[0] # Generate result dict result_dict = self.parser.generate_element(xsd_element, xsd_tree, full_path="") # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_create_simple_type_basic_ns(self): xsd_files = join("simple_type", "basic_ns") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element", namespaces=self.namespaces )[0] # Generate result dict result_dict = self.parser.generate_element(xsd_element, xsd_tree, full_path="") # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_create_simple_type_unbounded(self): xsd_files = join("simple_type", "unbounded") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType/xs:sequence/xs:element", namespaces=self.namespaces, )[0] # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path="/ex:root[1]" ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_create_simple_type_unbounded_ns(self): xsd_files = join("simple_type", "unbounded_ns") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType/xs:sequence/xs:element", namespaces=self.namespaces, )[0] # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path="/root[1]" ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_create_complex_type_basic(self): xsd_files = join("complex_type", "basic") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:element", namespaces=self.namespaces )[0] # generate result dict result_dict = self.parser.generate_element(xsd_element, xsd_tree, full_path="") # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict) def test_create_complex_type_unbounded(self): xsd_files = join("complex_type", "unbounded") xsd_tree = self.element_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType/xs:sequence/xs:element", namespaces=self.namespaces, )[0] # Generate result dict result_dict = self.parser.generate_element( xsd_element, xsd_tree, full_path="/root" ) # Load expected dictionary and compare with result expected_dict = self.element_data_handler.get_json(xsd_files) self.assertDictEqual(expected_dict, result_dict)
class ParserReloadChoiceTestSuite(TestCase): """""" def setUp(self): choice_data = join(RESOURCES_PATH, "parser", "choice") self.choice_data_handler = DataHandler(choice_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser() self.parser.editing = True def test_reload_element_basic(self): xsd_files = join("element", "basic") xsd_tree = self.choice_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath("/xs:schema/xs:complexType/xs:choice", namespaces=self.namespaces)[0] xml_tree = self.choice_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) result_string = self.parser.generate_choice( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree) expected_element = self.choice_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_element, result_string) def test_reload_element_unbounded(self): xsd_files = join("element", "unbounded") xsd_tree = self.choice_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath("/xs:schema/xs:complexType/xs:choice", namespaces=self.namespaces)[0] xml_tree = self.choice_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) result_string = self.parser.generate_choice( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree) expected_element = self.choice_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_element, result_string) def test_reload_sequence_basic(self): xsd_files = join("sequence", "basic") xsd_tree = self.choice_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath("/xs:schema/xs:complexType/xs:choice", namespaces=self.namespaces)[0] xml_tree = self.choice_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) result_string = self.parser.generate_choice( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree) expected_element = self.choice_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_element, result_string) def test_reload_sequence_unbounded(self): xsd_files = join("sequence", "unbounded") xsd_tree = self.choice_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath("/xs:schema/xs:complexType/xs:choice", namespaces=self.namespaces)[0] xml_tree = self.choice_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) result_string = self.parser.generate_choice( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree) expected_element = self.choice_data_handler.get_json(xsd_files + ".reload") self.assertDictEqual(expected_element, result_string)
class ParserCreateSequenceTestSuite(TestCase): """Test creation of elements under sequence""" def setUp(self): sequence_data = join(RESOURCES_PATH, "parser", "sequence") self.sequence_data_handler = DataHandler(sequence_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser() def _run_test(self, xsd_files): xsd_xpath = "/xs:schema/xs:complexType/xs:sequence" xsd_tree = self.sequence_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath(xsd_xpath, namespaces=self.namespaces)[0] result_dict = self.parser.generate_sequence(xsd_element, xsd_tree, full_path="/root") expected_dict = self.sequence_data_handler.get_json(xsd_files) return result_dict, expected_dict def test_create_element_basic(self): xsd_files = join("element", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_create_element_unbounded(self): xsd_files = join("element", "unbounded") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_create_choice_basic(self): xsd_files = join("choice", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_create_choice_unbounded(self): xsd_files = join("choice", "unbounded") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_create_sequence_basic(self): xsd_files = join("sequence", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_create_sequence_unbounded(self): xsd_files = join("sequence", "unbounded") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_create_multiple_basic(self): xsd_files = join("multiple", "basic") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict) def test_create_multiple_unbounded(self): xsd_files = join("multiple", "unbounded") result_dict, expected_dict = self._run_test(xsd_files) self.assertDictEqual(result_dict, expected_dict)
class ParserReloadComplexTypeTestSuite(TestCase): """Element reload unit tests""" def setUp(self): complex_type_data = join(RESOURCES_PATH, "parser", "complex_type") self.complex_type_data_handler = DataHandler(complex_type_data) # Set default namespace self.namespace = LXML_SCHEMA_NAMESPACE self.namespaces = {"xs": SCHEMA_NAMESPACE} # Get an instance of the XSDParser self.parser = XSDParser() self.parser.editing = True def test_reload_choice_basic(self): xsd_files = join("choice", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] xml_tree = self.complex_type_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.complex_type_data_handler.get_json("%s.reload" % xsd_files) self.assertDictEqual(result_string, expected_dict) def test_reload_sequence_basic(self): xsd_files = join("sequence", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] xml_tree = self.complex_type_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.complex_type_data_handler.get_json("%s.reload" % xsd_files) self.assertDictEqual(result_string, expected_dict) def test_reload_simple_content_basic(self): xsd_files = join("simple_content", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] xml_tree = self.complex_type_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) xml_value = xml_tree.xpath("/root", namespaces=self.namespaces)[0].text # Generate result dict result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree, default_value=xml_value, ) # Load expected dictionary and compare with result expected_dict = self.complex_type_data_handler.get_json("%s.reload" % xsd_files) self.assertDictEqual(result_string, expected_dict) def test_reload_complex_content_basic(self): xsd_files = join("complex_content", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] xml_tree = self.complex_type_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.complex_type_data_handler.get_json("%s.reload" % xsd_files) self.assertDictEqual(result_string, expected_dict) def test_reload_attribute_basic(self): xsd_files = join("attribute", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] xml_tree = self.complex_type_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.complex_type_data_handler.get_json("%s.reload" % xsd_files) self.assertDictEqual(result_string, expected_dict) def test_reload_multiple_basic(self): xsd_files = join("multiple", "basic") xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files) xsd_element = xsd_tree.xpath( "/xs:schema/xs:complexType", namespaces=self.namespaces )[0] xml_tree = self.complex_type_data_handler.get_xml(xsd_files) xml_data = XSDTree.tostring(xml_tree) edit_data_tree = XSDTree.transform_to_xml(xml_data) # Generate result dict result_string = self.parser.generate_complex_type( xsd_element, xsd_tree, full_path="/root", edit_data_tree=edit_data_tree ) # Load expected dictionary and compare with result expected_dict = self.complex_type_data_handler.get_json("%s.reload" % xsd_files) self.assertDictEqual(result_string, expected_dict)