#4476: Modify test client to follow redirect chains
-------------------------------------------------------+--------------------
Reporter: Chris Moffitt <[EMAIL PROTECTED]> | Owner:
adrian
Status: new | Component:
Unit test system
Version: SVN | Resolution:
Keywords: | Stage:
Accepted
Has_patch: 0 | Needs_docs:
0
Needs_tests: 0 | Needs_better_patch:
0
-------------------------------------------------------+--------------------
Changes (by russellm):
* summary: Proposal for assertRedirectContains => Modify test client to
follow redirect chains
* stage: Design decision needed => Accepted
Old description:
> When using assertRedirects, I find myself doing an assert redirects, then
> wanting to validate the text where I'm redirecting. The process seems a
> little clunky and an assertRedirectContains would be useful.
>
> Current process:
>
> {{{
> self.assertRedirects(response, '/confirm/', status_code=302,
> target_status_code=200)
> response = self.client.get('/confirm/')
> self.assertContains(response, "Total = $54.50", count=1, status_code=200)
> }}}
>
> It would be nice to have something like:
>
> {{{
> self.assertRedirectContains(response, "Total = $54.50", count=1,
> status_code=302, target_status_code=200)
> }}}
>
> I'm assuming there's no other shortcut I'm missing.
New description:
When using assertRedirects, I find myself doing an assert redirects, then
wanting to validate the text where I'm redirecting. The process seems a
little clunky and an assertRedirectContains would be useful.
Current process:
{{{
self.assertRedirects(response, '/confirm/', status_code=302,
target_status_code=200)
response = self.client.get('/confirm/')
self.assertContains(response, "Total = $54.50", count=1, status_code=200)
}}}
It would be nice to have something like:
{{{
self.assertRedirectContains(response, "Total = $54.50", count=1,
status_code=302, target_status_code=200)
}}}
I'm assuming there's no other shortcut I'm missing.
*** UPDATE (from russellm) ***
Rather that assertRedirectContains, I'm favouring a modification to the
test client that will follow redirects. Details in the comment below
Comment:
I'm not a fan of assertRedirectContains, because it sounds like start of
aggregating groups of tests together. It works for a single redirect, but
then you have a page that redirects to a redirect, so you need to add
'assertRedirectRedirectContains', and then the madness starts :-). So, -1
to the literal idea.
However, I'm going to mark the ticket is as accepted and change the
summary, because the general problem is valid.
Rather than assertRedirectContains, I'm going to suggest that the test
Client should be modified to do what a normal web client will do - follow
redirect trails. So, if you had a site with:
/first -> redirects to /second
/second -> redirects to /final
/final -> a page of content
response = client.get('/first', follow=True)
you would get back the content at '/final', with a response code of 200.
The response should also have some extra meta-data to indicate the paths
that were visited along the way. There may also be a need to modify the
assertions to allow for checking that a redirect occurred; e.g.,
assertContains(response, "content of /final", count=1, status_code=200,
redirected=True)
However, I'll leave the details of any assertion changes as a detail for
the implementer.
--
Ticket URL: <http://code.djangoproject.com/ticket/4476#comment:3>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---