Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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'))
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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))
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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))
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 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))
Exemplo n.º 11
0
 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))
Exemplo n.º 12
0
 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'))
Exemplo n.º 13
0
 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__)
Exemplo n.º 14
0
 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__)
Exemplo n.º 15
0
    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))
Exemplo n.º 16
0
 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__)
Exemplo n.º 17
0
 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))
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
 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))
Exemplo n.º 20
0
 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))
Exemplo n.º 21
0
 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))
Exemplo n.º 22
0
    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)
Exemplo n.º 23
0
    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)
Exemplo n.º 24
0
    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__)
Exemplo n.º 25
0
    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))
Exemplo n.º 26
0
 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)
Exemplo n.º 27
0
 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')
Exemplo n.º 28
0
    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)
Exemplo n.º 29
0
 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')
Exemplo n.º 30
0
 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')
Exemplo n.º 31
0
 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')
Exemplo n.º 32
0
 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')
Exemplo n.º 33
0
 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')