-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iQIcBAEBCAAGBQJWRhxiAAoJEC0ft5FqUuEh0IAP/34RJ8nBznkXTGF2eGxu9fwq
sEgNjqQw+mNm0x/vvUivtZCkLyht54v2BYag6PalRps0ewZ0uQBEntGoyTnZPmw0
qnVj8MCJY/vBVTbU3rERHqpGtUU1IQVbHaUgZH3Ttk/SMKvzYFHA4RY6LEF7Y4Oa
3pDcMDYyf8VhO1i+43ZP9kOHHxG0VNnQN8ohV9yMrFnQiXDcucZI7LPExm+QeAwC
Psh68nrlqM8/LAHS/qWC5X3CDMB45VhkQfqjMh+puYWUwQgXLHgE5uL7l2jzbfrf
B7wsiDmMzMfTW0u2zKndfIsw7ObALcGXXu7ltsOLkAuzAU2hVztZZQmYZTmBwfk3
jP567dCP3r7/Uefc5lgLzarvADskOmdJHpQYLbUDuRL3vJXNBekWayzLHGmwsOYh
aAm5VNEN43/1xzkZ3mt29jxCiMvqso8eFkUsyB6rbYtCoicUr3fYb0GVJP6US5pG
bz8fm0Qgw5y9WJ7R5icHj43klMyfQ7AXGPJvMjKDvK7kjNOe2wnmhn/DW6457gJ7
vixgWh+9zkQDIuHJqYaUnwTKz2rLEmtwPer/fCmLyOFRrmRDzbtos/y4M0vW19xV
S9MsgzghmxKraviqH8iR5pplBc6WjxuJWsS+agIss1n5bDGZETzvzTEclHrEkJBd
2SY4S2IGcHVcL+ENRpsh
=nyS4
-----END PGP SIGNATURE-----
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+unsubscribe@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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment