コード例 #1
0
ファイル: test_util.py プロジェクト: mozilla/bedrock
 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
ファイル: test_util.py プロジェクト: kyoshino/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")
コード例 #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
ファイル: test_util.py プロジェクト: alexgibson/bedrock
 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
ファイル: test_util.py プロジェクト: mozilla/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)
     assert response.status_code == 302
     assert response["Location"] == "abides"
コード例 #7
0
ファイル: test_util.py プロジェクト: mozilla/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)
     assert response.status_code == 301
     assert response["Location"] == "abides"
コード例 #8
0
ファイル: test_util.py プロジェクト: mozilla/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)
     assert response.status_code == 301
     assert response["Location"] == "abides?aggression=not_stand"
コード例 #9
0
ファイル: test_util.py プロジェクト: benrito/bedrock
 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
ファイル: test_util.py プロジェクト: kyoshino/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")
コード例 #11
0
ファイル: test_util.py プロジェクト: mozilla/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=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
ファイル: test_util.py プロジェクト: kyoshino/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")
コード例 #13
0
ファイル: test_util.py プロジェクト: kyoshino/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/")
コード例 #14
0
ファイル: test_util.py プロジェクト: kyoshino/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/")
コード例 #15
0
ファイル: test_util.py プロジェクト: kyoshino/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/")
コード例 #16
0
ファイル: test_util.py プロジェクト: kyoshino/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/")
コード例 #17
0
ファイル: test_util.py プロジェクト: kyoshino/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")
コード例 #18
0
ファイル: test_util.py プロジェクト: mozilla/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)
     assert response.status_code == 301
     assert response["Location"] == "abides?want=a#toe"
コード例 #19
0
ファイル: test_util.py プロジェクト: mozilla/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=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
ファイル: test_util.py プロジェクト: kyoshino/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/")
コード例 #21
0
ファイル: test_util.py プロジェクト: kyoshino/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")
コード例 #22
0
ファイル: test_util.py プロジェクト: mozilla/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=resolver)
     resp = middleware.process_request(self.rf.get("/iam/the/walrus/"))
     assert resp.status_code == 301
     assert resp["Location"] == "/donnie/the/walrus/"
コード例 #23
0
ファイル: test_util.py プロジェクト: benrito/bedrock
 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
ファイル: test_util.py プロジェクト: mozilla/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=resolver)
     resp = middleware.process_request(self.rf.get("/iam/the/walrus/"))
     assert resp.status_code == 301
     assert resp["Location"] == "/donnie/the/walrus/"
コード例 #25
0
ファイル: test_util.py プロジェクト: benrito/bedrock
 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
ファイル: test_util.py プロジェクト: mozilla/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=resolver)
     resp = middleware.process_request(self.rf.get("/iam/the/"))
     assert resp.status_code == 301
     assert resp["Location"] == "/donnie/the/"
コード例 #27
0
ファイル: test_util.py プロジェクト: kyoshino/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")
コード例 #28
0
ファイル: test_util.py プロジェクト: benrito/bedrock
 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
ファイル: test_util.py プロジェクト: mozilla/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)
     assert response.status_code == 301
     assert response["Location"] == "abides"
コード例 #30
0
ファイル: test_util.py プロジェクト: kyoshino/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")
コード例 #31
0
ファイル: test_util.py プロジェクト: mozilla/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)
     assert response.status_code == 301
     assert response["Location"] == "abides?aggression=not_stand"
コード例 #32
0
ファイル: test_util.py プロジェクト: benrito/bedrock
 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
ファイル: test_util.py プロジェクト: alexgibson/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)
     assert response.status_code == 302
     assert response['Location'] == 'abides'
コード例 #34
0
ファイル: test_util.py プロジェクト: alexgibson/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)
     assert response.status_code == 301
     assert response['Location'] == 'abides'
コード例 #35
0
ファイル: test_util.py プロジェクト: alexgibson/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)
     assert response.status_code == 301
     assert response['Location'] == 'abides?want=a#toe'
コード例 #36
0
ファイル: test_util.py プロジェクト: alexgibson/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)
     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
ファイル: test_util.py プロジェクト: alexgibson/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)
     assert response.status_code == 301
     assert response['Location'] == 'abides'
コード例 #44
0
ファイル: test_util.py プロジェクト: alexgibson/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/'))
     assert resp.status_code == 301
     assert resp['Location'] == '/donnie/the/walrus/'
コード例 #45
0
ファイル: test_util.py プロジェクト: alexgibson/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/'))
     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
ファイル: test_util.py プロジェクト: mozilla/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)
     assert response.status_code == 301
     assert response["Location"] == "abides"
     assert response["cache-control"] == "max-age=7200"  # 2 hours
コード例 #48
0
ファイル: test_util.py プロジェクト: alexgibson/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/'))
     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
ファイル: test_util.py プロジェクト: alexgibson/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/'))
     assert resp.status_code == 301
     assert resp['Location'] == '/pt-BR/donnie/the/walrus/'
コード例 #51
0
ファイル: test_util.py プロジェクト: alexgibson/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)
     assert response.status_code == 301
     assert response['Location'] == 'abides'
     assert response['Vary'] == 'Accept-Language'
コード例 #52
0
ファイル: test_util.py プロジェクト: alexgibson/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)
     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
ファイル: test_util.py プロジェクト: alexgibson/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/'))
     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
ファイル: test_util.py プロジェクト: mozilla/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)
     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')