def test_can_generate_schema_xml_containing_types_with_pattern_restriction(self):
        ns = 'http://soap.example/pattern.xsd'

        class Container(xsd.ComplexType):
            code = xsd.Element(xsd.String(pattern='[0-9]{0,5}'))
        schema = xsd.Schema(ns,
                            location=ns,
                            elementFormDefault=xsd.ElementFormDefault.QUALIFIED,
                            complexTypes=(
                                Container,
                            ),
                            elements={
                                'foo': xsd.Element(Container),
                            },
                            )
        # previously this would fail
        xsd_element = generate_xsd(schema)
        xmlschema = etree.XMLSchema(xsd_element)
        valid_xml = '<foo xmlns="%s"><code>1234</code></foo>' % ns

        def is_valid(s):
            return xmlschema.validate(etree.fromstring(s))
        assert_true(is_valid(valid_xml))

        bad_xml = '<foo xmlns="%s"><code>abc</code></foo>' % ns
        assert_false(is_valid(bad_xml))
示例#2
0
 def assert_is_valid(self, xml_string, soapfish_schema):
     xml = etree.fromstring(xml_string)
     xmlschema = etree.XMLSchema(generate_xsd(soapfish_schema))
     assert_true(
         xmlschema.validate(xml),
         message="XML did not validate: %r" % xml_string
     )
示例#3
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__)
示例#4
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)
示例#5
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)
示例#6
0
    def test_service_bind_function(self):
        handler, handler_state = echo_handler()
        service = echo_service(handler)

        @service.route('echoOperation')
        def echo_func(request, input_):
            handler_state.new_func_was_called = True
            return handler(request, input_)

        dispatcher = SOAPDispatcher(service)
        soap_message = (
            '<ns1:echoRequest xmlns:ns1="http://soap.example/echo/types">'
            '<value>foobar</value>'
            '</ns1:echoRequest>')
        request_message = self._wrap_with_soap_envelope(soap_message)
        request = SOAPRequest(dict(SOAPACTION='echo', REQUEST_METHOD='POST'),
                              request_message)
        response = dispatcher.dispatch(request)

        assert_true(handler_state.new_func_was_called)
        self.assert_is_successful_response(response, handler_state)
示例#7
0
    def test_service_bind_function(self):
        handler, handler_state = echo_handler()
        service = echo_service(handler)

        @service.route('echoOperation')
        def echo_func(request, input_):
            handler_state.new_func_was_called = True
            return handler(request, input_)

        dispatcher = SOAPDispatcher(service)
        soap_message = (
            '<ns1:echoRequest xmlns:ns1="http://soap.example/echo/types">'
            '<value>foobar</value>'
            '</ns1:echoRequest>'
        )
        request_message = self._wrap_with_soap_envelope(soap_message)
        request = SOAPRequest(dict(SOAPACTION='echo', REQUEST_METHOD='POST'),
                              request_message)
        response = dispatcher.dispatch(request)

        assert_true(handler_state.new_func_was_called)
        self.assert_is_successful_response(response, handler_state)
示例#8
0
 def assert_is_successful_response(self, response, handler_state=None):
     assert_equals(200, response.http_status_code)
     assert_equals('text/xml', response.http_headers['Content-Type'])
     if handler_state:
         assert_true(handler_state.was_called)
示例#9
0
 def assert_is_valid(self, xml_string, soapfish_schema):
     xml = etree.fromstring(xml_string)
     xmlschema = etree.XMLSchema(generate_xsd(soapfish_schema))
     assert_true(xmlschema.validate(xml),
                 message='XML did not validate: %r' % xml_string)
示例#10
0
 def assert_is_successful_response(self, response, handler_state=None):
     assert_equals(200, response.http_status_code)
     assert_equals('text/xml', response.http_headers['Content-Type'])
     if handler_state:
         assert_true(handler_state.was_called)
 def assert_fail(self, value, message=None):
     return assert_raises(AssertionError, lambda: assert_true(value, message=message))
 def test_exports_all_assert_methods_for_star_imports(self):
     exported_methods = pythonic_testcase.__all__
     for symbol_name in dir(pythonic_testcase):
         if symbol_name.startswith('assert_'):
             msg = '%r not exported in __all__' % symbol_name
             assert_true(symbol_name in exported_methods, message=msg)
 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__)
示例#14
0
 def test_passes_if_value_is_true(self):
     assert_true(True)
示例#15
0
 def test_exports_all_assert_methods_for_star_imports(self):
     exported_methods = pythonic_testcase.__all__
     for symbol_name in dir(pythonic_testcase):
         if symbol_name.startswith('assert_'):
             msg = '%r not exported in __all__' % symbol_name
             assert_true(symbol_name in exported_methods, message=msg)
示例#16
0
 def assert_fail(self, value, message=None):
     return assert_raises(AssertionError,
                          lambda: assert_true(value, message=message))
 def test_passes_if_value_is_true(self):
     assert_true(True)