Esempio n. 1
0
    def test_can_generate_code_with_xsd_refs_to_elements_with_anoynmous_complex_types(self):
        # The final test should have an object graph representation of the
        # schema below. Currently I don't know how to represent multiple
        # xs:elements in a schema without using ComplexTypes.
        # Maybe we should have a special type like AnonymousComplexType and
        # put that directly into schema.elements?
        xml = utils.open_document('tests/assets/generation/reference_complex.xsd')
        schema = xsdspec.Schema.parse_xmlelement(etree.fromstring(xml))
        code = xsd2py.schema_to_py(schema, ['xs'])

        schemas, symbols = generated_symbols(code)
        assert_is_not_empty(schemas)
        assert_length(3, symbols)
        assert_contains('Person', symbols.keys())
        assert_contains('Job', symbols.keys())

        assert_equals(set(['person', 'job']), list(schemas[0].elements))

        Job = symbols['Job']
        Person = symbols['Person']
        person_ref = Job.person
        assert_isinstance(person_ref, xsd.Ref)
        assert_equals(person_ref._type, Person)

        job = Job()
        person = Person()
        person.name = 'Foo'
        job.person = person
Esempio n. 2
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)
Esempio n. 3
0
    def test_can_generate_code_with_xsd_refs_to_elements_with_anoynmous_complex_types(
            self):
        # The final test should have an object graph representation of the
        # schema below. Currently I don't know how to represent multiple
        # xs:elements in a schema without using ComplexTypes.
        # Maybe we should have a special type like AnonymousComplexType and
        # put that directly into schema.elements?
        xml = utils.open_document(
            'tests/assets/generation/reference_complex.xsd')
        schema = xsdspec.Schema.parse_xmlelement(etree.fromstring(xml))
        code = xsd2py.schema_to_py(schema, ['xs'])

        schemas, symbols = generated_symbols(code)
        assert_is_not_empty(schemas)
        assert_length(3, symbols)
        assert_contains('Person', symbols.keys())
        assert_contains('Job', symbols.keys())

        assert_equals(set(['person', 'job']), list(schemas[0].elements))

        Job = symbols['Job']
        Person = symbols['Person']
        person_ref = Job.person
        assert_isinstance(person_ref, xsd.Ref)
        assert_equals(person_ref._type, Person)

        job = Job()
        person = Person()
        person.name = 'Foo'
        job.person = person
Esempio n. 4
0
    def test_can_generate_code_with_xsd_refs_to_simple_elements(self):
        xml = utils.open_document('tests/assets/generation/reference_simple.xsd')
        code = xsd2py.generate_code_from_xsd(xml)

        schemas, symbols = generated_symbols(code)
        assert_is_not_empty(schemas)
        # somehow we need to be able to have schemas with multiple possible
        # root elements
        assert_length(3, symbols)
        assert_contains('Name', symbols.keys())
        assert_contains('Job', symbols.keys())

        assert_equals(set(['name', 'job']), list(schemas[0].elements))

        Job = symbols['Job']
        Name = symbols['Name']
        name_ref = Job.name
        # not sure if these assertions are correct but they should give you
        # the idea
        assert_isinstance(name_ref, xsd.Ref)
        assert_equals(name_ref._type, Name)

        job = Job()
        # Should not raise
        job.name = u'Foo'
Esempio n. 5
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)
Esempio n. 6
0
    def test_can_generate_code_with_xsd_refs_to_simple_elements(self):
        xml = utils.open_document(
            'tests/assets/generation/reference_simple.xsd')
        code = xsd2py.generate_code_from_xsd(xml)

        schemas, symbols = generated_symbols(code)
        assert_is_not_empty(schemas)
        # somehow we need to be able to have schemas with multiple possible
        # root elements
        assert_length(3, symbols)
        assert_contains('Name', symbols.keys())
        assert_contains('Job', symbols.keys())

        assert_equals(set(['name', 'job']), list(schemas[0].elements))

        Job = symbols['Job']
        Name = symbols['Name']
        name_ref = Job.name
        # not sure if these assertions are correct but they should give you
        # the idea
        assert_isinstance(name_ref, xsd.Ref)
        assert_equals(name_ref._type, Name)

        job = Job()
        # Should not raise
        job.name = u'Foo'
