def check_redirect_url(
        response: HttpResponseRedirect, reversed_url: str, strip_params=True
) -> bool:
    """
    Check whether a given redirect response matches a specific reversed URL.

    Arguments:
    * `response`: The HttpResponseRedirect returned by the test client
    * `reversed_url`: The URL returned by `reverse()`
    * `strip_params`: Whether to strip URL parameters (following a "?") from the URL given in the
                     `response` object
    """
    host = get_host(None)
    hostname = reverse_host(host)

    redirect_url = response.url

    if strip_params and "?" in redirect_url:
        redirect_url = redirect_url.split("?", 1)[0]

    result = reversed_url == f"//{hostname}{redirect_url}"
    return result
 def test_appended_patterns(self):
     self.assertEqual(get_host('special').name, 'special')
 def test_get_host(self):
     self.assertEqual(get_host('static').name, 'static')
     self.assertRaisesMessage(NoReverseMatch,
                              "No host called 'non-existent' exists",
                              get_host, 'non-existent')
 def test_default_host(self):
     self.assertEqual(get_host().name, 'www')
     with self.settings(DEFAULT_HOST='static'):
         self.assertEqual(get_host().name, 'static')
     self.assertEqual(get_host().name, 'www')
Example #5
0
 def test_appended_patterns(self):
     self.assertEqual(get_host('special').name, 'special')
Example #6
0
 def test_get_host(self):
     self.assertEqual(get_host('static').name, 'static')
     self.assertRaisesMessage(NoReverseMatch,
         "No host called 'non-existent' exists", get_host, 'non-existent')
Example #7
0
 def test_default_host(self):
     self.assertEqual(get_host().name, 'www')
     with self.settings(DEFAULT_HOST='static'):
         self.assertEqual(get_host().name, 'static')
     self.assertEqual(get_host().name, 'www')