File was renamed from pyramid/tests/test_static.py |
| | |
| | | self.assertEqual(inst.index, 'index.html') |
| | | |
| | | def test_call_adds_slash_path_info_empty(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':''}) |
| | | context = DummyContext() |
| | | from pyramid.httpexceptions import HTTPMovedPermanently |
| | | self.assertRaises(HTTPMovedPermanently, inst, context, request) |
| | | |
| | | def test_path_info_slash_means_index_html(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | | self.assertTrue(b'<html>static</html>' in response.body) |
| | | |
| | | def test_oob_singledot(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/./index.html'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | self.assertTrue(b'<html>static</html>' in response.body) |
| | | |
| | | def test_oob_emptyelement(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'//index.html'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | self.assertTrue(b'<html>static</html>' in response.body) |
| | | |
| | | def test_oob_dotdotslash(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/subdir/../../minimal.pt'}) |
| | | context = DummyContext() |
| | | from pyramid.httpexceptions import HTTPNotFound |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_oob_dotdotslash_encoded(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest( |
| | | {'PATH_INFO':'/subdir/%2E%2E%2F%2E%2E/minimal.pt'}) |
| | | context = DummyContext() |
| | |
| | | |
| | | def test_oob_os_sep(self): |
| | | import os |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | dds = '..' + os.sep |
| | | request = self._makeRequest({'PATH_INFO':'/subdir/%s%sminimal.pt' % |
| | | (dds, dds)}) |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_resource_doesnt_exist(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/notthere'}) |
| | | context = DummyContext() |
| | | from pyramid.httpexceptions import HTTPNotFound |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_resource_isdir(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/subdir/'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | | self.assertTrue(b'<html>subdir</html>' in response.body) |
| | | |
| | | def test_resource_is_file(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | |
| | | def test_resource_is_file_with_wsgi_file_wrapper(self): |
| | | from pyramid.response import _BLOCK_SIZE |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | class _Wrapper(object): |
| | | def __init__(self, file, block_size=None): |
| | |
| | | app_iter.file.close() |
| | | |
| | | def test_resource_is_file_with_cache_max_age(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static', cache_max_age=600) |
| | | inst = self._makeOne('tests:fixtures/static', cache_max_age=600) |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | 'Expires', 'Last-Modified']) |
| | | |
| | | def test_resource_is_file_with_no_cache_max_age(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static', |
| | | inst = self._makeOne('tests:fixtures/static', |
| | | cache_max_age=None) |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | context = DummyContext() |
| | |
| | | ['Content-Length', 'Content-Type', 'Last-Modified']) |
| | | |
| | | def test_resource_notmodified(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | request.if_modified_since = fiveyrsfuture |
| | | context = DummyContext() |
| | |
| | | app_iter.close() |
| | | |
| | | def test_not_found(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/notthere.html'}) |
| | | context = DummyContext() |
| | | from pyramid.httpexceptions import HTTPNotFound |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_gz_resource_no_content_encoding(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/arcs.svg.tgz'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | response.app_iter.close() |
| | | |
| | | def test_resource_no_content_encoding(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | self.assertEqual(inst.index, 'index.html') |
| | | |
| | | def test_call_adds_slash_path_info_empty(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':''}) |
| | | request.subpath = () |
| | | context = DummyContext() |
| | |
| | | self.assertRaises(HTTPMovedPermanently, inst, context, request) |
| | | |
| | | def test_path_info_slash_means_index_html(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = () |
| | | context = DummyContext() |
| | |
| | | self.assertTrue(b'<html>static</html>' in response.body) |
| | | |
| | | def test_oob_singledot(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('.', 'index.html') |
| | | context = DummyContext() |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_oob_emptyelement(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('', 'index.html') |
| | | context = DummyContext() |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_oob_dotdotslash(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('subdir', '..', '..', 'minimal.pt') |
| | | context = DummyContext() |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_oob_dotdotslash_encoded(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('subdir', '%2E%2E', '%2E%2E', 'minimal.pt') |
| | | context = DummyContext() |
| | |
| | | |
| | | def test_oob_os_sep(self): |
| | | import os |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | dds = '..' + os.sep |
| | | request = self._makeRequest() |
| | | request.subpath = ('subdir', dds, dds, 'minimal.pt') |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_resource_doesnt_exist(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('notthere,') |
| | | context = DummyContext() |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_resource_isdir(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('subdir',) |
| | | context = DummyContext() |
| | |
| | | self.assertTrue(b'<html>subdir</html>' in response.body) |
| | | |
| | | def test_resource_is_file(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('index.html',) |
| | | context = DummyContext() |
| | |
| | | self.assertTrue(b'<html>static</html>' in response.body) |
| | | |
| | | def test_resource_is_file_with_cache_max_age(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static', cache_max_age=600) |
| | | inst = self._makeOne('tests:fixtures/static', cache_max_age=600) |
| | | request = self._makeRequest() |
| | | request.subpath = ('index.html',) |
| | | context = DummyContext() |
| | |
| | | 'Expires', 'Last-Modified']) |
| | | |
| | | def test_resource_is_file_with_no_cache_max_age(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static', |
| | | inst = self._makeOne('tests:fixtures/static', |
| | | cache_max_age=None) |
| | | request = self._makeRequest() |
| | | request.subpath = ('index.html',) |
| | |
| | | ['Content-Length', 'Content-Type', 'Last-Modified']) |
| | | |
| | | def test_resource_notmodified(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.if_modified_since = fiveyrsfuture |
| | | request.subpath = ('index.html',) |
| | |
| | | app_iter.close() |
| | | |
| | | def test_not_found(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('notthere.html',) |
| | | context = DummyContext() |
| | |
| | | ('css/main-test.css', {})) |
| | | |
| | | def test_it_with_absspec(self): |
| | | fut = self._makeOne('pyramid.tests:fixtures/manifest.json') |
| | | fut = self._makeOne('tests:fixtures/manifest.json') |
| | | self.assertEqual(fut('foo', 'bar', {}), ('bar', {})) |
| | | self.assertEqual( |
| | | fut('foo', 'css/main.css', {}), |