def test_import_same_namespace(self): path = 'tests/assets/same_namespace/same_namespace.wsdl' xml = utils.open_document(path) code = wsdl2py.generate_code_from_wsdl( xml, 'server', cwd=os.path.dirname(path)).decode() self.assertIn('Schema1_Element', code) self.assertIn('Schema2_Element', code)
def test_schema_xsd_include(self): path = 'tests/assets/include/include.wsdl' xml = utils.open_document(path) code = wsdl2py.generate_code_from_wsdl(xml, 'server', cwd=os.path.dirname(path)) if six.PY3: code = code.decode() assert_contains('Schema1_Element', code)
def test_relative_paths(self): path = 'tests/assets/relative/relative.wsdl' xml = utils.open_document(path) code = wsdl2py.generate_code_from_wsdl(xml, 'server', cwd=os.path.dirname(path)).decode() self.assertIn('Schema2_Element', code) self.assertIn('Schema3_Element', code) self.assertEqual(1, code.count('Schema3_Element'))
def test_can_generate_code_for_looped_wsdl_import(self): path = 'tests/assets/generation/import_looped.wsdl' xml = utils.open_document(path) code = wsdl2py.generate_code_from_wsdl(xml, 'client', cwd=os.path.dirname(path)) schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas)
def test_can_generate_code_for_two_schemas(self): xml = utils.open_document('tests/assets/generation/multi_schema.wsdl') code = wsdl2py.generate_code_from_wsdl(xml, 'client') schemas, symbols = generated_symbols(code) self.assertTrue(schemas) self.assertEqual(len([s for s in symbols if s.startswith('Schema_')]), 2) self.assertEqual(['A'], list(schemas[0].elements)) self.assertEqual(['B'], list(schemas[1].elements))
def test_relative_paths(self): path = 'tests/assets/relative/relative.wsdl' xml = open_document(path) code = generate_code_from_wsdl(xml, 'server', cwd=os.path.dirname(path)) if six.PY3: code = code.decode() assert_contains('Schema2_Element', code) assert_contains('Schema3_Element', code)
def test_can_generate_code_for_two_schemas(self): xml = utils.open_document('tests/assets/generation/multi_schema.wsdl') code = wsdl2py.generate_code_from_wsdl(xml, 'client') schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) assert_length(2, [s for s in symbols if s.startswith('Schema_')]) assert_equals(['A'], list(schemas[0].elements)) assert_equals(['B'], list(schemas[1].elements))
def test_import_same_namespace(self): path = 'tests/assets/same_namespace/same_namespace.wsdl' xml = open_document(path) code = generate_code_from_wsdl(xml, 'server', cwd=os.path.dirname(path)) if six.PY3: code = code.decode() assert_contains('Schema1_Element', code) assert_contains('Schema2_Element', code)
def test_can_generate_code_for_simple_wsdl_import(self): path = 'tests/assets/generation/import_simple.wsdl' xml = utils.open_document(path) code = wsdl2py.generate_code_from_wsdl(xml, 'client', cwd=os.path.dirname(path)) schemas, symbols = generated_symbols(code) self.assertTrue(schemas)
def test_can_generate_code_for_two_schemas(self): xml = utils.open_document("tests/assets/generation/multi_schema.wsdl") code = wsdl2py.generate_code_from_wsdl(xml, "client") schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) assert_length(4, symbols) assert_equals(["A"], list(schemas[0].elements)) assert_equals(["B"], list(schemas[1].elements))
def test_relative_paths(self): path = 'tests/assets/relative/relative.wsdl' xml = utils.open_document(path) code = wsdl2py.generate_code_from_wsdl(xml, 'server', cwd=os.path.dirname(path)) if six.PY3: code = code.decode() assert_contains('Schema2_Element', code) assert_contains('Schema3_Element', code) assert_equals(1, code.count('Schema3_Element'))
def test_can_generate_code_for_inheritance(self): xml = utils.open_document('tests/assets/generation/inheritance.wsdl') code = wsdl2py.generate_code_from_wsdl(xml, 'client') schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) assert_length(4, symbols) assert_equals(['B', 'A'], list(schemas[0].elements)) assert_isinstance(schemas[0].elements['B']._type, xsd.String) assert_isinstance(schemas[0].elements['A']._type, schemas[0].elements['B']._type.__class__)
def test_can_generate_code_for_inheritance(self): xml = utils.open_document('tests/assets/generation/inheritance.wsdl') code = wsdl2py.generate_code_from_wsdl(xml, 'client') schemas, symbols = generated_symbols(code) self.assertTrue(schemas) self.assertEqual(len(symbols), 4) self.assertEqual(['B', 'A'], list(schemas[0].elements)) self.assertIsInstance(schemas[0].elements['B']._type, xsd.String) self.assertIsInstance(schemas[0].elements['A']._type, schemas[0].elements['B']._type.__class__)
def test_can_generate_code_for_multiple_schemas(self): # raise SkipTest('can not generate code for wsdl with multiple schemas') code_string = wsdl2py.generate_code_from_wsdl(WSDL, 'client') schema, new_symbols = generated_symbols(code_string) assert_not_none(schema) assert_length(4, new_symbols) assert_equals(['B', 'A'], list(schema.elements))
def check_reparse_wsdl(self, base, target): xml = py2wsdl.tostring(base['PutOpsPort_SERVICE']) code = generate_code_from_wsdl(xml, target) m = {} self._exec(code, m) # XXX too much autonaming magic m['PutOpsPort_SERVICE'] = m.pop('PutOpsPortPort_SERVICE') if target == 'client': m['PutOpsPortServiceStub'] = m.pop('PutOpsPortPortServiceStub') assert_equals(sorted(m), sorted(base))
def check_reparse_wsdl(self, base, target): xml = py2wsdl.tostring(base['PutOpsPort_SERVICE']) code = generate_code_from_wsdl(xml, target) m = {} self._exec(code, m) # XXX too much autonaming magic m['PutOpsPort_SERVICE'] = m.pop('PutOpsPortPort_SERVICE') if target == 'client': m['PutOpsPortServiceStub'] = m.pop('PutOpsPortPortServiceStub') self.assertEqual(sorted(m), sorted(base))
def _check_reparse_wsdl(self, base, target): tree = py2wsdl.generate_wsdl(base['PutOpsPort_SERVICE']) xml = etree.tostring(tree, pretty_print=True) code = wsdl2py.generate_code_from_wsdl(xml, target) m = {} self._exec(code, m) # XXX too much autonaming magic m['PutOpsPort_SERVICE'] = m.pop('PutOpsPortPort_SERVICE') if target == 'client': m['PutOpsPortServiceStub'] = m.pop('PutOpsPortPortServiceStub') self.assertEqual(sorted(m), sorted(base))
def _check_reparse_wsdl(self, base, target): tree = py2wsdl.generate_wsdl(base['PutOpsPort_SERVICE']) xml = etree.tostring(tree, pretty_print=True) code = wsdl2py.generate_code_from_wsdl(xml, target) m = {} self._exec(code, m) # XXX too much autonaming magic m['PutOpsPort_SERVICE'] = m.pop('PutOpsPortPort_SERVICE') if target == 'client': m['PutOpsPortServiceStub'] = m.pop('PutOpsPortPortServiceStub') assert_equals(sorted(m), sorted(base))
def test_can_generate_remote_tree(self): def _mock(path): if path == 'http://example.org/xsd/simple_element.xsd': filename = 'tests/assets/generation/simple_element.xsd' else: self.fail('Unexpected remote path: %s' % path) with open(filename, 'rb') as f: return f.read() xml = utils.open_document('tests/assets/generation/import_remote.wsdl') with mock.patch('soapfish.xsd2py.open_document') as p: p.side_effect = _mock code = wsdl2py.generate_code_from_wsdl( xml, 'client', cwd='http://example.org/code/') schemas, symbols = generated_symbols(code)
def test_can_generate_code_for_inheritance(self): raise SkipTest('can not generate code for wsdl with type inheritance') xml = '<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">' \ ' <wsdl:types>' \ ' <xsd:schema elementFormDefault="qualified" targetNamespace="http://example.org/A">' \ ' <xsd:element name="A" type="B"/>' \ ' <xsd:element name="B" type="xsd:string"/>' \ ' </xsd:schema>' \ ' </wsdl:types>' \ '</wsdl:definitions>' code_string = wsdl2py.generate_code_from_wsdl(xml, 'client') schema, new_symbols = generated_symbols(code_string) assert_not_none(schema) assert_length(4, new_symbols) assert_equals(['B', 'A'], list(schema.elements)) assert_isinstance(schema.elements['B']._type, xsd.String) assert_isinstance(schema.elements['A']._type, schema.elements['B']._type.__class__)
def test_can_generate_code_for_two_schemas(self): # raise SkipTest('can not generate code for wsdl with multiple schemas') xml = '<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:b="http://example.org/B">' \ ' <wsdl:types>' \ ' <xsd:schema elementFormDefault="qualified" targetNamespace="http://example.org/A">' \ ' <xsd:import namespace="http://example.org/B"/>' \ ' <xsd:element name="A" type="b:B"/>' \ ' </xsd:schema>' \ ' <xsd:schema elementFormDefault="qualified" targetNamespace="http://example.org/B">' \ ' <xsd:element name="B" type="xsd:string"/>' \ ' </xsd:schema>' \ ' </wsdl:types>' \ '</wsdl:definitions>' code_string = wsdl2py.generate_code_from_wsdl(xml, 'client') schema, new_symbols = generated_symbols(code_string) assert_not_none(schema) assert_length(4, new_symbols) assert_equals(['B', 'A'], list(schema.elements))
def test_code_generation_from_wsdl_server(self): xml = utils.open_document('tests/assets/generation/default.wsdl') code = wsdl2py.generate_code_from_wsdl(xml, 'server') m = {} self._exec(code, m) self._check_reparse_wsdl(m, 'server')
def test_can_generate_code_for_hello(self): code_string = wsdl2py.generate_code_from_wsdl(WSDL_CHANGED, 'client') schema, new_symbols = generated_symbols(code_string) assert_not_none(schema)
def test_code_generation_from_wsdl_server(self): code = generate_code_from_wsdl(WSDL, 'server') m = {} self._exec(code, m) self.check_reparse_wsdl(m, 'server')
def test_code_generation_from_wsdl_client(self): code = generate_code_from_wsdl(WSDL, 'client') m = {} self._exec(code, m) self.check_reparse_wsdl(m, 'client')