def test_name(self): """ Should return a URLPattern with a matching name attribute """ url_pattern = redirect(r"^the/dude$", "abides", name="Lebowski") assert isinstance(url_pattern, URLPattern) assert url_pattern.name == "Lebowski"
def test_name(self): """ Should return a RegexURLPattern with a matching name attribute """ url_pattern = redirect(r"^the/dude$", "abides", name="Lebowski") ok_(isinstance(url_pattern, RegexURLPattern)) eq_(url_pattern.name, "Lebowski")
def test_name(self): """ Should return a RegexURLPattern with a matching name attribute """ url_pattern = redirect(r'^the/dude$', 'abides', name='Lebowski') ok_(isinstance(url_pattern, RegexURLPattern)) eq_(url_pattern.name, 'Lebowski')
def test_name(self): """ Should return a URLPattern with a matching name attribute """ url_pattern = redirect(r'^the/dude$', 'abides', name='Lebowski') assert isinstance(url_pattern, URLPattern) assert url_pattern.name == 'Lebowski'
def test_name(self): """ Should return a RegexURLPattern with a matching name attribute """ url_pattern = redirect(r'^the/dude$', 'abides', name='Lebowski') assert isinstance(url_pattern, RegexURLPattern) assert url_pattern.name == 'Lebowski'
def test_temporary_redirect(self): """ Should use a temporary redirect (status code 302) if permanent == False """ pattern = redirect(r"^the/dude$", "abides", permanent=False) request = self.rf.get("the/dude") response = pattern.callback(request) assert response.status_code == 302 assert response["Location"] == "abides"
def test_empty_query(self): """ Should strip query params if called with empty query """ pattern = redirect(r"^the/dude$", "abides", query={}) request = self.rf.get("the/dude?white=russian") response = pattern.callback(request) assert response.status_code == 301 assert response["Location"] == "abides"
def test_replace_query(self): """ Should replace query params if any are provided """ pattern = redirect(r"^the/dude$", "abides", query={"aggression": "not_stand"}) request = self.rf.get("the/dude?aggression=unchecked") response = pattern.callback(request) assert response.status_code == 301 assert response["Location"] == "abides?aggression=not_stand"
def test_anchor(self): """ Should append anchor text to the end, including after any querystring """ pattern, view = redirect(r'^the/dude$', 'abides', anchor='toe') request = self.rf.get('the/dude?want=a') response = view(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides?want=a#toe')
def test_replace_query(self): """ Should replace query params if any are provided """ pattern = redirect(r"^the/dude$", "abides", query={"aggression": "not_stand"}) request = self.rf.get("the/dude?aggression=unchecked") response = pattern.callback(request) eq_(response.status_code, 301) eq_(response["Location"], "abides?aggression=not_stand")
def test_locale_value_capture_ignore_locale(self): """ Should be able to ignore the original locale. """ resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/", prepend_locale=False)]) middleware = RedirectsMiddleware(resolver=resolver) resp = middleware.process_request(self.rf.get("/zh-TW/iam/the/walrus/")) assert resp.status_code == 301 assert resp["Location"] == "/donnie/the/walrus/"
def test_temporary_redirect(self): """ Should use a temporary redirect (status code 302) if permanent == False """ pattern = redirect(r"^the/dude$", "abides", permanent=False) request = self.rf.get("the/dude") response = pattern.callback(request) eq_(response.status_code, 302) eq_(response["Location"], "abides")
def test_locale_value_capture_no_locale(self): """ Should get locale value in kwargs and not break if no locale in URL. """ resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/")]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get("/iam/the/walrus/")) eq_(resp.status_code, 301) eq_(resp["Location"], "/donnie/the/walrus/")
def test_locale_value_capture_ignore_locale(self): """ Should be able to ignore the original locale. """ resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/", prepend_locale=False)]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get("/zh-TW/iam/the/walrus/")) eq_(resp.status_code, 301) eq_(resp["Location"], "/donnie/the/walrus/")
def test_locale_value_capture(self): """ Should prepend locale value automatically. """ resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/")]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get("/pt-BR/iam/the/walrus/")) eq_(resp.status_code, 301) eq_(resp["Location"], "/pt-BR/donnie/the/walrus/")
def test_value_capture_and_substitution(self): """ Should be able to capture info from URL and use in redirection. """ resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/")]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get("/iam/the/walrus/")) eq_(resp.status_code, 301) eq_(resp["Location"], "/donnie/the/walrus/")
def test_anchor(self): """ Should append anchor text to the end, including after any querystring """ pattern = redirect(r"^the/dude$", "abides", anchor="toe") request = self.rf.get("the/dude?want=a") response = pattern.callback(request) eq_(response.status_code, 301) eq_(response["Location"], "abides?want=a#toe")
def test_anchor(self): """ Should append anchor text to the end, including after any querystring """ pattern = redirect(r"^the/dude$", "abides", anchor="toe") request = self.rf.get("the/dude?want=a") response = pattern.callback(request) assert response.status_code == 301 assert response["Location"] == "abides?want=a#toe"
def test_locale_value_capture(self): """ Should prepend locale value automatically. """ resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/")]) middleware = RedirectsMiddleware(resolver=resolver) resp = middleware.process_request(self.rf.get("/pt-BR/iam/the/walrus/")) assert resp.status_code == 301 assert resp["Location"] == "/pt-BR/donnie/the/walrus/"
def test_empty_unnamed_captures(self): """ Should be able to define an optional unnamed capture. """ resolver = get_resolver([redirect(r"^iam/the(/.+)?/$", "/donnie/the{}/", locale_prefix=False)]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get("/iam/the/")) eq_(resp.status_code, 301) eq_(resp["Location"], "/donnie/the/")
def test_empty_query(self): """ Should strip query params if called with empty query """ pattern = redirect(r"^the/dude$", "abides", query={}) request = self.rf.get("the/dude?white=russian") response = pattern.callback(request) eq_(response.status_code, 301) eq_(response["Location"], "abides")
def test_value_capture_and_substitution(self): """ Should be able to capture info from URL and use in redirection. """ resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/")]) middleware = RedirectsMiddleware(resolver=resolver) resp = middleware.process_request(self.rf.get("/iam/the/walrus/")) assert resp.status_code == 301 assert resp["Location"] == "/donnie/the/walrus/"
def test_no_query(self): """ Should return a 301 redirect """ pattern, view = redirect(r'^the/dude$', 'abides') request = self.rf.get('the/dude') response = view(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides')
def test_locale_value_capture_no_locale(self): """ Should get locale value in kwargs and not break if no locale in URL. """ resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/")]) middleware = RedirectsMiddleware(resolver=resolver) resp = middleware.process_request(self.rf.get("/iam/the/walrus/")) assert resp.status_code == 301 assert resp["Location"] == "/donnie/the/walrus/"
def test_empty_query(self): """ Should strip query params if called with empty query """ pattern, view = redirect(r'^the/dude$', 'abides', query={}) request = self.rf.get('the/dude?white=russian') response = view(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides')
def test_empty_unnamed_captures(self): """ Should be able to define an optional unnamed capture. """ resolver = get_resolver([redirect(r"^iam/the(/.+)?/$", "/donnie/the{}/", locale_prefix=False)]) middleware = RedirectsMiddleware(resolver=resolver) resp = middleware.process_request(self.rf.get("/iam/the/")) assert resp.status_code == 301 assert resp["Location"] == "/donnie/the/"
def test_preserve_query(self): """ Should preserve querys from the original request by default """ pattern = redirect(r"^the/dude$", "abides") request = self.rf.get("the/dude?aggression=not_stand") response = pattern.callback(request) eq_(response.status_code, 301) eq_(response["Location"], "abides?aggression=not_stand")
def test_preserve_query(self): """ Should preserve querys from the original request by default """ pattern, view = redirect(r'^the/dude$', 'abides') request = self.rf.get('the/dude?aggression=not_stand') response = view(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides?aggression=not_stand')
def test_no_query(self): """ Should return a 301 redirect """ pattern = redirect(r"^the/dude$", "abides") request = self.rf.get("the/dude") response = pattern.callback(request) assert response.status_code == 301 assert response["Location"] == "abides"
def test_no_query(self): """ Should return a 301 redirect """ pattern = redirect(r"^the/dude$", "abides") request = self.rf.get("the/dude") response = pattern.callback(request) eq_(response.status_code, 301) eq_(response["Location"], "abides")
def test_preserve_query(self): """ Should preserve querys from the original request by default """ pattern = redirect(r"^the/dude$", "abides") request = self.rf.get("the/dude?aggression=not_stand") response = pattern.callback(request) assert response.status_code == 301 assert response["Location"] == "abides?aggression=not_stand"
def test_temporary_redirect(self): """ Should use a temporary redirect (status code 302) if permanent == False """ pattern, view = redirect(r'^the/dude$', 'abides', permanent=False) request = self.rf.get('the/dude') response = view(request) eq_(response.status_code, 302) eq_(response['Location'], 'abides')
def test_temporary_redirect(self): """ Should use a temporary redirect (status code 302) if permanent == False """ pattern = redirect(r'^the/dude$', 'abides', permanent=False) request = self.rf.get('the/dude') response = pattern.callback(request) assert response.status_code == 302 assert response['Location'] == 'abides'
def test_empty_query(self): """ Should strip query params if called with empty query """ pattern = redirect(r'^the/dude$', 'abides', query={}) request = self.rf.get('the/dude?white=russian') response = pattern.callback(request) assert response.status_code == 301 assert response['Location'] == 'abides'
def test_anchor(self): """ Should append anchor text to the end, including after any querystring """ pattern = redirect(r'^the/dude$', 'abides', anchor='toe') request = self.rf.get('the/dude?want=a') response = pattern.callback(request) assert response.status_code == 301 assert response['Location'] == 'abides?want=a#toe'
def test_preserve_query(self): """ Should preserve querys from the original request by default """ pattern = redirect(r'^the/dude$', 'abides') request = self.rf.get('the/dude?aggression=not_stand') response = pattern.callback(request) assert response.status_code == 301 assert response['Location'] == 'abides?aggression=not_stand'
def test_anchor(self): """ Should append anchor text to the end, including after any querystring """ pattern = redirect(r'^the/dude$', 'abides', anchor='toe') request = self.rf.get('the/dude?want=a') response = pattern.callback(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides?want=a#toe')
def test_no_query(self): """ Should return a 301 redirect """ pattern = redirect(r'^the/dude$', 'abides') request = self.rf.get('the/dude') response = pattern.callback(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides')
def test_empty_query(self): """ Should strip query params if called with empty query """ pattern = redirect(r'^the/dude$', 'abides', query={}) request = self.rf.get('the/dude?white=russian') response = pattern.callback(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides')
def test_temporary_redirect(self): """ Should use a temporary redirect (status code 302) if permanent == False """ pattern = redirect(r'^the/dude$', 'abides', permanent=False) request = self.rf.get('the/dude') response = pattern.callback(request) eq_(response.status_code, 302) eq_(response['Location'], 'abides')
def test_preserve_query(self): """ Should preserve querys from the original request by default """ pattern = redirect(r'^the/dude$', 'abides') request = self.rf.get('the/dude?aggression=not_stand') response = pattern.callback(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides?aggression=not_stand')
def test_value_capture_and_substitution(self): """ Should be able to capture info from URL and use in redirection. """ resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$', '/donnie/the/{name}/')]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get('/iam/the/walrus/')) eq_(resp.status_code, 301) eq_(resp['Location'], '/donnie/the/walrus/')
def test_no_query(self): """ Should return a 301 redirect """ pattern = redirect(r'^the/dude$', 'abides') request = self.rf.get('the/dude') response = pattern.callback(request) assert response.status_code == 301 assert response['Location'] == 'abides'
def test_value_capture_and_substitution(self): """ Should be able to capture info from URL and use in redirection. """ resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$', '/donnie/the/{name}/')]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get('/iam/the/walrus/')) assert resp.status_code == 301 assert resp['Location'] == '/donnie/the/walrus/'
def test_locale_value_capture_no_locale(self): """ Should get locale value in kwargs and not break if no locale in URL. """ resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$', '/donnie/the/{name}/')]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get('/iam/the/walrus/')) assert resp.status_code == 301 assert resp['Location'] == '/donnie/the/walrus/'
def test_replace_query(self): """ Should replace query params if any are provided """ pattern = redirect(r'^the/dude$', 'abides', query={'aggression': 'not_stand'}) request = self.rf.get('the/dude?aggression=unchecked') response = pattern.callback(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides?aggression=not_stand')
def test_cache_headers(self): """ Should add cache headers based on argument. """ pattern = redirect(r"^the/dude$", "abides", cache_timeout=2) request = self.rf.get("the/dude") response = pattern.callback(request) assert response.status_code == 301 assert response["Location"] == "abides" assert response["cache-control"] == "max-age=7200" # 2 hours
def test_empty_unnamed_captures(self): """ Should be able to define an optional unnamed capture. """ resolver = get_resolver([redirect(r'^iam/the(/.+)?/$', '/donnie/the{}/', locale_prefix=False)]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get('/iam/the/')) assert resp.status_code == 301 assert resp['Location'] == '/donnie/the/'
def test_vary_header(self): """ Should add vary header based on argument. """ pattern = redirect(r'^the/dude$', 'abides', vary='Accept-Language') request = self.rf.get('the/dude') response = pattern.callback(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides') eq_(response['Vary'], 'Accept-Language')
def test_locale_value_capture(self): """ Should prepend locale value automatically. """ resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$', '/donnie/the/{name}/')]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get('/pt-BR/iam/the/walrus/')) assert resp.status_code == 301 assert resp['Location'] == '/pt-BR/donnie/the/walrus/'
def test_vary_header(self): """ Should add vary header based on argument. """ pattern = redirect(r'^the/dude$', 'abides', vary='Accept-Language') request = self.rf.get('the/dude') response = pattern.callback(request) assert response.status_code == 301 assert response['Location'] == 'abides' assert response['Vary'] == 'Accept-Language'
def test_cache_headers(self): """ Should add cache headers based on argument. """ pattern = redirect(r'^the/dude$', 'abides', cache_timeout=2) request = self.rf.get('the/dude') response = pattern.callback(request) assert response.status_code == 301 assert response['Location'] == 'abides' assert response['cache-control'] == 'max-age=7200' # 2 hours
def test_cache_headers(self): """ Should add cache headers based on argument. """ pattern = redirect(r'^the/dude$', 'abides', cache_timeout=2) request = self.rf.get('the/dude') response = pattern.callback(request) eq_(response.status_code, 301) eq_(response['Location'], 'abides') eq_(response['cache-control'], 'max-age=7200') # 2 hours
def test_locale_value_capture_ignore_locale(self): """ Should be able to ignore the original locale. """ resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$', '/donnie/the/{name}/', prepend_locale=False)]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get('/zh-TW/iam/the/walrus/')) assert resp.status_code == 301 assert resp['Location'] == '/donnie/the/walrus/'
def test_empty_unnamed_captures(self): """ Should be able to define an optional unnamed capture. """ resolver = get_resolver([redirect(r'^iam/the(/.+)?/$', '/donnie/the{}/', locale_prefix=False)]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get('/iam/the/')) eq_(resp.status_code, 301) eq_(resp['Location'], '/donnie/the/')
def test_vary_header(self): """ Should add vary header based on argument. """ pattern = redirect(r"^the/dude$", "abides", vary="Accept-Language") request = self.rf.get("the/dude") response = pattern.callback(request) assert response.status_code == 301 assert response["Location"] == "abides" assert response["Vary"] == "Accept-Language"
def test_locale_value_capture_ignore_locale(self): """ Should be able to ignore the original locale. """ resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$', '/donnie/the/{name}/', prepend_locale=False)]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get('/zh-TW/iam/the/walrus/')) eq_(resp.status_code, 301) eq_(resp['Location'], '/donnie/the/walrus/')
def test_locale_value_capture(self): """ Should prepend locale value automatically. """ resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$', '/donnie/the/{name}/')]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get('/pt-BR/iam/the/walrus/')) eq_(resp.status_code, 301) eq_(resp['Location'], '/pt-BR/donnie/the/walrus/')
def test_locale_value_capture_no_locale(self): """ Should get locale value in kwargs and not break if no locale in URL. """ resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$', '/donnie/the/{name}/')]) middleware = RedirectsMiddleware(resolver) resp = middleware.process_request(self.rf.get('/iam/the/walrus/')) eq_(resp.status_code, 301) eq_(resp['Location'], '/donnie/the/walrus/')
def test_to_view(self, mock_reverse): """ Should use return value of reverse as redirect location """ mock_reverse.return_value = '/just/your/opinion/man' pattern = redirect(r'^the/dude$', 'yeah.well.you.know.thats') request = self.rf.get('the/dude') response = pattern.callback(request) mock_reverse.assert_called_with('yeah.well.you.know.thats', args=None, kwargs=None) eq_(response.status_code, 301) eq_(response['Location'], '/just/your/opinion/man')