def test_UserID_member(self): from plone.app.caching.operations.etags import UserID class DummyMember(object): def getId(self): return 'bob' class DummyPortalState(object): implements(Interface) adapts(DummyContext, Interface) def __init__(self, context, request): pass def member(self): return DummyMember() provideAdapter(DummyPortalState, name=u"plone_portal_state") environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) etag = UserID(published, request) self.assertEqual('bob', etag())
def test_LastModified(self): from plone.app.caching.operations.etags import LastModified mod = datetime(2010, 1, 2, 3, 4, 5, 6, tzlocal()) utcStamp = time.mktime(mod.utctimetuple()) class DummyLastModified(object): implements(ILastModified) adapts(DummyPublished) def __init__(self, context): self.context = context def __call__(self): return mod provideAdapter(DummyLastModified) environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) etag = LastModified(published, request) self.assertEqual(str(utcStamp), etag())
def test_CatalogCounter(self): from plone.app.caching.operations.etags import CatalogCounter class DummyCatalog(object): def getCounter(self): return 10 class DummyTools(object): implements(Interface) adapts(DummyContext, Interface) def __init__(self, context, request): pass def catalog(self): return DummyCatalog() provideAdapter(DummyTools, name=u"plone_tools") environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) etag = CatalogCounter(published, request) self.assertEqual('10', etag())
def test_Roles_member(self): from plone.app.caching.operations.etags import Roles class DummyMember(object): def getRolesInContext(self, context): return ['Member', 'Manager'] class DummyPortalState(object): implements(Interface) adapts(DummyContext, Interface) def __init__(self, context, request): pass def anonymous(self): return False def member(self): return DummyMember() provideAdapter(DummyPortalState, name=u"plone_portal_state") environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) etag = Roles(published, request) self.assertEqual('Manager;Member', etag())
def test_LastModified_no_adapter(self): from plone.app.caching.operations.etags import LastModified environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) etag = LastModified(published, request) self.assertEqual(None, etag())
def test_GZip_no_registry(self): from plone.app.caching.operations.etags import GZip environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) etag = GZip(published, request) self.assertEqual('0', etag())
def test_Language_with_header(self): from plone.app.caching.operations.etags import Language environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) request.environ['HTTP_ACCEPT_LANGUAGE'] = 'en' etag = Language(published, request) self.assertEqual('en', etag())
def test_GZip_enabled(self): from plone.app.caching.operations.etags import GZip provideUtility(Registry(), IRegistry) registry = getUtility(IRegistry) registry.registerInterface(IPloneCacheSettings) ploneSettings = registry.forInterface(IPloneCacheSettings) ploneSettings.enableCompression = True environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) request.environ['HTTP_ACCEPT_ENCODING'] = 'deflate; gzip' etag = GZip(published, request) self.assertEqual('1', etag())
def test_Skin_default(self): from plone.app.caching.operations.etags import Skin environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) class DummyPortalSkins(object): def getRequestVarname(self): return 'skin_name' def getDefaultSkin(self): return 'defaultskin' published.__parent__.portal_skins = DummyPortalSkins() etag = Skin(published, request) self.assertEqual('defaultskin', etag())
def _make_composite(self): from OFS.Folder import Folder from ZPublisher.HTTPRequest import HTTPRequest from ZPublisher.HTTPRequest import HTTPResponse from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate from Products.CompositePage.composite import Composite from Products.CompositePage.element import CompositeElement from Products.CompositePage.slot import Slot TEMPLATE_TEXT = '\n'.join(( '<html>', '<body>', """<div tal:replace="structure slot: slot_a (top) """ """'Top News Stories'">slot_a</div>""", """<span tal:replace="structure slot: slot_b """ """'Other News'">slot_b</span>""", '<div tal:replace="structure context/slots/slot_c">slot_c</div>', '</body>', '</html>', )) f = Folder() f.getPhysicalPath = lambda: () f.getPhysicalRoot = lambda f=f: f req = f.REQUEST = HTTPRequest('', dict(HTTP_HOST='localhost:8080'), {}) req.response = HTTPResponse() f.composite = Composite() f.composite._setId("composite") t = ZopePageTemplate(id="template", text=TEMPLATE_TEXT, content_type="text/html") f.composite.template = t f.composite.filled_slots.slot_a = slot_a = Slot("slot_a") t = f.composite.template if t.pt_errors(): raise SyntaxError(t.pt_errors()) a1 = ZopePageTemplate(id="a1", text="<b>Slot A</b>") f._setObject(a1.id, a1) e1 = CompositeElement('e1', f.a1) slot_a._setObject(e1.id, e1) return f.composite
def test_ObjectLocked_false(self): from plone.app.caching.operations.etags import ObjectLocked class DummyContextState(object): implements(Interface) adapts(DummyContext, Interface) def __init__(self, context, request): pass def is_locked(self): return False provideAdapter(DummyContextState, name=u"plone_context_state") environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) etag = ObjectLocked(published, request) self.assertEqual('0', etag())
def test_LastModified_None(self): from plone.app.caching.operations.etags import LastModified class DummyLastModified(object): implements(ILastModified) adapts(DummyPublished) def __init__(self, context): self.context = context def __call__(self): return None provideAdapter(DummyLastModified) environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'} response = HTTPResponse() request = HTTPRequest(StringIO(), environ, response) published = DummyPublished(DummyContext()) etag = LastModified(published, request) self.assertEqual(None, etag())