Esempio n. 7
0
 def test_schema_xsd_restriction(self):
     xml = utils.open_document('tests/assets/generation/restriction.xsd')
     code = xsd2py.generate_code_from_xsd(xml)
     if six.PY3:
         code = code.decode()
     assert_contains('RestrictedString', code)
     assert_contains("pattern=r'[a-z]+'", code)
Esempio n. 8
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'))
Esempio n. 9
0
 def test_schema_xsd_restriction(self):
     xml = utils.open_document('tests/assets/generation/restriction.xsd')
     code = xsd2py.generate_code_from_xsd(xml)
     if six.PY3:
         code = code.decode()
     assert_contains('RestrictedString', code)
     assert_contains("pattern=r'[a-z]+'", code)
Esempio n. 10
0
    def test_can_generate_code_with_xsd_refs_to_simple_elements(self):
        xml = utils.open_document('tests/assets/generation/reference_simple.xsd')
        code = xsd2py.generate_code_from_xsd(xml)

        schemas, symbols = generated_symbols(code)
        self.assertTrue(schemas)
        # somehow we need to be able to have schemas with multiple possible
        # root elements
        self.assertEqual(len(symbols), 3)
        self.assertIn('Name', symbols.keys())
        self.assertIn('Job', symbols.keys())

        self.assertEqual({'job', 'name'}, list(schemas[0].elements))

        Job = symbols['Job']
        Name = symbols['Name']
        name_ref = Job.name
        # not sure if these assertions are correct but they should give you
        # the idea
        self.assertIsInstance(name_ref, xsd.Ref)
        self.assertEqual(name_ref._type, Name)

        job = Job()
        # Should not raise
        job.name = 'Foo'
Esempio n. 11
0
 def test_schema_xsd_enumeration(self):
     xml = utils.open_document('tests/assets/generation/enumeration2.xsd')
     code = xsd2py.generate_code_from_xsd(xml)
     m = {}
     try:
         self._exec(code, m)
     except SyntaxError as e:
         self.fail('%s: %s' % (e.__class__.__name__, e))
Esempio n. 12
0
 def test_can_generate_extension_of_type_with_special_chars(self):
     xml = utils.open_document(
         'tests/assets/generation/extension_with_special_chars.xsd')
     code = xsd2py.generate_code_from_xsd(xml)
     schemas, symbols = generated_symbols(code)
     assert_true('BaseType_with_special_chars_123' in symbols)
     assert_equals('BaseType_with_special_chars_123',
                   symbols['ComplexType'].__base__.__name__)
 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))
Esempio n. 14
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))
Esempio n. 15
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)
Esempio n. 16
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))
Esempio n. 17
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)
 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))
Esempio n. 19
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)
Esempio n. 20
0
 def test_create_method_list_param(self):
     xml = utils.open_document('tests/assets/generation/list_param.xsd')
     code = xsd2py.generate_code_from_xsd(xml)
     if six.PY3:
         code = code.decode()
     assert_contains('def create(cls, Items):', code)
     assert_contains('instance.Items = Items', code)
     assert_not_contains('Itemss', code)
Esempio n. 21
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)
Esempio n. 22
0
 def test_create_method_list_param(self):
     xml = utils.open_document('tests/assets/generation/list_param.xsd')
     code = xsd2py.generate_code_from_xsd(xml)
     if six.PY3:
         code = code.decode()
     assert_contains('def create(cls, Items):', code)
     assert_contains('instance.Items = Items', code)
     assert_not_contains('Itemss', code)
 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__)
