Skip to content

Commit

Permalink
Merge pull request #2 from RobinRamael/master
Browse files Browse the repository at this point in the history
Added optional location parameter to assertHttpRedirect.
  • Loading branch information
Wilfred committed Jul 7, 2014
2 parents 12d12d8 + e084dd4 commit 8325993
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions django_test_mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.test import TestCase
from django.core.cache import cache

import urlparse


class HttpCodeTestCase(TestCase):
# TODO: this should be a private method.
Expand All @@ -16,7 +18,7 @@ def assertHttpOK(self, response):
def assertHttpCreated(self, response):
self.assertHttpCode(response, 201, "Created")

def assertHttpRedirect(self, response):
def assertHttpRedirect(self, response, location=None):
"""Assert that we had any redirect status code.
"""
Expand All @@ -26,9 +28,18 @@ def assertHttpRedirect(self, response):
response.status_code
)

if location:
if location.startswith("http://testserver/"):
absolute_location = location
else:
absolute_location = urlparse.urljoin("http://testserver/", location)

self.assertEqual(response['Location'], absolute_location)


def assertHttpBadRequest(self, response):
self.assertHttpCode(response, 400, "Bad Request")

def assertHttpUnauthorized(self, response):
self.assertHttpCode(response, 401, "Unauthorized")

Expand Down

0 comments on commit 8325993

Please sign in to comment.