Hi Tim, On 11/13/2015 10:06 AM, Tim Chase wrote: > On 2015-11-09 12:41, Tim Chase wrote: >> On 2015-11-06 01:09, Carl Meyer wrote: >>> [1] https://pypi.python.org/pypi/WebTest >>> [2] https://pypi.python.org/pypi/django-webtest >> >> Just to follow up, django-webtest has been pretty much exactly what >> I was looking for. Thanks! > > Monkeying around with my tests, I have the following snippet: > > response = self.app.get(self.login_url) > login_form = response.forms["login"] > login_form["username"] = NAME > login_form["password"] = PASS > good_response = login_form.submit() > > When I get my good_response back, it's a 302 redirect to "next". Is > there any way to get it follow that redirect automatically like > Django's Client allows for .get(..., follow=True)? Or do I have to > manually follow every redirect? I didn't see anything in the docs > for WebTest/django-webtest nor did I turn up anything > obvious-but-undocumented when poking around in the source for a > couple minutes.
As far as I know, you have to call `.follow()` on the response, which follows the redirect and returns the next response. Is that what you mean by "manually follow every redirect"? It's manual in a sense, but there is a convenience method to make it very easy. You can just change `login_form.submit()` to `login_form.submit().follow()`, you don't even need another line of code. I think this is better than the Django client's `follow=True`, because it means your test specifies the expected number of redirects, and will fail if the number of redirects changes unexpectedly. (You can check this with Django's test client by using the `redirect_chain` attribute, but usually people don't.) Carl -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/56461C5E.30007%40oddbird.net. For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature