On Sat, 2007-05-12 at 10:05 +0800, Russell Keith-Magee wrote:
> On 5/11/07, Jiri Barton <[EMAIL PROTECTED]> wrote:
> >
> > Thank you Russ, that has fixed the problem.
> >
> > I  have a problem with the fix though; what if there were multiple
> > redirects? This just happened when I jumped to use your fix today:
> ...
> > This calls for some loop in the code of assertRedirects but I don't
> > know where to place it and how to check the redirect chain has
> > finished (return code starts with '3'?) - and detect infinte loops
> > possibly.
> >
> > I hate to bother you but please explain this to me or, could you fix
> > it?
> 
> I thought about this, and decided that it would be better to require
> the user to do multiple checks. Tests should always be atomic, and
> although they have the appearance to the user of being a single
> action, they are two very distinct actions on the part of the server.
> 
> I suppose one option would be to make assertRedirects return the
> response from GETting the redirect page; that way you could chain the
> tests easily:
> 
> response = self.client.get('/page')
> response = self.assertRedirects(response, '/first/')
> response = self.assertRedirects(response, '/second'/)
> ...
> 
> but I'm not sure how I feel about assertRedirects being the only
> assert method that returns a value. Opinions?

I agree (with you). This sort of API feels like you're smashing
unrelated things together. Maybe an explicit response.follow_redirect()
method? 

Thinking out loud, this use case suggests you might want some way to
easily check that you've come to the end of a redirect chain. So running
the sorts of tests Jiri is asking about would involve a loop to get to
the end of the chain and then check the location to see that they end up
where they wanted to be.

Except that that isn't possible in the current setup: the ClientHandler
class doesn't have a concept of "current location" -- and I'm not sure
that adding one is the right idea (yet) -- and you can't implement a
method that asks "is the next redirect the last one?" without executing
the redirect.

Hmmm... imaginary code that would work:

        while response.is_redirect():
            old_response, response = response,
        response.follow_redirect()
        self.assertRedirect(old_response, '/final_destination/')
        
It's not winning prizes for beauty, though. This needs more thought.

(Wait! I thought I wasn't going to get involved in the testing
framework? How did I get to this point, posting a reply?!)

Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to