I'm writing some tests for my django app.In my view,it redirects to some other url using 'HttpResponseRedirect'.So how can I test that?
相关问题
- Angular RxJS mergeMap types
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
There are other attributes of the response that might be interesting to test. If you are unsure what is on the object then you can always do a
EDIT FOR CURRENT VERSIONS OF DJANGO
It's a bit simpler now, just do:
I would also suggest using reverse to look up the url you expect from a name, if it is a url in your app anyway.
The Django
TestCase
class has a methodassertRedirects
that you can use.Status code 301 checks that it's a permanent redirect.
In django 1.6, you could use(not recommended):
instead, following is more powerful and concise and no
http://testserver/
need