source: main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_dynamicroles.py @ 7206

Last change on this file since 7206 was 7159, checked in by Henrik Bettermann, 13 years ago

Rename securitypolicy module to dynamicroles.

  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1## $Id: test_dynamicroles.py 7159 2011-11-21 10:11:07Z 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, Deny, Unset
24from zope.securitypolicy.tests.test_securitymap import TestSecurityMap
25from zope.securitypolicy.tests.test_annotationprincipalrolemanager import (
26    Test as APRMTest, Manageable)
27from waeup.sirp.testing import FunctionalLayer
28from waeup.sirp.students.tests.test_browser import StudentsFullSetup
29from waeup.sirp.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        self.officer_role = 'waeup.StudentsClearanceOfficer'
52        # assign clearance permissions for a virtual officer
53        prm = IPrincipalRoleManager(self.app['faculties']['fac1']['dep1'])
54        prm.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'alice')
55        return
56
57    def test_iface(self):
58        # make sure our StudentPRM really implements required ifaces.
59        obj = StudentPrincipalRoleManager(self.student)
60        verify.verifyClass(IPrincipalRoleManager,
61                           StudentPrincipalRoleManager)
62        verify.verifyObject(IPrincipalRoleManager, obj)
63        return
64
65    def test_get_as_adapter(self):
66        # we can get an StudentPRM for Students by adapter lookup
67        prm = IPrincipalRoleManager(self.student)
68        self.assertTrue(
69            isinstance(prm, StudentPrincipalRoleManager))
70        return
71
72    def test_no_officer_set(self):
73        # if the faculty/dept. of the connected cert has no local
74        # roles set, we won't get any additional roles for our
75        # student
76        prm = IPrincipalRoleManager(self.student)
77        result = prm.getRolesForPrincipal('bob')
78        self.assertEqual(result, [])
79        return
80
81    def test_valid_officer(self):
82        # for an officer that has clearance role on the connected dept
83        # we get the ApplicationsOfficer role on our student
84        prm = IPrincipalRoleManager(self.student)
85        result = prm.getRolesForPrincipal('alice')
86        self.assertEqual(result, [(self.officer_role, Allow)])
87        return
Note: See TracBrowser for help on using the repository browser.