Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Loading… for Django example #211

Konjkov opened this Issue · 12 comments

3 participants


I write example for Django example project.
To make test successful You have to create stub file, set django.db.backends to anything non default, put my code into Run ./ 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

class _RemoteProcedure(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)
        # Hack
        client = Client()
        response =, 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):
            raise self.ctx.in_error
        elif code >= 400:
            raise self.ctx.in_error
            return self.ctx.in_object

class DjangoClient(ClientBase):
    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

class SpyneTestCase(TransactionTestCase):
    def setUp(self):
        self.client = DjangoClient('/hello_world/',

    def test_say_hello(self):
        resp =  self.client.service.say_hello('Joe',5)
        list_resp = list(resp)
        self.assertEqual(len(list_resp), 5)
        self.assertEqual(list_resp,['Hello, Joe']*5)


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.

@plq plq referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@plq plq referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.

Okay, but you should refactor this test to start its own server. As you may know, Spyne tests run unsupervised in


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.

@plq plq referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.

And on third thought, I'll put it back in spyne.client but under the name of DjangoTestClient :)

@plq plq referenced this issue from a commit in plq/spyne
@plq plq initial commit for a muted django test. Issue #211 59b6f87

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, 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.

@plq plq closed this

Hi, what is hello_world_service when it is supposed to have an app attribute? Some guidance doc would be splendid!


I thought this project was dead, sorry......

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.