Changeset 6603


Ignore:
Timestamp:
13 Aug 2011, 02:53:35 (13 years ago)
Author:
uli
Message:

Start splitting (code-wise) long tests into shorter pieces. I guess
that makes them better to copy, maintain, and understand in the long
run.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_browser.py

    r6600 r6603  
    2727from StringIO import StringIO
    2828from datetime import datetime
     29from mechanize import LinkNotFoundError
    2930from zope.component import createObject
    3031from zope.component.hooks import setSite, clearSite
     32from zope.security.interfaces import Unauthorized
    3133from zope.testbrowser.testing import Browser
    3234from hurry.workflow.interfaces import IWorkflowInfo
     
    7072
    7173        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'
    7276        self.container_path = 'http://localhost/app/applicants/app2009'
     77        self.manage_container_path = self.container_path + '/@@manage'
    7378
    7479        # Add an applicants container
     
    114119        clearSite()
    115120        shutil.rmtree(self.dc_root)
    116         #import pdb; pdb.set_trace()
    117 
    118 class ApplicantsUITests(ApplicantsFullSetup):
     121
     122class ApplicantsRootUITests(ApplicantsFullSetup):
    119123    # Tests for ApplicantsRoot class
    120124
     
    122126
    123127    def test_anonymous_access(self):
    124         # Anonymous users can access applicants root and applicants containers
     128        # Anonymous users can access applicants root
    125129        self.browser.open(self.root_path)
    126130        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    127131        self.assertFalse(
    128132            '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
    141149
    142150    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
    145152        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    146153        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')
    151164        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)
    154165        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
    172171        myusers = self.app['users']
    173172        myusers.addUser('bob', 'bobssecret')
     173        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    174174        self.browser.open(self.manage_root_path)
    175175        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']
    177178        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
    180181        ctrl = self.browser.getControl(name='role_id')
    181182        ctrl.getControl(value='bob|waeup.ApplicationsOfficer').selected = True
    182183        self.browser.getControl("Remove selected local roles").click()
    183184        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)
    198186        return
    199187
    200188    def test_add_delete_container(self):
    201189        # 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'
    204190        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    205191        self.browser.open(self.manage_root_path)
     
    402388        return
    403389
     390class 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
    404438class LoginTest(FunctionalTestCase):
    405439    # Here we check login view of applicants containers.
Note: See TracChangeset for help on using the changeset viewer.