Permalink
Browse files

Updated tests for static files and made static.py raise all HTTP exce…

…ptions
  • Loading branch information...
1 parent 04af145 commit 3d65afea0d2bd529a87f72d87a986c989ebffd29 @vipera vipera committed May 2, 2012
Showing with 25 additions and 13 deletions.
  1. +3 −3 pyramid/static.py
  2. +22 −10 pyramid/tests/test_static.py
View
@@ -108,7 +108,7 @@ def __call__(self, context, request):
resource_path ='%s/%s' % (self.docroot.rstrip('/'), path)
if resource_isdir(self.package_name, resource_path):
if not request.path_url.endswith('/'):
- return self.add_slash_redirect(request)
+ self.add_slash_redirect(request)
resource_path = '%s/%s' % (resource_path.rstrip('/'),self.index)
if not resource_exists(self.package_name, resource_path):
raise HTTPNotFound(request.url)
@@ -120,7 +120,7 @@ def __call__(self, context, request):
filepath = normcase(normpath(join(self.norm_docroot, path)))
if isdir(filepath):
if not request.path_url.endswith('/'):
- return self.add_slash_redirect(request)
+ self.add_slash_redirect(request)
filepath = join(filepath, self.index)
if not exists(filepath):
raise HTTPNotFound(request.url)
@@ -132,7 +132,7 @@ def add_slash_redirect(self, request):
qs = request.query_string
if qs:
url = url + '?' + qs
- return HTTPMovedPermanently(url)
+ raise HTTPMovedPermanently(url)
_seps = set(['/', os.sep])
def _contains_slash(item):
@@ -38,11 +38,17 @@ def test_call_adds_slash_path_info_empty(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest({'PATH_INFO':''})
context = DummyContext()
- response = inst(context, request)
- response.prepare(request.environ)
- self.assertEqual(response.status, '301 Moved Permanently')
- self.assertTrue(b'http://example.com:6543/' in response.body)
-
+ from pyramid.httpexceptions import HTTPMovedPermanently
+ try:
+ response = inst(context, request)
+ except HTTPMovedPermanently as e:
+ self.assertEqual(e.code, 301)
+ self.assertTrue(b'http://example.com:6543/' in e.location)
+ else:
+ response.prepare(request.environ)
+ self.assertEqual(response.status, '301 Moved Permanently')
+ self.assertTrue(b'http://example.com:6543/' in response.body)
+
def test_path_info_slash_means_index_html(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest()
@@ -258,11 +264,17 @@ def test_call_adds_slash_path_info_empty(self):
request = self._makeRequest({'PATH_INFO':''})
request.subpath = ()
context = DummyContext()
- response = inst(context, request)
- response.prepare(request.environ)
- self.assertEqual(response.status, '301 Moved Permanently')
- self.assertTrue(b'http://example.com:6543/' in response.body)
-
+ from pyramid.httpexceptions import HTTPMovedPermanently
+ try:
+ response = inst(context, request)
+ except HTTPMovedPermanently as e:
+ self.assertEqual(e.code, 301)
+ self.assertTrue(b'http://example.com:6543/' in e.location)
+ else:
+ response.prepare(request.environ)
+ self.assertEqual(response.status, '301 Moved Permanently')
+ self.assertTrue(b'http://example.com:6543/' in response.body)
+
def test_path_info_slash_means_index_html(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest()

0 comments on commit 3d65afe

Please sign in to comment.