The django.test.client.Client

I like django and the more I work with it, the more I like it :)

For a unittest I needed to simulate requests coming from different remote addresses. And the django.test.client.Client makes this pretty easy:

class DistributedTestClient(Client):
    def request(self, **request):
        request["REMOTE_ADDR"] = "192.168.%i.%i" % (random.randint(1,254), random.randint(1,254))
        return super(DistributedTestClient, self).request(**request)

class DistributedClientkTestCase(TestCase):
    client_class = DistributedTestClient
    def test_distributed_meep(self):
        test_stuff()

Thanks django!

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: