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 | """ |
---|
19 | Tests for dynamic roles concerning applicants and related. |
---|
20 | """ |
---|
21 | from zope.interface import verify |
---|
22 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
---|
23 | from zope.securitypolicy.settings import Allow, Deny, Unset |
---|
24 | from zope.securitypolicy.tests.test_securitymap import TestSecurityMap |
---|
25 | from zope.securitypolicy.tests.test_annotationprincipalrolemanager import ( |
---|
26 | Test as APRMTest, Manageable) |
---|
27 | from waeup.sirp.testing import FunctionalLayer |
---|
28 | from waeup.sirp.applicants.tests.test_browser import ApplicantsFullSetup |
---|
29 | from waeup.sirp.applicants import ApplicantPrincipalRoleManager |
---|
30 | |
---|
31 | class ApplicantPrincipalRoleManagerTests(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 an Applicant PRM is tested. |
---|
39 | if obj is None: |
---|
40 | obj = Manageable() |
---|
41 | return ApplicantPrincipalRoleManager(obj) |
---|
42 | |
---|
43 | class ApplicantPrincipalRoleManagerFunctionalTests(ApplicantsFullSetup): |
---|
44 | |
---|
45 | layer = FunctionalLayer |
---|
46 | |
---|
47 | def setUp(self): |
---|
48 | super(ApplicantPrincipalRoleManagerFunctionalTests, self).setUp() |
---|
49 | self.applicant.course1 = self.certificate |
---|
50 | self.officer_role = 'waeup.ApplicationsOfficer' |
---|
51 | # assign clearance permissions for a virtual officer |
---|
52 | prm = IPrincipalRoleManager(self.department) |
---|
53 | prm.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'alice') |
---|
54 | return |
---|
55 | |
---|
56 | def test_iface(self): |
---|
57 | # make sure out ApplicantPRM really implements required ifaces. |
---|
58 | obj = ApplicantPrincipalRoleManager(self.applicant) |
---|
59 | verify.verifyClass(IPrincipalRoleManager, |
---|
60 | ApplicantPrincipalRoleManager) |
---|
61 | verify.verifyObject(IPrincipalRoleManager, obj) |
---|
62 | return |
---|
63 | |
---|
64 | def test_get_as_adapter(self): |
---|
65 | # we can get an ApplicantPRM for Applicants by adapter lookup |
---|
66 | prm = IPrincipalRoleManager(self.applicant) |
---|
67 | self.assertTrue( |
---|
68 | isinstance(prm, ApplicantPrincipalRoleManager)) |
---|
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 | # applicant |
---|
75 | prm = IPrincipalRoleManager(self.applicant) |
---|
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 applicant |
---|
83 | prm = IPrincipalRoleManager(self.applicant) |
---|
84 | result = prm.getRolesForPrincipal('alice') |
---|
85 | self.assertEqual(result, [('waeup.ApplicationsOfficer', Allow)]) |
---|
86 | return |
---|