Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 524
Keith Fitzgerald Avatar asked Dec 05 '11 17:12

Keith Fitzgerald


1 Answers

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!

like image 137
Julian Avatar answered Oct 18 '22 08:10

Julian