'Asserts redirect and final redirect matches expected URL.
Similar to Django\'s `assertRedirects` but skips the final GET
verification for speed.'

def assert3xx(self, response, expected_url, status_code=302, target_status_code=200):

    if hasattr(response, 'redirect_chain'):
        self.assertTrue((len(response.redirect_chain) > 0), ("Response    didn't    redirect    as    expected:    Response    code    was    %d    (expected    %d)" % (response.status_code, status_code)))
        (url, status_code) = response.redirect_chain[(-1)]
        self.assertEqual(response.status_code, target_status_code, ("Response    didn't    redirect    as    expected:    Final    Response    code    was    %d    (expected    %d)" % (response.status_code, target_status_code)))
    else:
        self.assertEqual(response.status_code, status_code, ("Response    didn't    redirect    as    expected:    Response    code    was    %d    (expected    %d)" % (response.status_code, status_code)))
        url = response['Location']
    (scheme, netloc, path, query, fragment) = urlsplit(url)
    (e_scheme, e_netloc, e_path, e_query, e_fragment) = urlsplit(expected_url)
    if ((scheme and (not e_scheme)) and (netloc and (not e_netloc))):
        expected_url = urlunsplit(('http', 'testserver', e_path, e_query, e_fragment))
    self.assertEqual(url, expected_url, ("Response    redirected    to    '%s',    expected    '%s'" % (url, expected_url)))
