I write example test.py for Django example project.
To make test successful You have to create stub models.py file, set django.db.backends to anything non default, put my code into tests.py. Run ./manage.py test core.
"""The Django test client transport."""
from django.test.client import Client
from spyne.client import Service
from spyne.client import ClientBase
from spyne.client import RemoteProcedureBase
def __call__(self, *args, **kwargs):
# there's no point in having a client making the same request more than
# once, so if there's more than just one context, it is a bug.
# the comma-in-assignment trick is a general way of getting the first
# and the only variable from an iterable. so if there's more than one
# element in the iterable, it'll fail miserably.
self.ctx, = self.contexts
# sets ctx.out_object
self.get_out_object(self.ctx, args, kwargs)
# sets ctx.out_string
out_string = ''.join(self.ctx.out_string)
client = Client()
response = client.post(self.url, content_type='text/xml', data=out_string)
code = response.status_code
self.ctx.in_string = [response.content]
# this sets ctx.in_error if there's an error, and ctx.in_object if
# there's none.
if not (self.ctx.in_error is None):
elif code >= 400:
def __init__(self, url, app):
super(DjangoClient, self).__init__(url, app)
self.service = Service(_RemoteProcedure, url, app)
from django.test import TransactionTestCase
from views import hello_world_service
self.client = DjangoClient('/hello_world/', hello_world_service.app)
resp = self.client.service.say_hello('Joe',5)
list_resp = list(resp)
Thanks a lot, but I don't see what you're testing here. Mayber it's me, could you be a little more specific by pointing to the blocks of code that you're actually testing?
Django have the test client
it can make GET, POST, PUT, DELETE... requests to Django test server.
When I use spyne service as DjangoApplication, I want to test it like other Django applications, so I need special client for testing soap request in Django (over http transport).
class DjangoClient(ClientBase) is this client and it tests simple soap django application hello_world in this example.
Okay, but you should refactor this test to start its own server. As you may know, Spyne tests run unsupervised in travis-ci.org
oh, and the test client should actually go inside client.django module. I'll take care of that.
On second thought, I don't think it should. It's from django.test so I'd think it actually belongs in spyne.test.
And on third thought, I'll put it back in spyne.client but under the name of DjangoTestClient :)
initial commit for a muted django test. Issue #211
Thanks Arslan. This test was writing as example, how to test spyne server in Django project, with Django tools.
In my project I implement spyne server in Django and use the same way to test my application.
As you may know, the spyne tests are run by travis-ci.org, so need to be completely autonomous. So you should factor in the logic that creates a django project, starts the server and runs the tests. I can merge this the moment the test runs just fine simply by calling it. You can have a look at the suds test to see how we got it to work.
reopen if you're willing to do this.
Hi, what is hello_world_service when it is supposed to have an app attribute? Some guidance doc would be splendid!
Questions go to http://lists.spyne.io/listinfo/people
I thought this project was dead, sorry......