source: products/collective.referencedatagridfield/trunk/collective/referencedatagridfield/tests/base.py

Last change on this file was 2356, checked in by mylan, 14 years ago

Added getSecurityManager import

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1import unittest
2
3#from zope.testing import doctestunit
4#from zope.component import testing
5from Products.Five import zcml
6from Products.Five import fiveconfigure
7from Testing import ZopeTestCase as ztc
8from AccessControl import getSecurityManager
9from AccessControl.SecurityManagement import getSecurityManager
10from AccessControl.SecurityManagement import setSecurityManager
11
12from Products.Archetypes.tests.utils import makeContent
13
14from Products.Five import fiveconfigure
15from Products.PloneTestCase import PloneTestCase as ptc
16from Products.PloneTestCase.layer import PloneSite
17
18# install site
19ptc.setupPloneSite(extension_profiles=[
20        'collective.referencedatagridfield:default',
21        'collective.referencedatagridfield:examples'
22        ])
23
24import collective.referencedatagridfield
25
26class MixIn(object):
27    """ Mixin for setting up the necessary bits for testing the
28        collective.referencedatagridfield
29    """
30
31    class layer(PloneSite):
32
33        @classmethod
34        def setUp(cls):
35            fiveconfigure.debug_mode = True
36            zcml.load_config('configure.zcml',
37                             collective.referencedatagridfield)
38            ztc.installPackage('collective.referencedatagridfield')
39            fiveconfigure.debug_mode = False
40
41        @classmethod
42        def tearDown(cls):
43            pass
44
45    def createDemo(self, wfaction=None):
46        # Create tested content
47        sm = getSecurityManager()
48        self.loginAsPortalOwner()
49        content = {
50            "demo": {"type":'ReferenceDataGridDemoType', "title": 'RDGF Demo'},
51            "doc": {"type":'Document', "title": 'Test Document'},
52            "doc2": {"type":'Document', "title": 'Test Document 2'},
53            }
54        try:
55            wf = self.portal.portal_workflow
56            for cid, data in content.items():
57                makeContent(self.portal, portal_type=data['type'], id=cid)
58                obj = getattr(self.portal, cid)
59                obj.setTitle(data['title'])
60                obj.reindexObject()
61                if wfaction:
62                    wf.doActionFor(obj, wfaction)
63                setattr(self, cid, obj)
64        finally:
65            setSecurityManager(sm)
66
67class TestCase(MixIn, ptc.PloneTestCase):
68    """ Base TestCase for collective.referencedatagridfield """
69
70class FunctionalTestCase(MixIn, ptc.FunctionalTestCase):
71    """ Base TestCase for collective.referencedatagridfield """
72
Note: See TracBrowser for help on using the repository browser.