You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/12/16 18:59:01 UTC
[6/9] git commit: [#6942] Add tests for File ETag caching
[#6942] Add tests for File ETag caching
Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/d6a9e5e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/d6a9e5e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/d6a9e5e5
Branch: refs/heads/master
Commit: d6a9e5e5de5b4bc921ecb1a2d2f14de64ec8258e
Parents: 5164b74
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Fri Dec 13 04:41:16 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Dec 16 17:58:46 2013 +0000
----------------------------------------------------------------------
Allura/allura/lib/utils.py | 2 +-
Allura/allura/tests/model/test_filesystem.py | 12 +++++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d6a9e5e5/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 55b36f0..60097c5 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -481,7 +481,7 @@ def take_while_true(source):
def serve_file(fp, filename, content_type, last_modified=None, cache_expires=None, size=None, embed=True):
'''Sets the response headers and serves as a wsgi iter'''
if filename and last_modified:
- etag_cache('{0}?{1}'.format(filename, last_modified))
+ etag_cache(u'{0}?{1}'.format(filename, last_modified))
pylons.response.headers['Content-Type'] = ''
pylons.response.content_type = content_type.encode('utf-8')
pylons.response.cache_expires = cache_expires or asint(tg.config.get('files_expires_header_secs', 60 * 60))
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d6a9e5e5/Allura/allura/tests/model/test_filesystem.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_filesystem.py b/Allura/allura/tests/model/test_filesystem.py
index a10b0ef..1272ecd 100644
--- a/Allura/allura/tests/model/test_filesystem.py
+++ b/Allura/allura/tests/model/test_filesystem.py
@@ -22,7 +22,7 @@ from unittest import TestCase
from cStringIO import StringIO
from io import BytesIO
-from pylons import tmpl_context as c
+from pylons import tmpl_context as c, app_globals as g
from ming.orm import session, Mapper
from nose.tools import assert_equal
from mock import patch
@@ -124,8 +124,11 @@ class TestFile(TestCase):
f = File.from_data(u'te s\u0b6e1.txt', 'test1')
self.session.flush()
with patch('allura.lib.utils.tg.request', Request.blank('/')), \
- patch('allura.lib.utils.pylons.response', Response()) as response:
+ patch('allura.lib.utils.pylons.response', Response()) as response, \
+ patch('allura.lib.utils.etag_cache') as etag_cache:
response_body = list(f.serve())
+ etag_cache.assert_called_once_with(u'{}?{}'.format(f.filename,
+ f._id.generation_time))
assert_equal([ 'test1' ], response_body)
assert_equal(response.content_type, f.content_type)
assert 'Content-Disposition' not in response.headers
@@ -134,8 +137,11 @@ class TestFile(TestCase):
f = File.from_data(u'te s\u0b6e1.txt', 'test1')
self.session.flush()
with patch('allura.lib.utils.tg.request', Request.blank('/')), \
- patch('allura.lib.utils.pylons.response', Response()) as response:
+ patch('allura.lib.utils.pylons.response', Response()) as response, \
+ patch('allura.lib.utils.etag_cache') as etag_cache:
response_body = list(f.serve(embed=False))
+ etag_cache.assert_called_once_with(u'{}?{}'.format(f.filename,
+ f._id.generation_time))
assert_equal([ 'test1' ], response_body)
assert_equal(response.content_type, f.content_type)
assert_equal(response.headers['Content-Disposition'],