示例#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"
示例#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")
示例#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')
示例#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'
示例#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'
示例#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"
示例#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"
示例#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"
示例#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')
示例#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")
示例#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/"
示例#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")
示例#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/")
示例#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/")
示例#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/")
示例#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/")
示例#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")
示例#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"
示例#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/"
示例#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/")
示例#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")
示例#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/"
示例#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')
示例#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/"
示例#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')
示例#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/"
示例#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")
示例#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')
示例#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"
示例#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")
示例#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"
示例#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')
示例#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'
示例#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'
示例#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'
示例#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'
示例#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')
示例#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')
示例#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')
示例#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')
示例#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')
示例#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/')
示例#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'
示例#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/'
示例#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/'
示例#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')
示例#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
示例#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/'
示例#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')
示例#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/'
示例#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'
示例#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
示例#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
示例#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/'
示例#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/')
示例#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"
示例#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/')
示例#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/')
示例#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/')
示例#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')