source: products/quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/base.py @ 3389

Last change on this file since 3389 was 865, checked in by chervol, 17 years ago

fixed the typo

File size: 3.5 KB
RevLine 
[798]1try:
2    from zope.annotation.interfaces import IAnnotations
3except ImportError:
4    from zope.app.annotation.interfaces import IAnnotations
5
[865]6from plone.browserlayer.layer import mark_layer
7
[775]8from  Testing import ZopeTestCase as ztc
[756]9from  Products.Five import zcml
10from  Products.Five import fiveconfigure
[775]11from Products.CMFCore.utils import getToolByName
12from Products.CMFCore.interfaces import IAction, IActionCategory
13from Products.CMFCore.ActionInformation import Action, ActionCategory
[756]14from  Products.PloneTestCase import PloneTestCase as ptc
15from  Products.PloneTestCase.layer import onsetup
16
[775]17from quintagroup.plonetabs.tests.data import PORTAL_ACTIONS, PORTAL_CONTENT
18
[756]19#ztc.installProduct('Zope2Product')
20
21@onsetup
22def setup_package():
[798]23    import quintagroup.plonetabs
24    zcml.load_config('configure.zcml', quintagroup.plonetabs)
25    #ztc.installPackage('some.other.package')
26    ztc.installPackage('quintagroup.plonetabs')
[756]27
28setup_package()
29ptc.setupPloneSite(products=['quintagroup.plonetabs'])
30
[798]31_marker = object()
32
[756]33class PloneTabsTestCase(ptc.PloneTestCase):
[775]34    """Common test base class"""
[798]35   
[865]36    def afterSetUp(self):
37        # due to some reason plone.browserlayer is not marking REQUEST
38        # with installed products layer interfaces
39        # so I'm doing it manually here
40        class DummyEvent(object):
41            def __init__(self, request):
42                self.request = request
43        mark_layer(self.portal, DummyEvent(self.portal.REQUEST))
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']
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())
58   
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'])
70   
71    def purgeContent(self):
72        ids = [obj.id for obj in self.portal.listFolderContents()]
73        self.portal.manage_delObjects(ids=ids)
74   
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'])
82   
83    def _createType(self, container, portal_type, id, **kwargs):
84        """Helper method to create content objects"""
85        ttool = getToolByName(container, 'portal_types')
86        portal_catalog =  getToolByName(container, 'portal_catalog')
87   
88        fti = ttool.getTypeInfo(portal_type)
89        fti.constructInstance(container, id, **kwargs)
90        obj = getattr(container.aq_inner.aq_explicit, id)
91   
92        # publish and reindex
93        #self._publish_item(portal, obj)
94        portal_catalog.indexObject(obj)
95        return obj
Note: See TracBrowser for help on using the repository browser.