Esempio n. 24
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__)
Esempio n. 25
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__)
Esempio n. 26
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'))
Esempio n. 27
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)
Esempio n. 28
0
 def test_schema_xsd_enumeration(self):
     xml = utils.open_document('tests/assets/generation/enumeration2.xsd')
     code = xsd2py.generate_code_from_xsd(xml)
     if six.PY3:
         code = code.decode()
     m = {}
     try:
         self._exec(code, m)
     except SyntaxError as e:
         self.fail('%s: %s' % (e.__class__.__name__, e))
Esempio n. 29
0
    def test_can_generate_list_enumeration(self):
        xml = utils.open_document('tests/assets/generation/enumeration.xsd')
        code = xsd2py.generate_code_from_xsd(xml)
        schemas, symbols = generated_symbols(code)
        self.assertTrue(schemas)
        self.assertEqual(len(symbols), 2)

        self.assertIs(issubclass(symbols['MyList'], xsd.List), True)

        my_list = symbols['MyList']()
        self.assertIs(my_list.accept(['B']), True)
Esempio n. 30
0
    def test_can_generate_list_enumeration(self):
        xml = utils.open_document('tests/assets/generation/enumeration.xsd')
        code = xsd2py.generate_code_from_xsd(xml)
        schemas, symbols = generated_symbols(code)
        assert_is_not_empty(schemas)
        assert_length(2, symbols)

        assert_true(issubclass(symbols['MyList'], xsd.List))

        my_list = symbols['MyList']()
        assert_equals(my_list.accept(['B']), True)
Esempio n. 31
0
    def test_can_generate_code_for_simple_element(self):
        xml = utils.open_document('tests/assets/generation/simple_element.xsd')
        code = xsd2py.generate_code_from_xsd(xml)

        schemas, symbols = generated_symbols(code)
        assert_is_not_empty(schemas)
        assert_length(1, symbols)

        assert_equals(['simpleElement'], list(schemas[0].elements))
        simple_element = schemas[0].elements['simpleElement']
        assert_isinstance(simple_element._type, xsd.String)
Esempio n. 32
0
    def test_can_generate_code_for_simple_element(self):
        xml = utils.open_document('tests/assets/generation/simple_element.xsd')
        code = xsd2py.generate_code_from_xsd(xml)

        schemas, symbols = generated_symbols(code)
        self.assertTrue(schemas)
        self.assertEqual(len([s for s in symbols if s.startswith('Schema_')]), 1)

        self.assertEqual(['simpleElement'], list(schemas[0].elements))
        simple_element = schemas[0].elements['simpleElement']
        self.assertIsInstance(simple_element._type, xsd.String)
Esempio n. 33
0
    def test_can_generate_code_for_simple_element(self):
        xml = utils.open_document('tests/assets/generation/simple_element.xsd')
        code = xsd2py.generate_code_from_xsd(xml)

        schemas, symbols = generated_symbols(code)
        assert_is_not_empty(schemas)
        assert_length(1, symbols)

        assert_equals(['simpleElement'], list(schemas[0].elements))
        simple_element = schemas[0].elements['simpleElement']
        assert_isinstance(simple_element._type, xsd.String)
Esempio n. 34
0
    def test_can_generate_list_enumeration(self):
        xml = utils.open_document('tests/assets/generation/enumeration.xsd')
        code = xsd2py.generate_code_from_xsd(xml)
        schemas, symbols = generated_symbols(code)
        assert_is_not_empty(schemas)
        assert_length(2, symbols)

        assert_true(issubclass(symbols['MyList'], xsd.List))

        my_list = symbols['MyList']()
        assert_equals(my_list.accept(['B']), True)
Esempio n. 35
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)
    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)
Esempio n. 37
0
    def test_can_generate_extension_imported(self):
        xml = utils.open_document('tests/assets/generation/extension_imported.xsd')
        code = xsd2py.generate_code_from_xsd(xml, cwd='tests/assets/generation')
        schemas, symbols = generated_symbols(code)
        self.assertTrue(schemas)

        base = symbols['Base']
        base.Field1
        try:
            base.Field2
        except AttributeError:
            pass
        else:
            self.fail('Unexpected base.Field2')

        ct = symbols['ComplexType']
        ct.Field1
        ct.Field2
