source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_dynamicroles.py @ 7872

Last change on this file since 7872 was 7811, checked in by uli, 13 years ago

Rename all non-locales stuff from sirp to kofa.

  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1## $Id: test_dynamicroles.py 7811 2012-03-08 19:00:51Z uli $
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 applicants 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.applicants.tests.test_browser import ApplicantsFullSetup
28from waeup.kofa.applicants import ApplicantPrincipalRoleManager
29
30class 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
42class ApplicantPrincipalRoleManagerFunctionalTests(ApplicantsFullSetup):
43
44    layer = FunctionalLayer
45
46    def setUp(self):
47        super(ApplicantPrincipalRoleManagerFunctionalTests, self).setUp()
48        self.applicant.course1 = self.certificate
49        self.officer_role = 'waeup.ApplicationsOfficer'
50        # assign clearance permissions for a virtual officer
51        prm = IPrincipalRoleManager(self.department)
52        prm.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'alice')
53        return
54
55    def test_iface(self):
56        # make sure out ApplicantPRM really implements required ifaces.
57        obj = ApplicantPrincipalRoleManager(self.applicant)
58        verify.verifyClass(IPrincipalRoleManager,
59                           ApplicantPrincipalRoleManager)
60        verify.verifyObject(IPrincipalRoleManager, obj)
61        return
62
63    def test_get_as_adapter(self):
64        # we can get an ApplicantPRM for Applicants by adapter lookup
65        prm = IPrincipalRoleManager(self.applicant)
66        self.assertTrue(
67            isinstance(prm, ApplicantPrincipalRoleManager))
68        return
69
70    def test_no_officer_set(self):
71        # if the faculty/dept. of the connected cert has no local
72        # roles set, we won't get any additional roles for our
73        # applicant
74        prm = IPrincipalRoleManager(self.applicant)
75        result = prm.getRolesForPrincipal('bob')
76        self.assertEqual(result, [])
77        return
78
79    def test_valid_officer(self):
80        # for an officer that has clearance role on the connected dept
81        # we get the ApplicationsOfficer role on our applicant
82        prm = IPrincipalRoleManager(self.applicant)
83        result = prm.getRolesForPrincipal('alice')
84        self.assertEqual(result, [('waeup.ApplicationsOfficer', Allow)])
85        return
Note: See TracBrowser for help on using the repository browser.