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

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

pyflakes

  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1## $Id: test_dynamicroles.py 7257 2011-12-03 05:56:47Z 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.sirp.testing import FunctionalLayer
27from waeup.sirp.students.tests.test_browser import StudentsFullSetup
28from waeup.sirp.students import Student, StudentPrincipalRoleManager
29
30class StudentPrincipalRoleManagerTests(APRMTest):
31    # Make sure our PRM behaves like a regular one for usual cases.
32    # Usual cases are ones, that do not interact with external officers.
33    # See next test case for functional tests including officer perms.
34
35    def _make_roleManager(self, obj=None):
36        # Overriding this method of original testcase we make sure
37        # that really a Student PRM is tested.
38        if obj is None:
39            #obj = Manageable()
40            obj = Student()
41            obj['studycourse'] = Manageable()
42        return StudentPrincipalRoleManager(obj)
43
44class StudentPrincipalRoleManagerFunctionalTests(StudentsFullSetup):
45
46    layer = FunctionalLayer
47
48    def setUp(self):
49        super(StudentPrincipalRoleManagerFunctionalTests, self).setUp()
50        self.officer_role = 'waeup.StudentsClearanceOfficer'
51        # assign clearance permissions for a virtual officer
52        prm = IPrincipalRoleManager(self.app['faculties']['fac1']['dep1'])
53        prm.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'alice')
54        return
55
56    def test_iface(self):
57        # make sure our StudentPRM really implements required ifaces.
58        obj = StudentPrincipalRoleManager(self.student)
59        verify.verifyClass(IPrincipalRoleManager,
60                           StudentPrincipalRoleManager)
61        verify.verifyObject(IPrincipalRoleManager, obj)
62        return
63
64    def test_get_as_adapter(self):
65        # we can get an StudentPRM for Students by adapter lookup
66        prm = IPrincipalRoleManager(self.student)
67        self.assertTrue(
68            isinstance(prm, StudentPrincipalRoleManager))
69        return
70
71    def test_no_officer_set(self):
72        # if the faculty/dept. of the connected cert has no local
73        # roles set, we won't get any additional roles for our
74        # student
75        prm = IPrincipalRoleManager(self.student)
76        result = prm.getRolesForPrincipal('bob')
77        self.assertEqual(result, [])
78        return
79
80    def test_valid_officer(self):
81        # for an officer that has clearance role on the connected dept
82        # we get the ApplicationsOfficer role on our student
83        prm = IPrincipalRoleManager(self.student)
84        result = prm.getRolesForPrincipal('alice')
85        self.assertEqual(result, [(self.officer_role, Allow)])
86        return
Note: See TracBrowser for help on using the repository browser.