source: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_dynamicroles.py @ 16593

Last change on this file since 16593 was 10639, checked in by Henrik Bettermann, 11 years ago

Define new local roles (see uniben ticket 900).

Allow the dynamical assignment of multiple local roles.

  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1## $Id: test_dynamicroles.py 10639 2013-09-22 08:54:03Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Tests for dynamic roles concerning students and related.
20"""
21from zope.interface import verify
22from zope.securitypolicy.interfaces import IPrincipalRoleManager
23from zope.securitypolicy.settings import Allow
24from zope.securitypolicy.tests.test_annotationprincipalrolemanager import (
25    Test as APRMTest, Manageable)
26from waeup.kofa.testing import FunctionalLayer
27from waeup.kofa.app import University
28from waeup.kofa.students.tests.test_browser import StudentsFullSetup
29from waeup.kofa.students import Student, StudentPrincipalRoleManager
30
31class StudentPrincipalRoleManagerTests(APRMTest):
32    # Make sure our PRM behaves like a regular one for usual cases.
33    # Usual cases are ones, that do not interact with external officers.
34    # See next test case for functional tests including officer perms.
35
36    def _make_roleManager(self, obj=None):
37        # Overriding this method of original testcase we make sure
38        # that really a Student PRM is tested.
39        if obj is None:
40            #obj = Manageable()
41            obj = Student()
42            obj['studycourse'] = Manageable()
43        return StudentPrincipalRoleManager(obj)
44
45class StudentPrincipalRoleManagerFunctionalTests(StudentsFullSetup):
46
47    layer = FunctionalLayer
48
49    def setUp(self):
50        super(StudentPrincipalRoleManagerFunctionalTests, self).setUp()
51        # assign permissions for a virtual officers
52        prm = IPrincipalRoleManager(self.app['faculties']['fac1']['dep1'])
53        prm.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'alice')
54        prm.assignRoleToPrincipal('waeup.local.PGClearanceOfficer', 'bob')
55        prm.assignRoleToPrincipal('waeup.local.UGClearanceOfficer', 'anne')
56        prm.assignRoleToPrincipal('waeup.local.LocalStudentsManager', 'benita')
57        prm.assignRoleToPrincipal('waeup.local.LocalWorkflowManager', 'benita')
58        return
59
60    def test_iface(self):
61        # make sure our StudentPRM really implements required ifaces.
62        obj = StudentPrincipalRoleManager(self.student)
63        verify.verifyClass(IPrincipalRoleManager,
64                           StudentPrincipalRoleManager)
65        verify.verifyObject(IPrincipalRoleManager, obj)
66        return
67
68    def test_get_as_adapter(self):
69        # we can get an StudentPRM for Students by adapter lookup
70        prm = IPrincipalRoleManager(self.student)
71        self.assertTrue(
72            isinstance(prm, StudentPrincipalRoleManager))
73        return
74
75    def test_no_officer_set(self):
76        # if the faculty/dept. of the connected cert has no local
77        # roles set, we won't get any additional roles for our
78        # student
79        prm = IPrincipalRoleManager(self.student)
80        result = prm.getRolesForPrincipal('claus')
81        self.assertEqual(result, [])
82        return
83
84    def test_valid_officer(self):
85        # for an officer that has clearance role on the connected dept
86        # we get the ClearanceOfficer role on our student
87        prm = IPrincipalRoleManager(self.student)
88        result = prm.getRolesForPrincipal('alice')
89        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
90        # Student is a UG student
91        self.assertFalse(self.student.is_postgrad)
92        result = prm.getRolesForPrincipal('bob')
93        self.assertEqual(result, [('waeup.StudentsOfficer', Allow)])
94        result = prm.getRolesForPrincipal('anne')
95        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
96        # Make student a PG student
97        self.certificate.study_mode = u'pg_ft'
98        self.assertTrue(self.student.is_postgrad)
99        result = prm.getRolesForPrincipal('bob')
100        # The dynamic roles changed
101        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
102        result = prm.getRolesForPrincipal('anne')
103        self.assertEqual(result, [('waeup.StudentsOfficer', Allow)])
104        # Multiple roles can be assigned
105        result = prm.getRolesForPrincipal('benita')
106        self.assertEqual(result, [
107            ('waeup.WorkflowManager', Allow),
108            ('waeup.StudentsManager', Allow)
109            ])
110        return
Note: See TracBrowser for help on using the repository browser.