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):

Thanks django!

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: