Ignore:
Timestamp:
Nov 12, 2010 4:42:49 PM (13 years ago)
Author:
fenix
Message:

added test for getUsers method of 'ownership_by_type' view.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.analytics/trunk/quintagroup/analytics/tests.py

    r3004 r3014  
    22import transaction 
    33 
     4from AccessControl.SecurityManagement import newSecurityManager 
    45from zope.component import testing, queryMultiAdapter 
    56from Testing import ZopeTestCase as ztc 
     
    1314ptc.setupPloneSite() 
    1415 
     16class Installed(PloneSite): 
     17 
     18    @classmethod 
     19    def setUp(cls): 
     20        fiveconfigure.debug_mode = True 
     21        zcml.load_config('configure.zcml', 
     22                         quintagroup.analytics) 
     23        fiveconfigure.debug_mode = False 
     24        ztc.installPackage('quintagroup.analytics') 
     25        app = ztc.app() 
     26        portal = app[ptc_setup.portal_name] 
     27 
     28        # Sets the local site/manager 
     29        ptc_setup._placefulSetUp(portal) 
     30 
     31        qi = getattr(portal, 'portal_quickinstaller', None) 
     32        qi.installProduct('quintagroup.analytics') 
     33        transaction.commit() 
     34 
     35    @classmethod 
     36    def tearDown(cls): 
     37            pass 
     38 
     39class SetUpContent(Installed): 
     40 
     41    max = 10 
     42    types_ = ['Document', 'Event', 'Folder'] 
     43    users = [('user%s'%i, 'user%s'%i, 'Member', None) 
     44             for i in xrange(max)] 
     45 
     46    @classmethod 
     47    def setupUsers(cls, portal): 
     48        """ Creates users.""" 
     49        acl_users = portal.acl_users 
     50        mp = portal.portal_membership 
     51        map(acl_users._doAddUser, *zip(*cls.users)) 
     52        if not mp.memberareaCreationFlag: 
     53            mp.setMemberareaCreationFlag() 
     54        map(mp.createMemberArea, [u[0] for u in cls.users]) 
     55 
     56    @classmethod 
     57    def setupContent(cls, portal): 
     58        """ Creates users""" 
     59        uf = portal.acl_users 
     60        pm = portal.portal_membership 
     61        pc = portal.portal_catalog 
     62        users = [u[0] for u in cls.users] 
     63        for u in users: 
     64            folder = pm.getHomeFolder(u) 
     65            user = uf.getUserById(u) 
     66            if not hasattr(user, 'aq_base'): 
     67                user = user.__of__(uf) 
     68            newSecurityManager(None, user) 
     69            for i in xrange(users.index(u)+cls.max): 
     70                map(folder.invokeFactory, cls.types_, [t+str(i) for t in cls.types_]) 
     71        transaction.commit() 
     72 
     73 
     74    @classmethod 
     75    def setUp(cls): 
     76        app = ztc.app() 
     77        portal = app[ptc_setup.portal_name] 
     78        cls.setupUsers(portal) 
     79        cls.setupContent(portal) 
     80 
     81    @classmethod 
     82    def tearDown(cls): 
     83        pass 
     84 
    1585class TestCase(ptc.PloneTestCase): 
    16     class layer(PloneSite): 
    17         @classmethod 
    18         def setUp(cls): 
    19             fiveconfigure.debug_mode = True 
    20             zcml.load_config('configure.zcml', 
    21                              quintagroup.analytics) 
    22             fiveconfigure.debug_mode = False 
    23             ztc.installPackage('quintagroup.analytics') 
    24             app = ztc.app() 
    25             portal = app[ptc_setup.portal_name] 
    26  
    27             # Sets the local site/manager 
    28             ptc_setup._placefulSetUp(portal) 
    29  
    30             qi = getattr(portal, 'portal_quickinstaller', None) 
    31             qi.installProduct('quintagroup.analytics') 
    32             transaction.commit() 
    33  
    34         @classmethod 
    35         def tearDown(cls): 
    36             pass 
    37  
     86    layer = Installed 
    3887 
    3988#TO DO:===================================================================== 
    4089#      add tests for every views methods; 
    4190#      add doc tests to validate if all needed elements are present on page; 
    42  
    43  
    4491 
    4592class TestQAInstallation(TestCase): 
     
    109156        self.assert_(view, "Portlets Stats view isn't registered") 
    110157 
     158class TestOwnershipByType(TestCase): 
     159    """Tests all ownership by type view methods.""" 
     160 
     161    layer = SetUpContent 
     162 
     163    def test_getUsers(self): 
     164        """ 
     165        """ 
     166        view = queryMultiAdapter((self.portal, self.portal.REQUEST), 
     167                                 name="ownership_by_type") 
     168 
     169        self.assert_(False in map(lambda u1, u2:u1==u2, 
     170                     [u[0] for u in self.layer.users], view.getUsers())) 
     171 
     172 
     173 
    111174def test_suite(): 
    112175    from unittest import TestSuite, makeSuite 
     
    136199 
    137200    test_suite.addTest(makeSuite(TestQAInstallation)) 
     201    test_suite.addTest(makeSuite(TestOwnershipByType)) 
    138202    return test_suite 
    139203 
Note: See TracChangeset for help on using the changeset viewer.