[798] | 1 | try: |
---|
| 2 | from zope.annotation.interfaces import IAnnotations |
---|
| 3 | except ImportError: |
---|
| 4 | from zope.app.annotation.interfaces import IAnnotations |
---|
| 5 | |
---|
[775] | 6 | from Testing import ZopeTestCase as ztc |
---|
[756] | 7 | from Products.Five import zcml |
---|
| 8 | from Products.Five import fiveconfigure |
---|
[775] | 9 | from Products.CMFCore.utils import getToolByName |
---|
| 10 | from Products.CMFCore.interfaces import IAction, IActionCategory |
---|
| 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 | |
---|
| 19 | @onsetup |
---|
| 20 | def setup_package(): |
---|
[798] | 21 | import quintagroup.plonetabs |
---|
| 22 | zcml.load_config('configure.zcml', quintagroup.plonetabs) |
---|
| 23 | #ztc.installPackage('some.other.package') |
---|
| 24 | ztc.installPackage('quintagroup.plonetabs') |
---|
[756] | 25 | |
---|
| 26 | setup_package() |
---|
| 27 | ptc.setupPloneSite(products=['quintagroup.plonetabs']) |
---|
| 28 | |
---|
[798] | 29 | _marker = object() |
---|
| 30 | |
---|
[756] | 31 | class PloneTabsTestCase(ptc.PloneTestCase): |
---|
[775] | 32 | """Common test base class""" |
---|
[798] | 33 | |
---|
| 34 | def purgeCache(self, request): |
---|
| 35 | annotations = IAnnotations(request) |
---|
| 36 | cache = annotations.get('plone.memoize', _marker) |
---|
| 37 | if cache is not _marker: |
---|
| 38 | del annotations['plone.memoize'] |
---|
| 39 | |
---|
[775] | 40 | def purgeActions(self): |
---|
| 41 | for obj in self.tool.objectValues(): |
---|
| 42 | self.tool._delObject(obj.id) |
---|
| 43 | #if IAction.providedBy(obj): |
---|
| 44 | #self.tool._delObject(obj.id) |
---|
| 45 | #elif IActionCategory.providedBy(obj): |
---|
| 46 | #obj.manage_delObjects(ids=obj.objectIds()) |
---|
| 47 | |
---|
| 48 | def setupActions(self, parent, kids=PORTAL_ACTIONS): |
---|
| 49 | ids = parent.objectIds() |
---|
| 50 | for id, child in kids: |
---|
| 51 | if child['type'] == 'action' and id not in ids: |
---|
| 52 | parent._setObject(id, Action(id, **child)) |
---|
| 53 | continue |
---|
| 54 | if child['type'] == 'category': |
---|
| 55 | if id not in ids: |
---|
| 56 | parent._setObject(id, ActionCategory(id)) |
---|
| 57 | if child.get('children', {}): |
---|
| 58 | self.setupActions(getattr(parent, id), child['children']) |
---|
| 59 | |
---|
| 60 | def purgeContent(self): |
---|
| 61 | ids = [obj.id for obj in self.portal.listFolderContents()] |
---|
| 62 | self.portal.manage_delObjects(ids=ids) |
---|
| 63 | |
---|
| 64 | def setupContent(self, parent, kids=PORTAL_CONTENT): |
---|
| 65 | ids = parent.objectIds() |
---|
| 66 | for id, child in kids: |
---|
| 67 | if id not in ids: |
---|
| 68 | self._createType(parent, child['type'], id, **child) |
---|
| 69 | if child.get('children', {}) and id in ids: |
---|
| 70 | self.setupContent(getattr(parent, id), child['children']) |
---|
| 71 | |
---|
| 72 | def _createType(self, container, portal_type, id, **kwargs): |
---|
| 73 | """Helper method to create content objects""" |
---|
| 74 | ttool = getToolByName(container, 'portal_types') |
---|
| 75 | portal_catalog = getToolByName(container, 'portal_catalog') |
---|
| 76 | |
---|
| 77 | fti = ttool.getTypeInfo(portal_type) |
---|
| 78 | fti.constructInstance(container, id, **kwargs) |
---|
| 79 | obj = getattr(container.aq_inner.aq_explicit, id) |
---|
| 80 | |
---|
| 81 | # publish and reindex |
---|
| 82 | #self._publish_item(portal, obj) |
---|
| 83 | portal_catalog.indexObject(obj) |
---|
| 84 | return obj |
---|