[798] | 1 | try: |
---|
| 2 | from zope.annotation.interfaces import IAnnotations |
---|
[3406] | 3 | IAnnotations # pyflakes |
---|
[798] | 4 | except ImportError: |
---|
| 5 | from zope.app.annotation.interfaces import IAnnotations |
---|
[865] | 6 | from plone.browserlayer.layer import mark_layer |
---|
| 7 | |
---|
[775] | 8 | from Testing import ZopeTestCase as ztc |
---|
[756] | 9 | from Products.Five import zcml |
---|
[775] | 10 | from Products.CMFCore.utils import getToolByName |
---|
| 11 | from Products.CMFCore.ActionInformation import Action, ActionCategory |
---|
[756] | 12 | from Products.PloneTestCase import PloneTestCase as ptc |
---|
| 13 | from Products.PloneTestCase.layer import onsetup |
---|
| 14 | |
---|
[775] | 15 | from quintagroup.plonetabs.tests.data import PORTAL_ACTIONS, PORTAL_CONTENT |
---|
| 16 | |
---|
[756] | 17 | #ztc.installProduct('Zope2Product') |
---|
| 18 | |
---|
[3402] | 19 | |
---|
[756] | 20 | @onsetup |
---|
[3411] | 21 | dejf setup_package(): |
---|
[798] | 22 | import quintagroup.plonetabs |
---|
| 23 | zcml.load_config('configure.zcml', quintagroup.plonetabs) |
---|
| 24 | #ztc.installPackage('some.other.package') |
---|
| 25 | ztc.installPackage('quintagroup.plonetabs') |
---|
[756] | 26 | |
---|
| 27 | setup_package() |
---|
[3410] | 28 | if ptc.PLONE30: |
---|
[3411] | 29 | ptc.setupPloneSite(products=["plone.browserlayer"]) |
---|
[756] | 30 | ptc.setupPloneSite(products=['quintagroup.plonetabs']) |
---|
| 31 | |
---|
[798] | 32 | _marker = object() |
---|
| 33 | |
---|
[3402] | 34 | |
---|
[756] | 35 | class PloneTabsTestCase(ptc.PloneTestCase): |
---|
[775] | 36 | """Common test base class""" |
---|
[3402] | 37 | |
---|
[865] | 38 | def afterSetUp(self): |
---|
| 39 | # due to some reason plone.browserlayer is not marking REQUEST |
---|
| 40 | # with installed products layer interfaces |
---|
[3402] | 41 | # so I'm doing it manually here |
---|
[865] | 42 | class DummyEvent(object): |
---|
| 43 | def __init__(self, request): |
---|
| 44 | self.request = request |
---|
| 45 | mark_layer(self.portal, DummyEvent(self.portal.REQUEST)) |
---|
[3402] | 46 | |
---|
[798] | 47 | def purgeCache(self, request): |
---|
| 48 | annotations = IAnnotations(request) |
---|
| 49 | cache = annotations.get('plone.memoize', _marker) |
---|
| 50 | if cache is not _marker: |
---|
| 51 | del annotations['plone.memoize'] |
---|
[3402] | 52 | |
---|
[775] | 53 | def purgeActions(self): |
---|
| 54 | for obj in self.tool.objectValues(): |
---|
| 55 | self.tool._delObject(obj.id) |
---|
| 56 | #if IAction.providedBy(obj): |
---|
| 57 | #self.tool._delObject(obj.id) |
---|
| 58 | #elif IActionCategory.providedBy(obj): |
---|
| 59 | #obj.manage_delObjects(ids=obj.objectIds()) |
---|
[3402] | 60 | |
---|
[775] | 61 | def setupActions(self, parent, kids=PORTAL_ACTIONS): |
---|
| 62 | ids = parent.objectIds() |
---|
| 63 | for id, child in kids: |
---|
| 64 | if child['type'] == 'action' and id not in ids: |
---|
| 65 | parent._setObject(id, Action(id, **child)) |
---|
| 66 | continue |
---|
| 67 | if child['type'] == 'category': |
---|
| 68 | if id not in ids: |
---|
| 69 | parent._setObject(id, ActionCategory(id)) |
---|
| 70 | if child.get('children', {}): |
---|
| 71 | self.setupActions(getattr(parent, id), child['children']) |
---|
[3402] | 72 | |
---|
[775] | 73 | def purgeContent(self): |
---|
| 74 | ids = [obj.id for obj in self.portal.listFolderContents()] |
---|
| 75 | self.portal.manage_delObjects(ids=ids) |
---|
[3402] | 76 | |
---|
[775] | 77 | def setupContent(self, parent, kids=PORTAL_CONTENT): |
---|
| 78 | ids = parent.objectIds() |
---|
| 79 | for id, child in kids: |
---|
| 80 | if id not in ids: |
---|
| 81 | self._createType(parent, child['type'], id, **child) |
---|
| 82 | if child.get('children', {}) and id in ids: |
---|
| 83 | self.setupContent(getattr(parent, id), child['children']) |
---|
[3402] | 84 | |
---|
[775] | 85 | def _createType(self, container, portal_type, id, **kwargs): |
---|
| 86 | """Helper method to create content objects""" |
---|
| 87 | ttool = getToolByName(container, 'portal_types') |
---|
[3402] | 88 | portal_catalog = getToolByName(container, 'portal_catalog') |
---|
| 89 | |
---|
[775] | 90 | fti = ttool.getTypeInfo(portal_type) |
---|
| 91 | fti.constructInstance(container, id, **kwargs) |
---|
| 92 | obj = getattr(container.aq_inner.aq_explicit, id) |
---|
[3402] | 93 | |
---|
[775] | 94 | # publish and reindex |
---|
| 95 | #self._publish_item(portal, obj) |
---|
| 96 | portal_catalog.indexObject(obj) |
---|
| 97 | return obj |
---|