Permalink
Browse files

Merge pull request #11 from plone/ebrehault_fix_12038

fix for non-themed pages for anonymous + gzip
  • Loading branch information...
2 parents b667d71 + 94e4229 commit 88e3b95baaece02e29c2f195bf9fdda5b667124e @ebrehault ebrehault committed Nov 18, 2012
Showing with 187 additions and 1 deletion.
  1. +2 −0 buildout.cfg
  2. +3 −1 docs/HISTORY.txt
  3. +24 −0 src/plone/app/theming/testing.py
  4. +158 −0 src/plone/app/theming/tests/test_caching.py
View
2 buildout.cfg
@@ -44,6 +44,7 @@ repoze.xmliter = git ${remotes:repoze}/repoze.xmliter.git
lxml = git ${remotes:lxml}/lxml.git
plone.resourceeditor = git ${remotes:plone}/plone.resourceeditor.git
plone.app.themingplugins = git ${remotes:plone}/plone.app.themingplugins.git
+plone.app.caching = git ${remotes:plone}/plone.app.caching.git
[instance]
recipe = plone.recipe.zope2instance
@@ -70,6 +71,7 @@ eggs =
plone.resource [test]
plone.resourceeditor [test]
plone.subrequest [test]
+ plone.app.caching [test]
repoze.xmliter
defaults = ['--auto-color', '--auto-progress']
View
4 docs/HISTORY.txt
@@ -4,7 +4,9 @@ Changelog
1.1b2 (unreleased)
------------------
-- Nothing changed yet.
+- Add test about plone.app.theming / plone.app.caching integration when
+ using GZIP compression for anonymous
+ (see ticket `12038 <https://dev.plone.org/ticket/12038>`_). [ebrehault]
1.1b1 (2012-10-16)
View
24 src/plone/app/theming/testing.py
@@ -6,6 +6,7 @@
from plone.app.testing.layers import IntegrationTesting
from plone.app.testing.layers import FunctionalTesting
+
class Theming(PloneSandboxLayer):
defaultBases = (PLONE_FIXTURE,)
@@ -22,6 +23,29 @@ def setUpPloneSite(self, portal):
# install into the Plone site
applyProfile(portal, 'plone.app.theming:default')
+
+class ThemingWithCaching(Theming):
+ defaultBases = (PLONE_FIXTURE,)
+
+ def setUpZope(self, app, configurationContext):
+ # load ZCML
+ import plone.app.theming.tests
+ import plone.app.caching
+ xmlconfig.file('configure.zcml', plone.app.caching, context=configurationContext)
+ xmlconfig.file('configure.zcml', plone.app.theming.tests, context=configurationContext)
+
+ # Run the startup hook
+ from plone.app.theming.plugins.hooks import onStartup
+ onStartup(None)
+
+ def setUpPloneSite(self, portal):
+ # install into the Plone site
+ applyProfile(portal, 'plone.app.caching:default')
+ applyProfile(portal, 'plone.app.theming:default')
+ portal['portal_workflow'].setDefaultChain('simple_publication_workflow')
+
THEMING_FIXTURE = Theming()
THEMING_INTEGRATION_TESTING = IntegrationTesting(bases=(THEMING_FIXTURE,), name="Theming:Integration")
THEMING_FUNCTIONAL_TESTING = FunctionalTesting(bases=(THEMING_FIXTURE,), name="Theming:Functional")
+THEMINGWITHCACHING_FIXTURE = ThemingWithCaching()
+THEMINGWITHCACHING_TESTING = IntegrationTesting(bases=(THEMINGWITHCACHING_FIXTURE,), name="Theming:IntegrationWithCaching")
View
158 src/plone/app/theming/tests/test_caching.py
@@ -0,0 +1,158 @@
+import unittest2 as unittest
+from plone.testing.z2 import Browser
+from plone.app.testing import applyProfile, setRoles
+from plone.app.testing import TEST_USER_ID, TEST_USER_NAME, TEST_USER_PASSWORD
+
+import Globals
+import cStringIO
+import gzip
+
+from zope.component import provideUtility, provideAdapter, getUtility
+from zope.globalrequest import setRequest
+from plone.registry.interfaces import IRegistry
+from plone.registry import Registry
+
+from plone.app.caching.interfaces import IPloneCacheSettings
+from plone.caching.interfaces import ICacheSettings
+from plone.app.theming.interfaces import IThemeSettings
+from plone.app.theming.testing import THEMINGWITHCACHING_TESTING
+
+
+class TestIntegration(unittest.TestCase):
+
+ layer = THEMINGWITHCACHING_TESTING
+
+ def setUp(self):
+ self.settings = getUtility(IRegistry).forInterface(IThemeSettings)
+
+ self.settings.enabled = True
+ self.settings.rules = u'python://plone.app.theming/tests/rules.xml'
+ self.settings.parameterExpressions = {
+ 'stringParam': 'string:string param value',
+ 'boolParam': 'python:False',
+ 'contextParam' : 'context/absolute_url | string:no context',
+ 'requestParam': 'request/useother | string:off',
+ }
+
+ self.portal = self.layer['portal']
+ setRequest(self.portal.REQUEST)
+
+ applyProfile(self.portal, 'plone.app.caching:without-caching-proxy')
+
+ self.cacheSettings = getUtility(IRegistry).forInterface(ICacheSettings)
+ self.cacheSettings.enabled = True
+ self.cacheSettings.operationMapping = {'plone.content.folderView': 'plone.app.caching.weakCaching'}
+ registry = getUtility(IRegistry)
+ registry['plone.app.caching.weakCaching.ramCache'] = True
+
+ import transaction;
+ transaction.commit()
+
+ def tearDown(self):
+ setRequest(None)
+
+ def test_cache_without_GZIP(self):
+ ploneSettings = getUtility(IRegistry).forInterface(IPloneCacheSettings)
+ ploneSettings.enableCompression = False
+
+ app = self.layer['app']
+ portal = self.layer['portal']
+
+ # Folder content
+ setRoles(portal, TEST_USER_ID, ('Manager',))
+ portal.invokeFactory('Folder', 'f1')
+ portal['f1'].setTitle(u"Folder one")
+ portal['f1'].setDescription(u"Folder one description")
+ portal['f1'].reindexObject()
+
+ # Publish the folder
+ portal.portal_workflow.doActionFor(portal['f1'], 'publish')
+
+ import transaction; transaction.commit()
+ browser = Browser(app)
+ browser.open(portal['f1'].absolute_url())
+
+ # Title - pulled in with rules.xml
+ self.assertTrue(portal['f1'].Title() in browser.contents)
+
+ # Elsewhere - not pulled in
+ self.assertFalse("Accessibility" in browser.contents)
+
+ # The theme
+ self.assertTrue("This is the theme" in browser.contents)
+
+ def test_cache_with_GZIP_anonymous(self):
+ ploneSettings = getUtility(IRegistry).forInterface(IPloneCacheSettings)
+ ploneSettings.enableCompression = True
+
+ app = self.layer['app']
+ portal = self.layer['portal']
+
+ # Folder content
+ setRoles(portal, TEST_USER_ID, ('Manager',))
+ portal.invokeFactory('Folder', 'f2')
+ portal['f2'].setTitle(u"Folder two")
+ portal['f2'].setDescription(u"Folder two description")
+ portal['f2'].reindexObject()
+
+ # Publish the folder
+ portal.portal_workflow.doActionFor(portal['f2'], 'publish')
+
+ import transaction; transaction.commit()
+ browser = Browser(app)
+ browser.addHeader('Accept-Encoding', 'gzip')
+ browser.open(portal['f2'].absolute_url())
+ content_handler = cStringIO.StringIO(browser.contents)
+ uncompressed = gzip.GzipFile(fileobj=content_handler).read()
+
+ # Title - pulled in with rules.xml
+ self.assertTrue(portal['f2'].Title() in uncompressed)
+
+ # Elsewhere - not pulled in
+ self.assertFalse("Accessibility" in uncompressed)
+
+ # The theme
+ self.assertTrue("This is the theme" in uncompressed)
+
+ # headers
+ self.assertTrue('Accept-Encoding' in browser.headers['Vary'])
+ self.assertEqual('gzip', browser.headers['Content-Encoding'])
+
+ def test_cache_with_GZIP_authenticated(self):
+ ploneSettings = getUtility(IRegistry).forInterface(IPloneCacheSettings)
+ ploneSettings.enableCompression = True
+
+ app = self.layer['app']
+ portal = self.layer['portal']
+
+ # Folder content
+ setRoles(portal, TEST_USER_ID, ('Manager',))
+ portal.invokeFactory('Folder', 'f3')
+ portal['f3'].setTitle(u"Folder three")
+ portal['f3'].setDescription(u"Folder three description")
+ portal['f3'].reindexObject()
+
+ # Publish the folder
+ portal.portal_workflow.doActionFor(portal['f3'], 'publish')
+
+ import transaction; transaction.commit()
+ browser = Browser(app)
+ browser.addHeader('Accept-Encoding', 'gzip')
+ browser.addHeader('Authorization', 'Basic %s:%s' %
+ (TEST_USER_NAME, TEST_USER_PASSWORD,))
+ browser.open(portal['f3'].absolute_url())
+ content_handler = cStringIO.StringIO(browser.contents)
+ uncompressed = gzip.GzipFile(fileobj=content_handler).read()
+
+ # Title - pulled in with rules.xml
+ self.assertTrue(portal['f3'].Title() in uncompressed)
+
+ # Elsewhere - not pulled in
+ self.assertFalse("Accessibility" in uncompressed)
+
+ # The theme
+ self.assertTrue("This is the theme" in uncompressed)
+
+ # headers
+ self.assertTrue('Accept-Encoding' in browser.headers['Vary'])
+ self.assertEqual('gzip', browser.headers['Content-Encoding'])

0 comments on commit 88e3b95

Please sign in to comment.