Keith Fitzgerald
Keith Fitzgerald

Reputation: 5701

Django Test Client and Subdomains

I'm trying to figure out how to make the Django test client play nice with my app that puts each user on it's own subdomain. i.e. each account has account1.myapp.com, account2.myapp.com.

A user could be members of multiple subdomains (similar basecamp's model) so i handle which subdomain the request is being issued against in middleware.

As I'm writing my unit tests, I realized that all requests are issued to "http://testserver" which my middleware then redirects and the subsequent 302 is not followed as it's determined to be an external request.

Anyone aware of a way to enable this with the test client? I'm currently hacking a bit in django to enable it.

Upvotes: 12

Views: 1475

Answers (1)

Julian
Julian

Reputation: 702

in your tests, when using the client, add the HTTP_HOST parameter:

response = c.post(reverse('my-url'), data={}, HTTP_HOST='account1.myapp.com')

on your middleware now you should see the host changed!

Upvotes: 12

Related Questions