Example #1
0
 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"
Example #2
0
 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")
Example #3
0
 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')
Example #4
0
 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'
Example #5
0
 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'
Example #6
0
 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"
Example #7
0
 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"
Example #8
0
 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"
Example #9
0
 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')
Example #10
0
 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")
Example #11
0
 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/"
Example #12
0
 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")
Example #13
0
 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/")
Example #14
0
 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/")
Example #15
0
 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/")
Example #16
0
 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/")
Example #17
0
 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")
Example #18
0
 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"
Example #19
0
 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/"
Example #20
0
 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/")
Example #21
0
 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")
Example #22
0
 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/"
Example #23
0
 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')
Example #24
0
 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/"
Example #25
0
 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')
Example #26
0
 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/"
Example #27
0
 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")
Example #28
0
 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')
Example #29
0
 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"
Example #30
0
 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")
Example #31
0
 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"
Example #32
0
 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')
Example #33
0
 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'
Example #34
0
 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'
Example #35
0
 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'
Example #36
0
 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'
Example #37
0
 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')
Example #38
0
 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')
Example #39
0
 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')
Example #40
0
 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')
Example #41
0
 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')
Example #42
0
 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/')
Example #43
0
 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'
Example #44
0
 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/'
Example #45
0
 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/'
Example #46
0
 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')
Example #47
0
 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
Example #48
0
 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/'
Example #49
0
 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')
Example #50
0
 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/'
Example #51
0
 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'
Example #52
0
 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
Example #53
0
 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
Example #54
0
 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/'
Example #55
0
 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/')
Example #56
0
 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"
Example #57
0
 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/')
Example #58
0
 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/')
Example #59
0
 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/')
Example #60
0
 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')