Exemplo n.º 1
0
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
Exemplo n.º 2
0
 def test_appended_patterns(self):
     self.assertEqual(get_host('special').name, 'special')
Exemplo n.º 3
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')
Exemplo n.º 4
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')
Exemplo n.º 5
0
 def test_appended_patterns(self):
     self.assertEqual(get_host('special').name, 'special')
Exemplo n.º 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')
Exemplo n.º 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')