source: products/quintagroup.plonetabs/branches/tests/quintagroup/plonetabs/tests/base.py @ 3402

Last change on this file since 3402 was 3402, checked in by potar, 12 years ago

Fixing pep8

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
[3402]21
[756]22@onsetup
23def setup_package():
[798]24    import quintagroup.plonetabs
25    zcml.load_config('configure.zcml', quintagroup.plonetabs)
26    #ztc.installPackage('some.other.package')
27    ztc.installPackage('quintagroup.plonetabs')
[756]28
29setup_package()
30ptc.setupPloneSite(products=['quintagroup.plonetabs'])
31
[798]32_marker = object()
33
[3402]34
[756]35class 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
Note: See TracBrowser for help on using the repository browser.