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

Last change on this file since 9282 was 8963, checked in by Henrik Bettermann, 12 years ago

Check for new local roles and assign StudentsClearanceOfficer? role accordingly.

  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1## $Id: test_dynamicroles.py 8963 2012-07-10 05:39:02Z 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 clearance permissions for a virtual officer
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        return
57
58    def test_iface(self):
59        # make sure our StudentPRM really implements required ifaces.
60        obj = StudentPrincipalRoleManager(self.student)
61        verify.verifyClass(IPrincipalRoleManager,
62                           StudentPrincipalRoleManager)
63        verify.verifyObject(IPrincipalRoleManager, obj)
64        return
65
66    def test_get_as_adapter(self):
67        # we can get an StudentPRM for Students by adapter lookup
68        prm = IPrincipalRoleManager(self.student)
69        self.assertTrue(
70            isinstance(prm, StudentPrincipalRoleManager))
71        return
72
73    def test_no_officer_set(self):
74        # if the faculty/dept. of the connected cert has no local
75        # roles set, we won't get any additional roles for our
76        # student
77        prm = IPrincipalRoleManager(self.student)
78        result = prm.getRolesForPrincipal('claus')
79        self.assertEqual(result, [])
80        return
81
82    def test_valid_officer(self):
83        # for an officer that has clearance role on the connected dept
84        # we get the ApplicationsOfficer role on our student
85        prm = IPrincipalRoleManager(self.student)
86        result = prm.getRolesForPrincipal('alice')
87        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
88        # Student is a UG student
89        self.assertFalse(self.student.is_postgrad)
90        result = prm.getRolesForPrincipal('bob')
91        self.assertEqual(result, [('waeup.StudentsOfficer', Allow)])
92        result = prm.getRolesForPrincipal('anne')
93        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
94        # Make student a PG student
95        self.certificate.study_mode = u'pg_ft'
96        self.assertTrue(self.student.is_postgrad)
97        result = prm.getRolesForPrincipal('bob')
98        # The dynamic roles changed
99        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
100        result = prm.getRolesForPrincipal('anne')
101        self.assertEqual(result, [('waeup.StudentsOfficer', Allow)])
102        return
Note: See TracBrowser for help on using the repository browser.