Skip to content

Commit

Permalink
Merge pull request #11 from plone/ebrehault_fix_12038
Browse files Browse the repository at this point in the history
fix for non-themed pages for anonymous + gzip
  • Loading branch information
ebrehault committed Nov 18, 2012
2 parents b667d71 + 94e4229 commit 88e3b95
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 1 deletion.
2 changes: 2 additions & 0 deletions buildout.cfg
Expand Up @@ -44,6 +44,7 @@ repoze.xmliter = git ${remotes:repoze}/repoze.xmliter.git
lxml = git ${remotes:lxml}/lxml.git lxml = git ${remotes:lxml}/lxml.git
plone.resourceeditor = git ${remotes:plone}/plone.resourceeditor.git plone.resourceeditor = git ${remotes:plone}/plone.resourceeditor.git
plone.app.themingplugins = git ${remotes:plone}/plone.app.themingplugins.git plone.app.themingplugins = git ${remotes:plone}/plone.app.themingplugins.git
plone.app.caching = git ${remotes:plone}/plone.app.caching.git


[instance] [instance]
recipe = plone.recipe.zope2instance recipe = plone.recipe.zope2instance
Expand All @@ -70,6 +71,7 @@ eggs =
plone.resource [test] plone.resource [test]
plone.resourceeditor [test] plone.resourceeditor [test]
plone.subrequest [test] plone.subrequest [test]
plone.app.caching [test]
repoze.xmliter repoze.xmliter
defaults = ['--auto-color', '--auto-progress'] defaults = ['--auto-color', '--auto-progress']


Expand Down
4 changes: 3 additions & 1 deletion docs/HISTORY.txt
Expand Up @@ -4,7 +4,9 @@ Changelog
1.1b2 (unreleased) 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) 1.1b1 (2012-10-16)
Expand Down
24 changes: 24 additions & 0 deletions src/plone/app/theming/testing.py
Expand Up @@ -6,6 +6,7 @@
from plone.app.testing.layers import IntegrationTesting from plone.app.testing.layers import IntegrationTesting
from plone.app.testing.layers import FunctionalTesting from plone.app.testing.layers import FunctionalTesting



class Theming(PloneSandboxLayer): class Theming(PloneSandboxLayer):
defaultBases = (PLONE_FIXTURE,) defaultBases = (PLONE_FIXTURE,)


Expand All @@ -22,6 +23,29 @@ def setUpPloneSite(self, portal):
# install into the Plone site # install into the Plone site
applyProfile(portal, 'plone.app.theming:default') 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_FIXTURE = Theming()
THEMING_INTEGRATION_TESTING = IntegrationTesting(bases=(THEMING_FIXTURE,), name="Theming:Integration") THEMING_INTEGRATION_TESTING = IntegrationTesting(bases=(THEMING_FIXTURE,), name="Theming:Integration")
THEMING_FUNCTIONAL_TESTING = FunctionalTesting(bases=(THEMING_FIXTURE,), name="Theming:Functional") THEMING_FUNCTIONAL_TESTING = FunctionalTesting(bases=(THEMING_FIXTURE,), name="Theming:Functional")
THEMINGWITHCACHING_FIXTURE = ThemingWithCaching()
THEMINGWITHCACHING_TESTING = IntegrationTesting(bases=(THEMINGWITHCACHING_FIXTURE,), name="Theming:IntegrationWithCaching")
158 changes: 158 additions & 0 deletions 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.