You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/12/13 20:29:32 UTC

git commit: [#6942] Fix tests and css caching

Updated Branches:
  refs/heads/tv/6942 d75c7cdc4 -> 699baceca


[#6942] Fix tests and css caching

- Switch to using md5 for css etag caching, which will be consistent
  across procs and restarts.

- Fix filesystem tests to account for etag encoding.

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/699bacec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/699bacec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/699bacec

Branch: refs/heads/tv/6942
Commit: 699baceca860386a559dfee4740c7c4dc77793c4
Parents: d75c7cd
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Fri Dec 13 19:29:12 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Dec 13 19:29:12 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/static.py          | 6 +++---
 Allura/allura/lib/app_globals.py             | 8 ++++----
 Allura/allura/tests/model/test_filesystem.py | 4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/699bacec/Allura/allura/controllers/static.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/static.py b/Allura/allura/controllers/static.py
index ce04bbe..53b8be5 100644
--- a/Allura/allura/controllers/static.py
+++ b/Allura/allura/controllers/static.py
@@ -22,7 +22,6 @@ from tg.decorators import without_trailing_slash
 from webob import exc
 
 from pylons import tmpl_context as c, app_globals as g
-from pylons.controllers.util import etag_cache
 from allura.lib import helpers as h
 from allura.lib import utils
 
@@ -48,5 +47,6 @@ class NewForgeController(object):
         """Serve stylesheet containing icon urls for every installed tool.
 
         """
-        return utils.serve_file(StringIO(g.tool_icon_css),
-                'tool_icon_css', 'text/css', last_modified=g.server_start)
+        css, md5 = g.tool_icon_css
+        return utils.serve_file(StringIO(css), 'tool_icon_css', 'text/css',
+                last_modified=md5)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/699bacec/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 17e3b89..8f49d90 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -139,7 +139,6 @@ class Globals(object):
         self.__dict__ = self.__shared_state
         if self.__shared_state: return
         self.allura_templates = pkg_resources.resource_filename('allura', 'templates')
-        self.server_start = datetime.datetime.utcnow()
         # Setup SOLR
         self.solr_server = aslist(config.get('solr.server'), ',')
         # skip empty strings in case of extra commas
@@ -472,8 +471,9 @@ class Globals(object):
 
     @LazyProperty
     def tool_icon_css(self):
-        """Return a string of CSS containing class names and icon urls for
-        every installed tool.
+        """Return a (css, md5) tuple, where ``css`` is a string of CSS
+        containing class names and icon urls for every installed tool, and
+        ``md5`` is the md5 hexdigest of ``css``.
 
         """
         css = ''
@@ -482,7 +482,7 @@ class Globals(object):
                 url = self.theme.app_icon_url(tool_name.lower(), size)
                 css += '.ui-icon-tool-%s-%i {background: url(%s) no-repeat;}\n' % (
                         tool_name, size, url)
-        return css
+        return css, hashlib.md5(css).hexdigest()
 
     @property
     def resource_manager(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/699bacec/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 1272ecd..3b625f7 100644
--- a/Allura/allura/tests/model/test_filesystem.py
+++ b/Allura/allura/tests/model/test_filesystem.py
@@ -128,7 +128,7 @@ class TestFile(TestCase):
                 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))
+                f._id.generation_time).encode('utf-8'))
             assert_equal([ 'test1' ], response_body)
             assert_equal(response.content_type, f.content_type)
             assert 'Content-Disposition' not in response.headers
@@ -141,7 +141,7 @@ class TestFile(TestCase):
                 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))
+                f._id.generation_time).encode('utf-8'))
             assert_equal([ 'test1' ], response_body)
             assert_equal(response.content_type, f.content_type)
             assert_equal(response.headers['Content-Disposition'],