Esempio n. 1
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. 2
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. 3
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. 4
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. 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)
     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_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_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. 8
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)
 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. 10
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. 11
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. 12
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. 13
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. 14
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. 15
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. 16
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
 def assert_fail(self, value, message=None):
     return assert_raises(AssertionError, lambda: assert_is_not_empty(value, message=message))
 def test_passes_if_value_is_not_empty(self):
     assert_is_not_empty((1,))
     assert_is_not_empty([1])
     assert_is_not_empty('foo')
 def test_passes_if_value_is_not_empty(self):
     assert_is_not_empty((1, ))
     assert_is_not_empty([1])
     assert_is_not_empty('foo')
 def assert_fail(self, value, message=None):
     return assert_raises(
         AssertionError,
         lambda: assert_is_not_empty(value, message=message))
 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_consume_generator_if_necessary(self):
        def generator():
            for i in (1, 2, 3):
                yield i

        assert_is_not_empty(generator())