Skip to content

Commit

Permalink
Fixed tests to match new HTTP redirect behaviour. We always redirect …
Browse files Browse the repository at this point in the history
…to absolute URLs now.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6169 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Sep 14, 2007
1 parent 2083c53 commit eabb57f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions tests/modeltests/test_client/models.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_redirect(self):
"GET a URL that redirects elsewhere" "GET a URL that redirects elsewhere"
response = self.client.get('/test_client/redirect_view/') response = self.client.get('/test_client/redirect_view/')
# Check that the response was a 302 (redirect) # Check that the response was a 302 (redirect)
self.assertRedirects(response, '/test_client/get_view/') self.assertRedirects(response, 'http://testserver/test_client/get_view/')


client_providing_host = Client(HTTP_HOST='django.testserver') client_providing_host = Client(HTTP_HOST='django.testserver')
response = client_providing_host.get('/test_client/redirect_view/') response = client_providing_host.get('/test_client/redirect_view/')
Expand All @@ -96,13 +96,13 @@ def test_redirect_with_query(self):
response = self.client.get('/test_client/redirect_view/', {'var': 'value'}) response = self.client.get('/test_client/redirect_view/', {'var': 'value'})


# Check if parameters are intact # Check if parameters are intact
self.assertRedirects(response, '/test_client/get_view/?var=value') self.assertRedirects(response, 'http://testserver/test_client/get_view/?var=value')


def test_permanent_redirect(self): def test_permanent_redirect(self):
"GET a URL that redirects permanently elsewhere" "GET a URL that redirects permanently elsewhere"
response = self.client.get('/test_client/permanent_redirect_view/') response = self.client.get('/test_client/permanent_redirect_view/')
# Check that the response was a 301 (permanent redirect) # Check that the response was a 301 (permanent redirect)
self.assertRedirects(response, '/test_client/get_view/', status_code=301) self.assertRedirects(response, 'http://testserver/test_client/get_view/', status_code=301)


client_providing_host = Client(HTTP_HOST='django.testserver') client_providing_host = Client(HTTP_HOST='django.testserver')
response = client_providing_host.get('/test_client/permanent_redirect_view/') response = client_providing_host.get('/test_client/permanent_redirect_view/')
Expand All @@ -115,7 +115,7 @@ def test_redirect_to_strange_location(self):


# Check that the response was a 302, and that # Check that the response was a 302, and that
# the attempt to get the redirection location returned 301 when retrieved # the attempt to get the redirection location returned 301 when retrieved
self.assertRedirects(response, '/test_client/permanent_redirect_view/', target_status_code=301) self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/', target_status_code=301)


def test_notfound_response(self): def test_notfound_response(self):
"GET a URL that responds as '404:Not Found'" "GET a URL that responds as '404:Not Found'"
Expand Down Expand Up @@ -239,7 +239,7 @@ def test_view_with_login(self):


# Get the page without logging in. Should result in 302. # Get the page without logging in. Should result in 302.
response = self.client.get('/test_client/login_protected_view/') response = self.client.get('/test_client/login_protected_view/')
self.assertRedirects(response, '/accounts/login/?next=/test_client/login_protected_view/') self.assertRedirects(response, 'http://testserver/accounts/login/?next=/test_client/login_protected_view/')


# Log in # Log in
login = self.client.login(username='testclient', password='password') login = self.client.login(username='testclient', password='password')
Expand Down Expand Up @@ -277,7 +277,7 @@ def test_logout(self):


# Request a page that requires a login # Request a page that requires a login
response = self.client.get('/test_client/login_protected_view/') response = self.client.get('/test_client/login_protected_view/')
self.assertRedirects(response, '/accounts/login/?next=/test_client/login_protected_view/') self.assertRedirects(response, 'http://testserver/accounts/login/?next=/test_client/login_protected_view/')


def test_session_modifying_view(self): def test_session_modifying_view(self):
"Request a page that modifies the session" "Request a page that modifies the session"
Expand Down
6 changes: 3 additions & 3 deletions tests/regressiontests/test_client_regress/models.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_lost_query(self):
try: try:
self.assertRedirects(response, '/test_client/get_view/') self.assertRedirects(response, '/test_client/get_view/')
except AssertionError, e: except AssertionError, e:
self.assertEquals(str(e), "Response redirected to '/test_client/get_view/?var=value', expected '/test_client/get_view/'") self.assertEquals(str(e), "Response redirected to 'http://testserver/test_client/get_view/?var=value', expected '/test_client/get_view/'")


def test_incorrect_target(self): def test_incorrect_target(self):
"An assertion is raised if the response redirects to another target" "An assertion is raised if the response redirects to another target"
Expand All @@ -135,7 +135,7 @@ def test_target_page(self):
response = self.client.get('/test_client/double_redirect_view/') response = self.client.get('/test_client/double_redirect_view/')
try: try:
# The redirect target responds with a 301 code, not 200 # The redirect target responds with a 301 code, not 200
self.assertRedirects(response, '/test_client/permanent_redirect_view/') self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/')
except AssertionError, e: except AssertionError, e:
self.assertEquals(str(e), "Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)") self.assertEquals(str(e), "Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)")


Expand Down Expand Up @@ -260,4 +260,4 @@ def test_login_different_client(self):
# At this points, the self.client isn't logged in. # At this points, the self.client isn't logged in.
# Check that assertRedirects uses the original client, not the # Check that assertRedirects uses the original client, not the
# default client. # default client.
self.assertRedirects(response, "/test_client_regress/get_view/") self.assertRedirects(response, "http://testserver/test_client_regress/get_view/")

0 comments on commit eabb57f

Please sign in to comment.