Skip to content

Commit

Permalink
Merge pull request #114 from ScrumLATAMComunidad/issue_33
Browse files Browse the repository at this point in the history
Added more improvements about rolemap unit testing #33
  • Loading branch information
macagua committed Aug 15, 2023
2 parents f002f7c + 6cf3013 commit 818ef92
Showing 1 changed file with 115 additions and 1 deletion.
116 changes: 115 additions & 1 deletion backend/src/slc_web/src/slc_web/tests/test_ct_community_sponsor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 = [
Expand All @@ -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',
# ))

0 comments on commit 818ef92

Please sign in to comment.