Changeset 1896 in products
- Timestamp:
- Mar 11, 2010 8:26:37 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/base.py
r1877 r1896 7 7 """ 8 8 import re 9 import transaction 9 10 from AccessControl.SecurityManagement import newSecurityManager 10 11 … … 16 17 from Products.CMFCore.utils import getToolByName 17 18 18 from Products.PloneTestCase.layer import onsetup 19 from Products.PloneTestCase.layer import onsetup, PloneSite 19 20 from Products.PloneTestCase import PloneTestCase as ptc 21 from Products.PloneTestCase import setup as ptc_setup 22 20 23 from Products.PloneTestCase.PloneTestCase import portal_owner 21 24 from Products.PloneTestCase.PloneTestCase import default_user … … 24 27 from quintagroup.seoptimizer.config import * 25 28 26 # When ZopeTestCase configures Zope, it will *not* auto-load products 27 # in Products/. Instead, we have to use a statement such as: 28 # ztc.installProduct('SimpleAttachment') 29 # This does *not* apply to products in eggs and Python packages (i.e. 30 # not in the Products.*) namespace. For that, see below. 31 # All of Plone's products are already set up by PloneTestCase. 29 ptc.setupPloneSite() 32 30 33 @onsetup 34 def setup_product(): 35 """Set up the package and its dependencies. 36 37 The @onsetup decorator causes the execution of this body to be 38 deferred until the setup of the Plone site testing layer. We could 39 have created our own layer, but this is the easiest way for Plone 40 integration tests. 31 class NotInstalled(PloneSite): 32 """ Only package register, without installation into portal 41 33 """ 42 34 43 # Load the ZCML configuration for the example.tests package. 44 # This can of course use <include /> to include other packages. 35 @classmethod 36 def setUp(cls): 37 fiveconfigure.debug_mode = True 38 import quintagroup.seoptimizer 39 zcml.load_config('configure.zcml', quintagroup.seoptimizer) 40 #zcml.load_config('overrides.zcml', quintagroup.seoptimizer) 41 fiveconfigure.debug_mode = False 42 ztc.installPackage(PROJECT_NAME) 45 43 46 fiveconfigure.debug_mode = True47 import quintagroup.seoptimizer48 zcml.load_config('configure.zcml', quintagroup.seoptimizer)49 #zcml.load_config('overrides.zcml', quintagroup.seoptimizer)50 fiveconfigure.debug_mode = False51 44 52 # We need to tell the testing framework that these products 53 # should be available. This can't happen until after we have loaded 54 # the ZCML. Thus, we do it here. Note the use of installPackage() 55 # instead of installProduct(). 56 # This is *only* necessary for packages outside the Products.* 57 # namespace which are also declared as Zope 2 products, using 58 # <five:registerPackage /> in ZCML. 45 class Installed(NotInstalled): 46 """ Install product into the portal 47 """ 48 @classmethod 49 def setUp(cls): 50 app = ztc.app() 51 portal = app[ptc_setup.portal_name] 52 qi = getattr(portal, 'portal_quickinstaller', None) 53 qi.installProduct(PROJECT_NAME) 54 transaction.commit() 59 55 60 # We may also need to load dependencies, e.g.:61 # ztc.installPackage('borg.localrole')62 63 # installPackage - register package in Control_Panel.Products64 # and results to QI can correctly use install/uninstall external65 # methods66 ztc.installPackage(PROJECT_NAME)67 68 # The order here is important: We first call the (deferred) function69 # which installs the products we need for this product. Then, we let70 # PloneTestCase set up this product on installation.71 72 setup_product()73 # Use products to force QI install method usage74 ptc.setupPloneSite(products=[PROJECT_NAME,])75 56 76 57 class MixinTestCase: … … 86 67 87 68 69 class TestCase(MixinTestCase, ptc.PloneTestCase): 70 layer = Installed 88 71 89 class TestCase(MixinTestCase, ptc.PloneTestCase): 90 """We use this base class for all the tests in this package. If 91 necessary, we can put common utility or setup code in here. This 92 applies to unit test cases. 93 """ 72 class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase): 73 layer = NotInstalled 74 94 75 95 76 class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase): 96 """We use this class for functional integration tests that use 97 doctest syntax. Again, we can put basic common utility or setup 98 code in here. 99 """ 77 layer = Installed 100 78 101 #def afterSetUp(self): 102 #roles = ('Member', 'Contributor') 103 #self.portal.portal_membership.addMember('contributor', 104 #'secret', 105 #roles, []) 106 107 #class TestErase(TestCase): 108 ## we use here nested layer for not to make an impact on 109 ## the rest test cases, this test case check uninstall procedure 110 ## thus it has to uninstall package which will be required to 111 ## be installed for other test cases 112 #class layer(PloneSiteLayer): 113 #@classmethod 114 #def setUp(cls): 115 #app = ztc.app() 116 #portal = app.plone 117 118 ## elevate permissions 119 #user = portal.getWrappedOwner() 120 #newSecurityManager(None, user) 121 122 #tool = getToolByName(portal, 'portal_quickinstaller') 123 #if tool.isProductInstalled(PROJECT_NAME): 124 #tool.uninstallProducts([PROJECT_NAME,]) 125 126 ## drop elevated perms 127 #noSecurityManager() 128 129 #transaction.commit() 130 #ztc.close(app) 131 79 class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase): 80 layer = NotInstalled
Note: See TracChangeset
for help on using the changeset viewer.