incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [44/45] git commit: [#6942] Add tests for File ETag caching
Date Fri, 13 Dec 2013 05:08:30 GMT
[#6942] Add tests for File ETag caching

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@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/77e22d8c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/77e22d8c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/77e22d8c

Branch: refs/heads/tv/6942
Commit: 77e22d8c17b197c77657373ac95ef95ee6919237
Parents: 574e4a3
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Fri Dec 13 04:41:16 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Fri Dec 13 04:41:16 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/77e22d8c/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/77e22d8c/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'],


Mime
View raw message