Changeset 6603
- Timestamp:
- 13 Aug 2011, 02:53:35 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_browser.py
r6600 r6603 27 27 from StringIO import StringIO 28 28 from datetime import datetime 29 from mechanize import LinkNotFoundError 29 30 from zope.component import createObject 30 31 from zope.component.hooks import setSite, clearSite 32 from zope.security.interfaces import Unauthorized 31 33 from zope.testbrowser.testing import Browser 32 34 from hurry.workflow.interfaces import IWorkflowInfo … … 70 72 71 73 self.root_path = 'http://localhost/app/applicants' 74 self.manage_root_path = self.root_path + '/@@manage' 75 self.add_container_path = self.root_path + '/@@add' 72 76 self.container_path = 'http://localhost/app/applicants/app2009' 77 self.manage_container_path = self.container_path + '/@@manage' 73 78 74 79 # Add an applicants container … … 114 119 clearSite() 115 120 shutil.rmtree(self.dc_root) 116 #import pdb; pdb.set_trace() 117 118 class ApplicantsUITests(ApplicantsFullSetup): 121 122 class ApplicantsRootUITests(ApplicantsFullSetup): 119 123 # Tests for ApplicantsRoot class 120 124 … … 122 126 123 127 def test_anonymous_access(self): 124 # Anonymous users can access applicants root and applicants containers128 # Anonymous users can access applicants root 125 129 self.browser.open(self.root_path) 126 130 self.assertEqual(self.browser.headers['Status'], '200 Ok') 127 131 self.assertFalse( 128 132 'Manage' in self.browser.contents) 129 self.browser.open(self.container_path) 130 self.assertEqual(self.browser.headers['Status'], '200 Ok') 131 self.assertFalse( 132 'Manage' in self.browser.contents) 133 return 134 135 def test_manage_cert_access(self): 136 # Managers can access CERT1 137 cert_path = 'http://localhost/app/faculties/fac1/dep1/certificates/CERT1' 138 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 139 self.browser.open(cert_path) 140 self.assertEqual(self.browser.headers['Status'], '200 Ok') 133 134 def test_anonymous_no_actions(self): 135 # Make sure anonymous users cannot access actions 136 self.browser.open(self.root_path) 137 self.assertRaises( 138 LookupError, self.browser.getControl, "Add local role") 139 # Manage screen neither linked nor accessible for anonymous 140 self.assertRaises( 141 LinkNotFoundError, 142 self.browser.getLink, 'Manage application section') 143 self.assertRaises( 144 Unauthorized, self.browser.open, self.manage_root_path) 145 # Add container screen not accessible for anonymous 146 self.assertRaises( 147 Unauthorized, self.browser.open, self.add_container_path) 148 return 141 149 142 150 def test_manage_access(self): 143 # Managers can access the manage pages of applicants root and 144 # applicants containers and can perform actions 151 # Managers can access the manage pages of applicants root 145 152 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 146 153 self.browser.open(self.root_path) 147 self.assertTrue( 148 'Manage application section' in self.browser.contents) 149 self.manage_root_path = self.root_path + '/@@manage' 150 self.manage_container_path = self.container_path + '/@@manage' 154 self.assertTrue('Manage application section' in self.browser.contents) 155 # There is a manage link 156 link = self.browser.getLink('Manage application section') 157 link.click() 158 self.assertEqual(self.browser.headers['Status'], '200 Ok') 159 self.assertEqual(self.browser.url, self.manage_root_path) 160 161 def test_manage_actions_access(self): 162 # Managers can access the action on manage screen 163 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 151 164 self.browser.open(self.manage_root_path) 152 self.assertEqual(self.browser.headers['Status'], '200 Ok')153 self.assertEqual(self.browser.url, self.manage_root_path)154 165 self.browser.getControl("Add local role").click() 155 self.assertTrue( 156 'No user selected' in self.browser.contents) 157 self.browser.open(self.manage_container_path) 158 self.assertEqual(self.browser.headers['Status'], '200 Ok') 159 self.assertEqual(self.browser.url, self.manage_container_path) 160 self.browser.getControl("Save").click() 161 self.assertTrue( 162 'Data saved' in self.browser.contents) 163 self.browser.getControl("Remove selected", index=0).click() 164 self.assertTrue( 165 'No applicant selected' in self.browser.contents) 166 self.browser.getControl("Add local role").click() 167 self.assertTrue( 168 'No user selected' in self.browser.contents) 169 self.browser.getControl("Cancel", index=0).click() 170 self.assertEqual(self.browser.url, self.container_path) 171 # Managers can can assign local roles 166 self.assertTrue('No user selected' in self.browser.contents) 167 return 168 169 def test_local_roles_add_delete(self): 170 # Managers can assign and delete local roles of applicants root 172 171 myusers = self.app['users'] 173 172 myusers.addUser('bob', 'bobssecret') 173 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 174 174 self.browser.open(self.manage_root_path) 175 175 self.browser.getControl(name="user").value = ['bob'] 176 self.browser.getControl(name="local_role").value = ['waeup.ApplicationsOfficer'] 176 self.browser.getControl(name="local_role").value = [ 177 'waeup.ApplicationsOfficer'] 177 178 self.browser.getControl("Add local role").click() 178 self.assertTrue( 179 '<td>bob</td>' in self.browser.contents)179 self.assertTrue('<td>bob</td>' in self.browser.contents) 180 # Remove the role assigned 180 181 ctrl = self.browser.getControl(name='role_id') 181 182 ctrl.getControl(value='bob|waeup.ApplicationsOfficer').selected = True 182 183 self.browser.getControl("Remove selected local roles").click() 183 184 self.assertTrue('Successfully removed:' in self.browser.contents) 184 self.assertFalse( 185 '<td>bob</td>' in self.browser.contents) 186 self.browser.open(self.manage_container_path) 187 self.browser.getControl(name="user").value = ['bob'] 188 self.browser.getControl(name="local_role").value = ['waeup.ApplicationsOfficer'] 189 self.browser.getControl("Add local role").click() 190 self.assertTrue( 191 '<td>bob</td>' in self.browser.contents) 192 ctrl = self.browser.getControl(name='role_id') 193 ctrl.getControl(value='bob|waeup.ApplicationsOfficer').selected = True 194 self.browser.getControl("Remove selected local roles").click() 195 self.assertTrue('Successfully removed:' in self.browser.contents) 196 self.assertFalse( 197 '<td>bob</td>' in self.browser.contents) 185 self.assertFalse('<td>bob</td>' in self.browser.contents) 198 186 return 199 187 200 188 def test_add_delete_container(self): 201 189 # Managers can add and delete applicants containers 202 self.manage_root_path = self.root_path + '/@@manage'203 self.add_container_path = self.root_path + '/@@add'204 190 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 205 191 self.browser.open(self.manage_root_path) … … 402 388 return 403 389 390 class ApplicantsContainerUITests(ApplicantsFullSetup): 391 # Tests for ApplicantsContainer class views and pages 392 393 layer = FunctionalLayer 394 395 def test_anonymous_access(self): 396 # Anonymous users can access applicants containers 397 self.browser.open(self.container_path) 398 self.assertEqual(self.browser.headers['Status'], '200 Ok') 399 self.assertFalse( 400 'Manage' in self.browser.contents) 401 return 402 403 def test_manage_access(self): 404 # Managers can access the manage pages of applicants 405 # containers and can perform actions 406 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 407 self.browser.open(self.manage_container_path) 408 self.assertEqual(self.browser.headers['Status'], '200 Ok') 409 self.assertEqual(self.browser.url, self.manage_container_path) 410 self.browser.getControl("Save").click() 411 self.assertTrue('Data saved' in self.browser.contents) 412 self.browser.getControl("Remove selected", index=0).click() 413 self.assertTrue('No applicant selected' in self.browser.contents) 414 self.browser.getControl("Add local role").click() 415 self.assertTrue('No user selected' in self.browser.contents) 416 self.browser.getControl("Cancel", index=0).click() 417 self.assertEqual(self.browser.url, self.container_path) 418 return 419 420 def test_local_roles_add_delete(self): 421 # Managers can assign and delete local roles of applicants containers 422 myusers = self.app['users'] 423 myusers.addUser('bob', 'bobssecret') 424 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 425 self.browser.open(self.manage_container_path) 426 self.browser.getControl(name="user").value = ['bob'] 427 self.browser.getControl(name="local_role").value = [ 428 'waeup.ApplicationsOfficer'] 429 self.browser.getControl("Add local role").click() 430 self.assertTrue('<td>bob</td>' in self.browser.contents) 431 ctrl = self.browser.getControl(name='role_id') 432 ctrl.getControl(value='bob|waeup.ApplicationsOfficer').selected = True 433 self.browser.getControl("Remove selected local roles").click() 434 self.assertTrue('Successfully removed:' in self.browser.contents) 435 self.assertFalse('<td>bob</td>' in self.browser.contents) 436 return 437 404 438 class LoginTest(FunctionalTestCase): 405 439 # Here we check login view of applicants containers.
Note: See TracChangeset for help on using the changeset viewer.