From 895633a80d04ba95b2efdb3e32ddf560c0693339 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sun, 18 Feb 2007 08:02:00 +0000 Subject: [PATCH] Fixed #3210 -- Modified test Client.login() to use urlparse, allowing absolute URLs in the Location header. Thanks, Ben Dean Kawamura. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4540 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/test/client.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index ad8f876a6f14f..57f9df3efe8df 100644 --- a/AUTHORS +++ b/AUTHORS @@ -104,6 +104,7 @@ answer newbie questions, and generally made Django that much better: Michael Josephson jpellerin@gmail.com junzhang.jn@gmail.com + Ben Dean Kawamura Garth Kidd kilian Sune Kirkeby diff --git a/django/test/client.py b/django/test/client.py index 95900154c52c9..682dd01261edb 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -1,5 +1,6 @@ import sys from cStringIO import StringIO +from urlparse import urlparse from django.conf import settings from django.core.handlers.base import BaseHandler from django.core.handlers.wsgi import WSGIRequest @@ -222,7 +223,7 @@ def login(self, path, username, password, **extra): if response.status_code != 302: return False - login_path, data = response['Location'].split('?') + _, _, login_path, _, data, _= urlparse(response['Location']) next = data.split('=')[1] # Second, GET the login page; required to set up cookies @@ -239,7 +240,8 @@ def login(self, path, username, password, **extra): response = self.post(login_path, data=form_data, **extra) # Login page should 302 redirect to the originally requested page - if response.status_code != 302 or response['Location'] != path: + if (response.status_code != 302 or + urlparse(response['Location'])[2] != path): return False # Since we are logged in, request the actual page again