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

Last change on this file since 17367 was 17313, checked in by Henrik Bettermann, 22 months ago

Allow beds to be blocked so that no student can be allocated to such a bed space (in contrast to reserved beds)

  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1## $Id: test_dynamicroles.py 17313 2023-01-25 08:52:51Z 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.student import Student
30from waeup.kofa.students.dynamicroles import StudentPrincipalRoleManager
31
32class StudentPrincipalRoleManagerTests(APRMTest):
33    # Make sure our PRM behaves like a regular one for usual cases.
34    # Usual cases are ones, that do not interact with external officers.
35    # See next test case for functional tests including officer perms.
36
37    def _make_roleManager(self, obj=None):
38        # Overriding this method of original testcase we make sure
39        # that really a Student PRM is tested.
40        if obj is None:
41            #obj = Manageable()
42            obj = Student()
43            obj['studycourse'] = Manageable()
44        return StudentPrincipalRoleManager(obj)
45
46class StudentPrincipalRoleManagerFunctionalTests(StudentsFullSetup):
47
48    layer = FunctionalLayer
49
50    def setUp(self):
51        super(StudentPrincipalRoleManagerFunctionalTests, self).setUp()
52        # assign permissions for a virtual officers
53        prm = IPrincipalRoleManager(self.app['faculties']['fac1']['dep1'])
54        prm.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'alice')
55        prm.assignRoleToPrincipal('waeup.local.PGClearanceOfficer', 'bob')
56        prm.assignRoleToPrincipal('waeup.local.UGClearanceOfficer', 'anne')
57        prm.assignRoleToPrincipal('waeup.local.LocalStudentsManager', 'benita')
58        prm.assignRoleToPrincipal('waeup.local.LocalWorkflowManager', 'benita')
59        return
60
61    def test_iface(self):
62        # make sure our StudentPRM really implements required ifaces.
63        obj = StudentPrincipalRoleManager(self.student)
64        verify.verifyClass(IPrincipalRoleManager,
65                           StudentPrincipalRoleManager)
66        verify.verifyObject(IPrincipalRoleManager, obj)
67        return
68
69    def test_get_as_adapter(self):
70        # we can get an StudentPRM for Students by adapter lookup
71        prm = IPrincipalRoleManager(self.student)
72        self.assertTrue(
73            isinstance(prm, StudentPrincipalRoleManager))
74        return
75
76    def test_no_officer_set(self):
77        # if the faculty/dept. of the connected cert has no local
78        # roles set, we won't get any additional roles for our
79        # student
80        prm = IPrincipalRoleManager(self.student)
81        result = prm.getRolesForPrincipal('claus')
82        self.assertEqual(result, [])
83        return
84
85    def test_valid_officer(self):
86        # for an officer that has clearance role on the connected dept
87        # we get the ClearanceOfficer role on our student
88        prm = IPrincipalRoleManager(self.student)
89        result = prm.getRolesForPrincipal('alice')
90        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
91        # Student is a UG student
92        self.assertFalse(self.student.is_postgrad)
93        result = prm.getRolesForPrincipal('bob')
94        self.assertEqual(result, [('waeup.StudentsOfficer', Allow)])
95        result = prm.getRolesForPrincipal('anne')
96        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
97        # Make student a PG student
98        self.certificate.study_mode = u'pg_ft'
99        self.assertTrue(self.student.is_postgrad)
100        result = prm.getRolesForPrincipal('bob')
101        # The dynamic roles changed
102        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
103        result = prm.getRolesForPrincipal('anne')
104        self.assertEqual(result, [('waeup.StudentsOfficer', Allow)])
105        # Multiple roles can be assigned
106        result = prm.getRolesForPrincipal('benita')
107        self.assertEqual(result, [
108            ('waeup.WorkflowManager', Allow),
109            ('waeup.StudentsManager', Allow)
110            ])
111        return
Note: See TracBrowser for help on using the repository browser.