Esempio n. 38
0
    def test_can_generate_extension_imported(self):
        xml = utils.open_document('tests/assets/generation/extension_imported.xsd')
        code = xsd2py.generate_code_from_xsd(xml, cwd='tests/assets/generation')
        schemas, symbols = generated_symbols(code)
        assert_is_not_empty(schemas)

        base = symbols['Base']
        base.Field1
        try:
            base.Field2
        except AttributeError:
            pass
        else:
            self.fail('Unexpected base.Field2')

        ct = symbols['ComplexType']
        ct.Field1
        ct.Field2
Esempio n. 39
0
 def test_code_generation_from_xsd(self):
     xml = utils.open_document('tests/assets/generation/default.xsd')
     # Add mandatory imports to test the generated code
     code = xsd2py.generate_code_from_xsd(xml)
     self._exec(code, {})
Esempio n. 40
0
 def test_can_generate_extension_of_type_with_special_chars(self):
     xml = utils.open_document('tests/assets/generation/extension_with_special_chars.xsd')
     code = xsd2py.generate_code_from_xsd(xml)
     schemas, symbols = generated_symbols(code)
     assert_true('BaseType_with_special_chars_123' in symbols)
     assert_equals('BaseType_with_special_chars_123', symbols['ComplexType'].__base__.__name__)
 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)
Esempio n. 42
0
 def test_create_method_list_param(self):
     xml = utils.open_document('tests/assets/generation/list_param.xsd')
     code = xsd2py.generate_code_from_xsd(xml).decode()
     self.assertIn('def create(cls, Items):', code)
     self.assertIn('instance.Items = Items', code)
     self.assertNotIn('Itemss', code)
Esempio n. 43
0
 def test_schema_xsd_restriction(self):
     xml = utils.open_document('tests/assets/generation/restriction.xsd')
     code = xsd2py.generate_code_from_xsd(xml).decode()
     self.assertIn('RestrictedString', code)
     self.assertIn("pattern=r'[a-z]+'", code)
Esempio n. 44
0
 def test_can_generate_extension(self):
     xml = utils.open_document('tests/assets/generation/extension.xsd')
     code = xsd2py.generate_code_from_xsd(xml)
     schemas, symbols = generated_symbols(code)
Esempio n. 45
0
 def test_implicit_target_namespace(self):
     xml = utils.open_document('tests/assets/generation/implicit_namespace.xsd')
     schema = xsdspec.Schema.parse_xmlelement(etree.fromstring(xml))
     xsd2py.schema_to_py(schema, ['xs'], parent_namespace='http://site.example/ws/spec')
Esempio n. 46
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')
Esempio n. 47
0
 def test_implicit_target_namespace(self):
     xml = utils.open_document(
         'tests/assets/generation/implicit_namespace.xsd')
     schema = xsdspec.Schema.parse_xmlelement(etree.fromstring(xml))
     xsd2py.schema_to_py(schema, ['xs'],
                         parent_namespace='http://site.example/ws/spec')
Esempio n. 48
0
 def test_code_generation_from_xsd(self):
     xml = utils.open_document('tests/assets/generation/default.xsd')
     # Add mandatory imports to test the generated code
     code = xsd2py.generate_code_from_xsd(xml)
     self._exec(code, {})
 def setUp(self):
     xsd_str = utils.open_document('tests/assets/generation/attrgroup_usage.xsd')
     self.code = xsd2py.generate_code_from_xsd(xsd_str)
 def setUp(self):
     xsd_str = utils.open_document('tests/assets/generation/attribute_usage.xsd')
     code = xsd2py.generate_code_from_xsd(xsd_str)
     self.schemas, self.symbols = testutil.generated_symbols(code)
     self.SampleType = self.symbols['SampleType']
Esempio n. 51
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')
Esempio n. 52
0
 def test_can_generate_extension(self):
     xml = utils.open_document('tests/assets/generation/extension.xsd')
     code = xsd2py.generate_code_from_xsd(xml)
     schemas, symbols = generated_symbols(code)