Friday, November 13, 2015

Re: following 302s in WebTest form.submit() (was Best practices for writing functional tests to exercise forms?

On 2015-11-13 10:22, Carl Meyer wrote:
> 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.

Okay, that's a nice balance between explicitly testing the redirect
and verbosity. I was afraid I'd have to do chainings something like

resp = frm.submit()
count = 0
while resp.code == 302 and count < 5: # or some broader test
resp = get(resp.redirect_url)
count += 1
if count >= 5:
did_we_circular_redirect("?")

for every one of my get/post calls. Using .follow() is much nicer.

Thanks,

-tkc



--
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/20151113114907.040b7e30%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment