Changeset 1896 in products


Ignore:
Timestamp:
Mar 11, 2010 8:26:37 PM (10 years ago)
Author:
mylan
Message:

#161: Add Installed and NotInstalled? layers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/base.py

    r1877 r1896  
    77""" 
    88import re 
     9import transaction 
    910from AccessControl.SecurityManagement import newSecurityManager 
    1011 
     
    1617from Products.CMFCore.utils import getToolByName 
    1718 
    18 from Products.PloneTestCase.layer import onsetup 
     19from Products.PloneTestCase.layer import onsetup, PloneSite 
    1920from Products.PloneTestCase import PloneTestCase as ptc 
     21from Products.PloneTestCase import setup as ptc_setup 
     22 
    2023from Products.PloneTestCase.PloneTestCase import portal_owner 
    2124from Products.PloneTestCase.PloneTestCase import default_user 
     
    2427from quintagroup.seoptimizer.config import * 
    2528 
    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. 
     29ptc.setupPloneSite() 
    3230 
    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. 
     31class NotInstalled(PloneSite): 
     32    """ Only package register, without installation into portal 
    4133    """ 
    4234 
    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) 
    4543 
    46     fiveconfigure.debug_mode = True 
    47     import quintagroup.seoptimizer 
    48     zcml.load_config('configure.zcml', quintagroup.seoptimizer) 
    49     #zcml.load_config('overrides.zcml', quintagroup.seoptimizer) 
    50     fiveconfigure.debug_mode = False 
    5144 
    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. 
     45class 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() 
    5955 
    60     # We may also need to load dependencies, e.g.: 
    61     #   ztc.installPackage('borg.localrole') 
    62  
    63     # installPackage - register package in Control_Panel.Products 
    64     # and results to QI can correctly use install/uninstall external 
    65     # methods 
    66     ztc.installPackage(PROJECT_NAME) 
    67  
    68 # The order here is important: We first call the (deferred) function 
    69 # which installs the products we need for this product. Then, we let 
    70 # PloneTestCase set up this product on installation. 
    71  
    72 setup_product() 
    73 # Use products to force QI install method usage                                  
    74 ptc.setupPloneSite(products=[PROJECT_NAME,])                                     
    7556 
    7657class MixinTestCase: 
     
    8667 
    8768 
     69class TestCase(MixinTestCase, ptc.PloneTestCase): 
     70    layer = Installed 
    8871 
    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     """ 
     72class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase): 
     73    layer = NotInstalled 
     74 
    9475 
    9576class 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 
    10078 
    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  
     79class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase): 
     80    layer = NotInstalled 
Note: See TracChangeset for help on using the changeset viewer.