Permalink
Browse files

strict type checking

  • Loading branch information...
1 parent 9d7b4fc commit 2665e1c3f54284d4c59ea1e119e80d7c46c8da0f @baverman committed Apr 6, 2012
Showing with 19 additions and 10 deletions.
  1. +13 −4 dropthesoap/schema/xs.py
  2. +2 −2 dropthesoap/service.py
  3. +2 −2 tests/test_schema.py
  4. +2 −2 tests/test_service.py
View
@@ -366,10 +366,6 @@ def init(instance, value):
def fill_node(cls, node, instance, _creator):
node.text = cls.from_python(instance.value)
- @staticmethod
- def from_python(value):
- return unicode(value)
-
@classmethod
def from_node(cls, node):
return cls.to_python(node.text)
@@ -378,6 +374,11 @@ def from_node(cls, node):
class string(_FinalSimpleType):
namespace = namespace
+ @staticmethod
+ def from_python(value):
+ assert isinstance(value, basestring), 'Value should be a string not %s' % (type(value))
+ return value
+
@staticmethod
def to_python(value):
return value
@@ -398,6 +399,10 @@ def to_python(value):
class int(_FinalSimpleType):
namespace = namespace
+ @staticmethod
+ def from_python(value):
+ return str(value)
+
@staticmethod
def to_python(value):
return _int(value)
@@ -406,6 +411,10 @@ def to_python(value):
class float(_FinalSimpleType):
namespace = namespace
+ @staticmethod
+ def from_python(value):
+ return str(value)
+
@staticmethod
def to_python(value):
return _float(value)
View
@@ -192,10 +192,10 @@ def call(self, transport_request, xml):
response = self.dispatch(ctx, request)
except Fault as e:
- response = soap.Fault.instance(faultcode=e.code, faultstring=str(e))
+ response = soap.Fault.instance(faultcode=e.code, faultstring=e.message)
except Exception as e:
logger.exception('Exception during soap request:')
- response = soap.Fault.instance(faultcode='Server', faultstring=str(e),
+ response = soap.Fault.instance(faultcode='Server', faultstring=e.message,
detail=traceback.format_exc())
renvelope = soap.Envelope.instance(Body=soap.Body.instance(_any=[response]))
View
@@ -15,10 +15,10 @@ def test_simple_schema():
AddResponse
)
- assert validate(schema, AddRequest.instance(x=10, y=15))
+ assert validate(schema, AddRequest.instance(x='10', y='15'))
assert validate(schema, AddResponse.instance(15))
- obj = schema.fromstring(tostring(AddRequest.instance(x=11, y=12)))
+ obj = schema.fromstring(tostring(AddRequest.instance(x='11', y='12')))
assert obj.x == '11'
assert obj.y == 12
View
@@ -48,13 +48,13 @@ def test_complex_return_type():
@service.expose(returns=ResponseType)
def add(x=xs.int, y=xs.int):
- return ResponseType.instance(foo=x+y, bar=x-y)
+ return ResponseType.instance(foo=str(x+y), bar=str(x-y))
#open('/tmp/wow.xml', 'w').write(service.get_wsdl('http://localhost/'))
cl = Client('some address', transport=DirectSudsTransport(service), cache=None)
- result = cl.service.add(1, 10)
+ result = cl.service.add('1', '10')
assert result.foo == '11'
assert result.bar == '-9'

0 comments on commit 2665e1c

Please sign in to comment.