I'm having a problem with the cookies from a Client() disappearing.

Here is the example I'm working with (also on dpaste: 
http://dpaste.com/hold/69285/)

# This method works as expected.  It does not lose any
# cookie information.
def followRedirect_working(response, expected_url):
        """
        Do a GET on the URL from a redirected response
        and return that response.
        """
        # I can't use the assertions outside of a class.
        #self.assertRedirects(response, expected_url)

        #self.assert_('Location' in response)
        redirect_url = response['Location']

        scheme, netloc, path, query, fragment = urlsplit(redirect_url)
        # Get the redirection page, using the same client that was used
        # to obtain the original response.
        redirect_response = response.client.get(path, QueryDict(query))

        return redirect_response


# This is my base class.  I extend this in all of my actual tests.
# I need a bunch of "helper" methods in all of my actual tests, so
# I define them here so I don't have to redefine them in every class.
class NewsBaseTestCase(TestCase):

        # This is the method that doesn't work
        def followRedirect_does_not_work(self, client, response,
expected_url):
                """
                Do a GET on the URL from a redirected response
                and return that response.
                """
                self.assertRedirects(response, expected_url)

                self.assert_('Location' in response)
                redirect_url = response['Location']

                scheme, netloc, path, query, fragment = urlsplit(redirect_url)
                # Get the redirection page, using the same client that was used
                # to obtain the original response.
                redirect_response = client.get(path, QueryDict(query))

                return redirect_response


# This is the method that is extending my base class.
# I have a lot of methods like this, and I want them all to
# be able to access the followRedirect_does_not_work() method,
# but I don't want to have to repeat myself and rewrite it for
# all of them.  So, I just make all of my test classes extend
# the base class.
class NewsLoginTests(NewsBaseTestCase):
        """
        Tests for dealing with logging in, creating users, etc.
        """

        def testCreateAccount(self):
                """
                Test the create_account view.
                """
                create_account_view = '/create_account'

                # if our username is not valid (we should be redirected back
                # to the login page, but our failed username should still be
                # in the box).
                # (This view will set some session variables that are read
                # when the redirected page is loaded.  Therefore I need the
                # to get the session id to get the session variables).
                response = self.client.post(create_account_view,
                                {'username':"asefasef.", 'password': "lalala",
                                 'next': 
reverse('news.views_news_items.index')})
                print response.cookies
                redirect_response = followRedirect_does_not_work(response,
                                reverse('news.views_login.login_view') + 
'?next=' +
                                reverse('news.views_news_items.index'))
                print redirect_response.cookies

                # response.cookies and redirect_response.cookies are the same
                # when using followRedirect_working(), but they are different
                # when using self.followRedirect_does_not_work().  Obviously,
                # I need them to be the same so that I can access session
                # variables.



I want to be able to have followRedirect() in my super class, but it
doesn't work there.  I have to have it outside of all the classes.
Otherwise the cookies will not persist with I do the
`redirect_response = response.client.get('/login')`.

What am I doing wrong?  Is it a bug in Django?

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to