1 | ## $Id: test_dynamicroles.py 10226 2013-05-24 17:54:10Z 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 |
---|
24 | from zope.securitypolicy.tests.test_annotationprincipalrolemanager import ( |
---|
25 | Test as APRMTest, Manageable) |
---|
26 | from waeup.kofa.testing import FunctionalLayer |
---|
27 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
28 | from waeup.kofa.applicants import ApplicantPrincipalRoleManager |
---|
29 | |
---|
30 | class ApplicantPrincipalRoleManagerTests(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 an Applicant PRM is tested. |
---|
38 | if obj is None: |
---|
39 | obj = Manageable() |
---|
40 | return ApplicantPrincipalRoleManager(obj) |
---|
41 | |
---|
42 | class ApplicantPrincipalRoleManagerFunctionalTests(ApplicantsFullSetup): |
---|
43 | |
---|
44 | layer = FunctionalLayer |
---|
45 | |
---|
46 | def setUp(self): |
---|
47 | super(ApplicantPrincipalRoleManagerFunctionalTests, self).setUp() |
---|
48 | self.applicant.course1 = self.certificate |
---|
49 | # assign application manage permissions for a virtual officer |
---|
50 | prm = IPrincipalRoleManager(self.department) |
---|
51 | prm.assignRoleToPrincipal('waeup.local.ApplicationsManager', 'alice') |
---|
52 | return |
---|
53 | |
---|
54 | def test_iface(self): |
---|
55 | # make sure out ApplicantPRM really implements required ifaces. |
---|
56 | obj = ApplicantPrincipalRoleManager(self.applicant) |
---|
57 | verify.verifyClass(IPrincipalRoleManager, |
---|
58 | ApplicantPrincipalRoleManager) |
---|
59 | verify.verifyObject(IPrincipalRoleManager, obj) |
---|
60 | return |
---|
61 | |
---|
62 | def test_get_as_adapter(self): |
---|
63 | # we can get an ApplicantPRM for Applicants by adapter lookup |
---|
64 | prm = IPrincipalRoleManager(self.applicant) |
---|
65 | self.assertTrue( |
---|
66 | isinstance(prm, ApplicantPrincipalRoleManager)) |
---|
67 | return |
---|
68 | |
---|
69 | def test_no_officer_set(self): |
---|
70 | # if the faculty/dept. of the connected cert has no local |
---|
71 | # roles set, we won't get any additional roles for our |
---|
72 | # applicant |
---|
73 | prm = IPrincipalRoleManager(self.applicant) |
---|
74 | result = prm.getRolesForPrincipal('bob') |
---|
75 | self.assertEqual(result, []) |
---|
76 | return |
---|
77 | |
---|
78 | def test_valid_officer(self): |
---|
79 | # for an officer that has application manage permissions |
---|
80 | # on the connected dept |
---|
81 | # we get the ApplicationsManager role on our applicant |
---|
82 | prm = IPrincipalRoleManager(self.applicant) |
---|
83 | result = prm.getRolesForPrincipal('alice') |
---|
84 | self.assertEqual(result, [('waeup.ApplicationsManager', Allow)]) |
---|
85 | return |
---|