summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Rukavina <marin@shinyshell.net>2012-05-02 02:24:39 +0200
committerMarin Rukavina <marin@shinyshell.net>2012-05-02 02:24:39 +0200
commit04af145ab4b19d6fe0c4a5087c1722868d6fcedc (patch)
tree3f424c9fe9bd22abbddbb2b7fe1b7f751e7136e2
parentfaf33bf3bf999c8b38aa79a8bae11d4078bc4739 (diff)
downloadpyramid-04af145ab4b19d6fe0c4a5087c1722868d6fcedc.tar.gz
pyramid-04af145ab4b19d6fe0c4a5087c1722868d6fcedc.tar.bz2
pyramid-04af145ab4b19d6fe0c4a5087c1722868d6fcedc.zip
Fixed up the tests and returned HTTPMovedPermanently
-rw-r--r--pyramid/static.py6
-rw-r--r--pyramid/tests/test_static.py109
2 files changed, 87 insertions, 28 deletions
diff --git a/pyramid/static.py b/pyramid/static.py
index 63ca58597..50b274dae 100644
--- a/pyramid/static.py
+++ b/pyramid/static.py
@@ -108,7 +108,7 @@ class static_view(object):
resource_path ='%s/%s' % (self.docroot.rstrip('/'), path)
if resource_isdir(self.package_name, resource_path):
if not request.path_url.endswith('/'):
- self.add_slash_redirect(request)
+ return 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 @@ class static_view(object):
filepath = normcase(normpath(join(self.norm_docroot, path)))
if isdir(filepath):
if not request.path_url.endswith('/'):
- self.add_slash_redirect(request)
+ return self.add_slash_redirect(request)
filepath = join(filepath, self.index)
if not exists(filepath):
raise HTTPNotFound(request.url)
@@ -132,7 +132,7 @@ class static_view(object):
qs = request.query_string
if qs:
url = url + '?' + qs
- raise HTTPMovedPermanently(url)
+ return HTTPMovedPermanently(url)
_seps = set(['/', os.sep])
def _contains_slash(item):
diff --git a/pyramid/tests/test_static.py b/pyramid/tests/test_static.py
index 7f94df990..300647099 100644
--- a/pyramid/tests/test_static.py
+++ b/pyramid/tests/test_static.py
@@ -70,16 +70,26 @@ class Test_static_view_use_subpath_False(unittest.TestCase):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest({'PATH_INFO':'/subdir/../../minimal.pt'})
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_oob_dotdotslash_encoded(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest(
{'PATH_INFO':'/subdir/%2E%2E%2F%2E%2E/minimal.pt'})
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_oob_os_sep(self):
import os
@@ -88,15 +98,25 @@ class Test_static_view_use_subpath_False(unittest.TestCase):
request = self._makeRequest({'PATH_INFO':'/subdir/%s%sminimal.pt' %
(dds, dds)})
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_resource_doesnt_exist(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest({'PATH_INFO':'/notthere'})
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_resource_isdir(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
@@ -174,8 +194,13 @@ class Test_static_view_use_subpath_False(unittest.TestCase):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest({'PATH_INFO':'/notthere.html'})
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_resource_with_content_encoding(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
@@ -251,33 +276,52 @@ class Test_static_view_use_subpath_True(unittest.TestCase):
request = self._makeRequest()
request.subpath = ('.', 'index.html')
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_oob_emptyelement(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest()
request.subpath = ('', 'index.html')
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_oob_dotdotslash(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest()
request.subpath = ('subdir', '..', '..', 'minimal.pt')
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_oob_dotdotslash_encoded(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest()
request.subpath = ('subdir', '%2E%2E', '%2E%2E', 'minimal.pt')
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
-
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_oob_os_sep(self):
import os
inst = self._makeOne('pyramid.tests:fixtures/static')
@@ -285,16 +329,26 @@ class Test_static_view_use_subpath_True(unittest.TestCase):
request = self._makeRequest()
request.subpath = ('subdir', dds, dds, 'minimal.pt')
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_resource_doesnt_exist(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
request = self._makeRequest()
request.subpath = ('notthere,')
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
def test_resource_isdir(self):
inst = self._makeOne('pyramid.tests:fixtures/static')
@@ -361,8 +415,13 @@ class Test_static_view_use_subpath_True(unittest.TestCase):
request = self._makeRequest()
request.subpath = ('notthere.html',)
context = DummyContext()
- response = inst(context, request)
- self.assertEqual(response.status, '404 Not Found')
+ from pyramid.httpexceptions import HTTPNotFound
+ try:
+ response = inst(context, request)
+ except HTTPNotFound as e:
+ self.assertEqual(e.code, 404)
+ else:
+ self.assertEqual(response.status, '404 Not Found')
class DummyContext:
pass