[798] | 1 | try: |
---|
| 2 | from zope.annotation.interfaces import IAnnotations |
---|
| 3 | except ImportError: |
---|
| 4 | from zope.app.annotation.interfaces import IAnnotations |
---|
| 5 | |
---|
[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 |
---|
| 21 | def 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() |
---|
| 28 | ptc.setupPloneSite(products=['quintagroup.plonetabs']) |
---|
| 29 | |
---|
[798] | 30 | _marker = object() |
---|
| 31 | |
---|
[3402] | 32 | |
---|
[756] | 33 | class PloneTabsTestCase(ptc.PloneTestCase): |
---|
[775] | 34 | """Common test base class""" |
---|
[3402] | 35 | |
---|
[865] | 36 | def afterSetUp(self): |
---|
| 37 | # due to some reason plone.browserlayer is not marking REQUEST |
---|
| 38 | # with installed products layer interfaces |
---|
[3402] | 39 | # so I'm doing it manually here |
---|
[865] | 40 | class DummyEvent(object): |
---|
| 41 | def __init__(self, request): |
---|
| 42 | self.request = request |
---|
| 43 | mark_layer(self.portal, DummyEvent(self.portal.REQUEST)) |
---|
[3402] | 44 | |
---|
[798] | 45 | def purgeCache(self, request): |
---|
| 46 | annotations = IAnnotations(request) |
---|
| 47 | cache = annotations.get('plone.memoize', _marker) |
---|
| 48 | if cache is not _marker: |
---|
| 49 | del annotations['plone.memoize'] |
---|
[3402] | 50 | |
---|
[775] | 51 | def purgeActions(self): |
---|
| 52 | for obj in self.tool.objectValues(): |
---|
| 53 | self.tool._delObject(obj.id) |
---|
| 54 | #if IAction.providedBy(obj): |
---|
| 55 | #self.tool._delObject(obj.id) |
---|
| 56 | #elif IActionCategory.providedBy(obj): |
---|
| 57 | #obj.manage_delObjects(ids=obj.objectIds()) |
---|
[3402] | 58 | |
---|
[775] | 59 | def setupActions(self, parent, kids=PORTAL_ACTIONS): |
---|
| 60 | ids = parent.objectIds() |
---|
| 61 | for id, child in kids: |
---|
| 62 | if child['type'] == 'action' and id not in ids: |
---|
| 63 | parent._setObject(id, Action(id, **child)) |
---|
| 64 | continue |
---|
| 65 | if child['type'] == 'category': |
---|
| 66 | if id not in ids: |
---|
| 67 | parent._setObject(id, ActionCategory(id)) |
---|
| 68 | if child.get('children', {}): |
---|
| 69 | self.setupActions(getattr(parent, id), child['children']) |
---|
[3402] | 70 | |
---|
[775] | 71 | def purgeContent(self): |
---|
| 72 | ids = [obj.id for obj in self.portal.listFolderContents()] |
---|
| 73 | self.portal.manage_delObjects(ids=ids) |
---|
[3402] | 74 | |
---|
[775] | 75 | def setupContent(self, parent, kids=PORTAL_CONTENT): |
---|
| 76 | ids = parent.objectIds() |
---|
| 77 | for id, child in kids: |
---|
| 78 | if id not in ids: |
---|
| 79 | self._createType(parent, child['type'], id, **child) |
---|
| 80 | if child.get('children', {}) and id in ids: |
---|
| 81 | self.setupContent(getattr(parent, id), child['children']) |
---|
[3402] | 82 | |
---|
[775] | 83 | def _createType(self, container, portal_type, id, **kwargs): |
---|
| 84 | """Helper method to create content objects""" |
---|
| 85 | ttool = getToolByName(container, 'portal_types') |
---|
[3402] | 86 | portal_catalog = getToolByName(container, 'portal_catalog') |
---|
| 87 | |
---|
[775] | 88 | fti = ttool.getTypeInfo(portal_type) |
---|
| 89 | fti.constructInstance(container, id, **kwargs) |
---|
| 90 | obj = getattr(container.aq_inner.aq_explicit, id) |
---|
[3402] | 91 | |
---|
[775] | 92 | # publish and reindex |
---|
| 93 | #self._publish_item(portal, obj) |
---|
| 94 | portal_catalog.indexObject(obj) |
---|
| 95 | return obj |
---|