Changeset 3014 in products for quintagroup.analytics/trunk/quintagroup/analytics/tests.py
- Timestamp:
- Nov 12, 2010 4:42:49 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.analytics/trunk/quintagroup/analytics/tests.py
r3004 r3014 2 2 import transaction 3 3 4 from AccessControl.SecurityManagement import newSecurityManager 4 5 from zope.component import testing, queryMultiAdapter 5 6 from Testing import ZopeTestCase as ztc … … 13 14 ptc.setupPloneSite() 14 15 16 class 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 39 class 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 15 85 class 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 38 87 39 88 #TO DO:===================================================================== 40 89 # add tests for every views methods; 41 90 # add doc tests to validate if all needed elements are present on page; 42 43 44 91 45 92 class TestQAInstallation(TestCase): … … 109 156 self.assert_(view, "Portlets Stats view isn't registered") 110 157 158 class 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 111 174 def test_suite(): 112 175 from unittest import TestSuite, makeSuite … … 136 199 137 200 test_suite.addTest(makeSuite(TestQAInstallation)) 201 test_suite.addTest(makeSuite(TestOwnershipByType)) 138 202 return test_suite 139 203
Note: See TracChangeset
for help on using the changeset viewer.