From 6cf30133543e5f1d01d3633b0aca1e0102683f3a Mon Sep 17 00:00:00 2001 From: Manuel Matos Date: Wed, 26 Jul 2023 19:22:24 -0400 Subject: [PATCH] Added more improvements about rolemap unit testing #33 --- .../tests/test_ct_community_sponsor.py | 116 +++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/backend/src/slc_web/src/slc_web/tests/test_ct_community_sponsor.py b/backend/src/slc_web/src/slc_web/tests/test_ct_community_sponsor.py index fb8e2e5..fa02087 100644 --- a/backend/src/slc_web/src/slc_web/tests/test_ct_community_sponsor.py +++ b/backend/src/slc_web/src/slc_web/tests/test_ct_community_sponsor.py @@ -24,6 +24,22 @@ def setUp(self): self.portal = self.layer["portal"] setRoles(self.portal, TEST_USER_ID, ["Manager"]) + def _check_permission_for_role(self, permission, role): + """Check if the specified role has the specified permission. + The API of the permissionsOfRole() function sucks - it is bound too + closely up in the permission management screen's user interface. + + Args: + permission (str): permission string + role (str): role string + + Returns: + bool: True or False if permission in role + """ + return permission in [ + r["name"] for r in self.portal.permissionsOfRole(role) if r["selected"] + ] + def test_ct_community_sponsor_fti(self): """Test If CommunitySponsor exits on Dexterity FTI.""" fti = queryUtility(IDexterityFTI, name="CommunitySponsor") @@ -40,8 +56,9 @@ def test_ct_community_sponsor_globally_addable(self): "{0} is not globally addable!".format(fti.id), ) + # profiles/default/rolemap.xml file def test_ct_community_sponsor_roles(self): - """Test correct assigning of permissions from rolemap.xml file.""" + """Test correct assigning of permissions registered.""" # Test permission mapping for adding an Community Sponsor sponsor_roles = [ @@ -68,3 +85,100 @@ def test_ct_community_sponsor_roles(self): if r["selected"] ] self.assertEqual(sponsor_roles, MANAGE_SPONSOR_ROLES) + + # profiles/default/rolemap.xml file + def test_ct_community_sponsor_manage_disabled(self): + """Test that Community Sponsor is disabled.""" + self.assertFalse( + self._check_permission_for_role( + permission="Community Sponsor: Manage Sponsors", + role="Member", + ) + ) + + # profiles/default/rolemap.xml file + def test_ct_community_sponsor_manage_editable(self): + """Test that 'Manager' and 'Sponsorship Committee' + members can manage sponsors.""" + + self.assertTrue( + self._check_permission_for_role( + permission="Community Sponsor: Manage Sponsors", + role="Sponsorship Committee", + ) + ) + self.assertTrue( + self._check_permission_for_role( + permission="Community Sponsor: Manage Sponsors", + role="Manager", + ) + ) + + # profiles/default/rolemap.xml file + def test_ct_community_sponsor_add_disabled(self): + """Test that 'Member' role members does not add new sponsors.""" + self.assertFalse( + self._check_permission_for_role( + permission="Community Sponsor: Add Community Sponsor", + role="Member", + ) + ) + + # profiles/default/rolemap.xml file + def test_ct_community_sponsor_only_roles_can_add(self): + """Test that only 'Sponsorship Committee' and 'Manager' + members can add new sponsors.""" + self.assertTrue( + self._check_permission_for_role( + permission="Community Sponsor: Add Community Sponsor", + role="Sponsorship Committee", + ) + ) + self.assertTrue( + self._check_permission_for_role( + permission="Community Sponsor: Add Community Sponsor", + role="Manager", + ) + ) + # self.assertTrue(self._check_permission_for_role( + # permission='Community Sponsor: Add Community Sponsor', + # role='Site Administrator', + # )) + + # profiles/default/rolemap.xml file + def test_ct_community_sponsor_view_disabled(self): + """Test that 'Member' and 'Anonymous' role members + can sponsors view detail.""" + self.assertFalse( + self._check_permission_for_role( + permission="Community Sponsor: View Detail", + role="Member", + ) + ) + # self.assertFalse( + # self._check_permission_for_role( + # permission="Community Sponsor: View Detail", + # role="Anonymous", + # ) + # ) + + # profiles/default/rolemap.xml file + def test_ct_community_sponsor_view_only_roles_can_add(self): + """Test that only 'Sponsorship Committee' and'Manager' + members can sponsors view detail.""" + self.assertTrue( + self._check_permission_for_role( + permission="Community Sponsor: View Detail", + role="Sponsorship Committee", + ) + ) + self.assertTrue( + self._check_permission_for_role( + permission="Community Sponsor: View Detail", + role="Manager", + ) + ) + # self.assertTrue(self._check_permission_for_role( + # permission='Community Sponsor: View Detail', + # role='Site Administrator', + # ))