Opened 15 years ago
Last modified 4 years ago
#12227 new Bug
PREPEND_WWW breaks the test client
Reported by: | Andy Baker | Owned by: | |
---|---|---|---|
Component: | Testing framework | Version: | 1.1 |
Severity: | Normal | Keywords: | test client, redirect, prepend_www |
Cc: | andy@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Pull Requests: | How to create a pull request | ||
Description ¶
With PREPEND_WWW set to true the test client will always give a 301 status_code:
>>> from django.test.client import Client >>> c = Client() >>> r = c.get('/admin/', follow=True) >>> r.status_code 301 >>> r.redirect_chain [('http://www.testserver/admin/', 301), ('http://www.testserver/admin/', 301)]
According to the ticket's flags, the next step(s) to move this issue forward are:
- To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.
Change History (9)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:4 by , 13 years ago
Easy pickings: | unset |
---|---|
UI/UX: | unset |
Not sure how to fix but I've added a test case which demonstrates the described issue.
comment:5 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 10 years ago
I’ve been experiencing this and am using SERVER_NAME
and host
as a fix. Though as the number of tests I write for the project grows it doesn’t seem the most ideal solution.
response = self.client.get('/redirect/', follow=True, SERVER_NAME='www.testserver') self.assertRedirects(response, '/result/', status_code=301, host='www.testserver')
comment:8 by , 4 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
Note:
See TracTickets
for help on using tickets.
+1, this behaviour serves no purpose. It only makes testing difficult and forces me to never use prepend_www and rather do my redirects at the webserver level. Perhaps PREPEND_WWW should be disabled before every test automatically, since it's not what testing is supposed to test for?