예제 #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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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
파일: test_util.py 프로젝트: yshlin/bedrock
 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')