'Check for redirect.
Asserts that the given response issued a 302 redirect without
processing the view which is redirected to.'

def assertRedirectsNoFollow(self, response, expected_url):

    if (django.VERSION >= (1, 9)):
        loc = six.text_type(response._headers.get('location', None)[1])
        loc = http.urlunquote(loc)
        expected_url = http.urlunquote(expected_url)
        self.assertEqual(loc, expected_url)
    else:
        self.assertEqual(response._headers.get('location', None), ('Location', (settings.TESTSERVER + expected_url)))
    self.assertEqual(response.status_code, 302)
