| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # File: testDemandTypeTermWorkflow.py |
|---|
| 4 | # |
|---|
| 5 | # Copyright (c) 2007 by CommunesPlone |
|---|
| 6 | # Generator: ArchGenXML Version 1.5.1-svn |
|---|
| 7 | # http://plone.org/products/archgenxml |
|---|
| 8 | # |
|---|
| 9 | # GNU General Public License (GPL) |
|---|
| 10 | # |
|---|
| 11 | # This program is free software; you can redistribute it and/or |
|---|
| 12 | # modify it under the terms of the GNU General Public License |
|---|
| 13 | # as published by the Free Software Foundation; either version 2 |
|---|
| 14 | # of the License, or (at your option) any later version. |
|---|
| 15 | # |
|---|
| 16 | # This program is distributed in the hope that it will be useful, |
|---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 19 | # GNU General Public License for more details. |
|---|
| 20 | # |
|---|
| 21 | # You should have received a copy of the GNU General Public License |
|---|
| 22 | # along with this program; if not, write to the Free Software |
|---|
| 23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|---|
| 24 | # 02110-1301, USA. |
|---|
| 25 | # |
|---|
| 26 | |
|---|
| 27 | __author__ = """Gauthier BASTIEN <gbastien@commune.sambreville.be>, Stephan GEULETTE <stephan.geulette@uvcw.be>""" |
|---|
| 28 | __docformat__ = 'plaintext' |
|---|
| 29 | |
|---|
| 30 | import os, sys |
|---|
| 31 | if __name__ == '__main__': |
|---|
| 32 | execfile(os.path.join(sys.path[0], 'framework.py')) |
|---|
| 33 | |
|---|
| 34 | ##code-section module-header #fill in your manual code here |
|---|
| 35 | from Products.TeleServices.config import * |
|---|
| 36 | from Products.TeleServices.tests.BaseTeleServicesTestCase import BaseTeleServicesTestCase |
|---|
| 37 | from AccessControl import Unauthorized |
|---|
| 38 | from AccessControl.SecurityManagement import getSecurityManager |
|---|
| 39 | from Products.CMFCore.permissions import View, AccessContentsInformation, ModifyPortalContent |
|---|
| 40 | from Products.TeleServices import TeleServicesReview, ManageTeleServices |
|---|
| 41 | from Products.CMFCore.utils import getToolByName |
|---|
| 42 | ##/code-section module-header |
|---|
| 43 | |
|---|
| 44 | # |
|---|
| 45 | # Test-cases for class(es) |
|---|
| 46 | # |
|---|
| 47 | |
|---|
| 48 | from Testing import ZopeTestCase |
|---|
| 49 | |
|---|
| 50 | # Import the tested classes |
|---|
| 51 | |
|---|
| 52 | ##code-section module-beforeclass #fill in your manual code here |
|---|
| 53 | ##/code-section module-beforeclass |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | class testDemandTypeTermWorkflow(BaseTeleServicesTestCase): |
|---|
| 57 | """Test-cases for class(es) .""" |
|---|
| 58 | |
|---|
| 59 | ##code-section class-header_testDemandTypeTermWorkflow #fill in your manual code here |
|---|
| 60 | ##/code-section class-header_testDemandTypeTermWorkflow |
|---|
| 61 | |
|---|
| 62 | def afterSetUp(self): |
|---|
| 63 | """ |
|---|
| 64 | |
|---|
| 65 | """ |
|---|
| 66 | BaseTeleServicesTestCase.afterSetup(self) |
|---|
| 67 | |
|---|
| 68 | # Manually created methods |
|---|
| 69 | |
|---|
| 70 | def testInitialState(self): |
|---|
| 71 | """ On teste ici l'etat initial """ |
|---|
| 72 | wft = self.wft |
|---|
| 73 | self.login("admin") |
|---|
| 74 | dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms |
|---|
| 75 | term_id = dtf.invokeFactory('DemandTypeTerm', id='test_term') |
|---|
| 76 | term_obj = getattr(dtf, term_id) |
|---|
| 77 | self.login("member") |
|---|
| 78 | self.assertEquals(wft.getInfoFor(term_obj, 'review_state'), 'on_line') |
|---|
| 79 | |
|---|
| 80 | def testPermissionsInStateOn_line(self): |
|---|
| 81 | """ we test the permissions of differents roles when a term is in state on_line """ |
|---|
| 82 | self.login("admin") |
|---|
| 83 | dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms |
|---|
| 84 | term_id = dtf.invokeFactory('DemandTypeTerm', id='test_term') |
|---|
| 85 | term_obj = getattr(dtf, term_id) |
|---|
| 86 | term_obj = getattr(dtf, 'carte-identite-enfant') |
|---|
| 87 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') |
|---|
| 88 | #the Owner have the 'View', 'Access contents information' but not 'Modify portal content' |
|---|
| 89 | self.login("member") |
|---|
| 90 | sm = getSecurityManager() |
|---|
| 91 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 92 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 93 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 94 | #Manager has every permissions |
|---|
| 95 | self.login('admin') |
|---|
| 96 | sm = getSecurityManager() |
|---|
| 97 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 98 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 99 | self.failUnless(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 100 | #PopulationTSManager |
|---|
| 101 | self.login('ptsmanager') |
|---|
| 102 | sm = getSecurityManager() |
|---|
| 103 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 104 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 105 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 106 | #WorkTSManager |
|---|
| 107 | self.login('wtsmanager') |
|---|
| 108 | sm = getSecurityManager() |
|---|
| 109 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 110 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 111 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 112 | #Anonymous |
|---|
| 113 | self.login('anon') |
|---|
| 114 | sm = getSecurityManager() |
|---|
| 115 | self.failIf(sm.checkPermission(View, term_obj)) |
|---|
| 116 | self.failIf(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 117 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 118 | |
|---|
| 119 | def testPermissionsInStateInfo_only(self): |
|---|
| 120 | """ we test the permissions of differents roles when a term is in state info_only """ |
|---|
| 121 | self.login("admin") |
|---|
| 122 | dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms |
|---|
| 123 | term_id = dtf.invokeFactory('DemandTypeTerm', id='test_term') |
|---|
| 124 | term_obj = getattr(dtf, term_id) |
|---|
| 125 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') |
|---|
| 126 | #we set the term in info_only state |
|---|
| 127 | self.wft.doActionFor(term_obj, 'for_info_only') |
|---|
| 128 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "info_only") |
|---|
| 129 | #the Owner have the 'View', 'Access contents information' but not 'Modify portal content' |
|---|
| 130 | self.login("member") |
|---|
| 131 | sm = getSecurityManager() |
|---|
| 132 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 133 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 134 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 135 | #Manager has every permissions |
|---|
| 136 | self.login('admin') |
|---|
| 137 | sm = getSecurityManager() |
|---|
| 138 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 139 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 140 | self.failUnless(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 141 | #PopulationTSManager |
|---|
| 142 | self.login('ptsmanager') |
|---|
| 143 | sm = getSecurityManager() |
|---|
| 144 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 145 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 146 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 147 | #WorkTSManager |
|---|
| 148 | self.login('wtsmanager') |
|---|
| 149 | sm = getSecurityManager() |
|---|
| 150 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 151 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 152 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 153 | #Anonymous |
|---|
| 154 | self.login('anon') |
|---|
| 155 | sm = getSecurityManager() |
|---|
| 156 | self.failIf(sm.checkPermission(View, term_obj)) |
|---|
| 157 | self.failIf(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 158 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 159 | |
|---|
| 160 | def testPermissionsInStateDisabled(self): |
|---|
| 161 | """ we test the permissions of differents roles when a term is in state disabled """ |
|---|
| 162 | self.login("admin") |
|---|
| 163 | dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms |
|---|
| 164 | term_id = dtf.invokeFactory('DemandTypeTerm', id='test_term') |
|---|
| 165 | term_obj = getattr(dtf, term_id) |
|---|
| 166 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') |
|---|
| 167 | #we set the term in disabled state |
|---|
| 168 | self.wft.doActionFor(term_obj, 'for_info_only') |
|---|
| 169 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "info_only") |
|---|
| 170 | self.wft.doActionFor(term_obj, 'disable') |
|---|
| 171 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "disabled") |
|---|
| 172 | #the Owner have the 'View', 'Access contents information' but not 'Modify portal content' |
|---|
| 173 | self.login("member") |
|---|
| 174 | sm = getSecurityManager() |
|---|
| 175 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 176 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 177 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 178 | #Manager has every permissions |
|---|
| 179 | self.login('admin') |
|---|
| 180 | sm = getSecurityManager() |
|---|
| 181 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 182 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 183 | self.failUnless(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 184 | #PopulationTSManager |
|---|
| 185 | self.login('ptsmanager') |
|---|
| 186 | sm = getSecurityManager() |
|---|
| 187 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 188 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 189 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 190 | #WorkTSManager |
|---|
| 191 | self.login('wtsmanager') |
|---|
| 192 | sm = getSecurityManager() |
|---|
| 193 | self.failUnless(sm.checkPermission(View, term_obj)) |
|---|
| 194 | self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 195 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 196 | #Anonymous |
|---|
| 197 | self.login('anon') |
|---|
| 198 | sm = getSecurityManager() |
|---|
| 199 | self.failIf(sm.checkPermission(View, term_obj)) |
|---|
| 200 | self.failIf(sm.checkPermission(AccessContentsInformation, term_obj)) |
|---|
| 201 | self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) |
|---|
| 202 | |
|---|
| 203 | def testTransitionFromOn_line(self): |
|---|
| 204 | """ we test the available transitions for differents roles when the term is in the on_line state """ |
|---|
| 205 | self.login("admin") |
|---|
| 206 | dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms |
|---|
| 207 | term_id = dtf.invokeFactory('DemandTypeTerm', id='test_term') |
|---|
| 208 | term_obj = getattr(dtf, term_id) |
|---|
| 209 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') |
|---|
| 210 | #we log as PopulationTeleServicesManager |
|---|
| 211 | self.login('ptsmanager') |
|---|
| 212 | self.checkActionList(term_obj, []) |
|---|
| 213 | #member |
|---|
| 214 | self.login("member") |
|---|
| 215 | self.checkActionList(term_obj, []) |
|---|
| 216 | #Manager |
|---|
| 217 | self.login('admin') |
|---|
| 218 | self.checkActionList(term_obj, ['for_info_only']) |
|---|
| 219 | #WTSManager |
|---|
| 220 | self.login('wtsmanager') |
|---|
| 221 | self.checkActionList(term_obj, []) |
|---|
| 222 | #Anonymous |
|---|
| 223 | self.login('anon') |
|---|
| 224 | self.checkActionList(term_obj, []) |
|---|
| 225 | |
|---|
| 226 | def testTransitionFromInfo_only(self): |
|---|
| 227 | """ we test the available transitions for differents roles when the term is in the info_only state """ |
|---|
| 228 | self.login("admin") |
|---|
| 229 | dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms |
|---|
| 230 | term_id = dtf.invokeFactory('DemandTypeTerm', id='test_term') |
|---|
| 231 | term_obj = getattr(dtf, term_id) |
|---|
| 232 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') |
|---|
| 233 | #we set the term in info_only state |
|---|
| 234 | self.wft.doActionFor(term_obj, 'for_info_only') |
|---|
| 235 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "info_only") |
|---|
| 236 | #we log as PopulationTeleServicesManager |
|---|
| 237 | self.login('ptsmanager') |
|---|
| 238 | self.checkActionList(term_obj, []) |
|---|
| 239 | #member |
|---|
| 240 | self.login("member") |
|---|
| 241 | self.checkActionList(term_obj, []) |
|---|
| 242 | #Manager |
|---|
| 243 | self.login('admin') |
|---|
| 244 | self.checkActionList(term_obj, ['disable', 'put_on_line']) |
|---|
| 245 | #WTSManager |
|---|
| 246 | self.login('wtsmanager') |
|---|
| 247 | self.checkActionList(term_obj, []) |
|---|
| 248 | #Anonymous |
|---|
| 249 | self.login('anon') |
|---|
| 250 | self.checkActionList(term_obj, []) |
|---|
| 251 | |
|---|
| 252 | def testTransitionFromDisabled(self): |
|---|
| 253 | """ we test the available transitions for differents roles when the term is in the disabled state """ |
|---|
| 254 | self.login("admin") |
|---|
| 255 | dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms |
|---|
| 256 | term_id = dtf.invokeFactory('DemandTypeTerm', id='test_term') |
|---|
| 257 | term_obj = getattr(dtf, term_id) |
|---|
| 258 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') |
|---|
| 259 | #we set the term in disabled state |
|---|
| 260 | self.wft.doActionFor(term_obj, 'for_info_only') |
|---|
| 261 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "info_only") |
|---|
| 262 | self.wft.doActionFor(term_obj, 'disable') |
|---|
| 263 | self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "disabled") |
|---|
| 264 | #we log as PopulationTeleServicesManager |
|---|
| 265 | self.login('ptsmanager') |
|---|
| 266 | self.checkActionList(term_obj, []) |
|---|
| 267 | #member |
|---|
| 268 | self.login("member") |
|---|
| 269 | self.checkActionList(term_obj, []) |
|---|
| 270 | #Manager |
|---|
| 271 | self.login('admin') |
|---|
| 272 | self.checkActionList(term_obj, ['enable']) |
|---|
| 273 | #WTSManager |
|---|
| 274 | self.login('wtsmanager') |
|---|
| 275 | self.checkActionList(term_obj, []) |
|---|
| 276 | #Anonymous |
|---|
| 277 | self.login('anon') |
|---|
| 278 | self.checkActionList(term_obj, []) |
|---|
| 279 | |
|---|
| 280 | def test_suite(): |
|---|
| 281 | from unittest import TestSuite, makeSuite |
|---|
| 282 | suite = TestSuite() |
|---|
| 283 | suite.addTest(makeSuite(testDemandTypeTermWorkflow)) |
|---|
| 284 | return suite |
|---|
| 285 | |
|---|
| 286 | ##code-section module-footer #fill in your manual code here |
|---|
| 287 | ##/code-section module-footer |
|---|
| 288 | |
|---|
| 289 | if __name__ == '__main__': |
|---|
| 290 | framework() |
|---|
| 291 | |
|---|
| 292 | |
|---|