<commit_before>"""
:Copyright: 2006-2019 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from byceps.services.authorization import service

from tests.base import AbstractAppTestCase


class PermissionToRoleAssignmentTestCase(AbstractAppTestCase):

    def setUp(self):
        super().setUp()

        self.permission_id = 'board_topic_hide'
        self.permission = service.create_permission(self.permission_id,
                                                    self.permission_id)

        self.role_id = 'board_moderator'
        self.role = service.create_role(self.role_id, self.role_id)

    def test_assign_permission_to_role(self):
        permission_id = self.permission.id
        role_id = self.role.id

        role_permission_ids_before = self.get_permission_ids_for_role(role_id)
        assert self.permission_id not in role_permission_ids_before

        service.assign_permission_to_role(permission_id, role_id)

        role_permission_ids_after = self.get_permission_ids_for_role(role_id)
        assert self.permission_id in role_permission_ids_after

    def test_deassign_permission_from_role(self):
        permission_id = self.permission.id
        role_id = self.role.id

        service.assign_permission_to_role(permission_id, role_id)

        role_permission_ids_before = self.get_permission_ids_for_role(role_id)
        assert self.permission_id in role_permission_ids_before

        service.deassign_permission_from_role(permission_id, role_id)

        role_permission_ids_after = self.get_permission_ids_for_role(role_id)
        assert self.permission_id not in role_permission_ids_after

    # -------------------------------------------------------------------- #
    # helpers

    def get_permission_ids_for_role(self, role_id):
        return {p.id for p in self.role.permissions}<commit_msg>Turn test helper method into function, remove unused argument<commit_after>"""
:Copyright: 2006-2019 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from byceps.services.authorization import service

from tests.base import AbstractAppTestCase


class PermissionToRoleAssignmentTestCase(AbstractAppTestCase):

    def setUp(self):
        super().setUp()

        self.permission_id = 'board_topic_hide'
        self.permission = service.create_permission(self.permission_id,
                                                    self.permission_id)

        self.role_id = 'board_moderator'
        self.role = service.create_role(self.role_id, self.role_id)

    def test_assign_permission_to_role(self):
        permission_id = self.permission.id
        role_id = self.role.id

        role_permission_ids_before = get_permission_ids_for_role(self.role)
        assert self.permission_id not in role_permission_ids_before

        service.assign_permission_to_role(permission_id, role_id)

        role_permission_ids_after = get_permission_ids_for_role(self.role)
        assert self.permission_id in role_permission_ids_after

    def test_deassign_permission_from_role(self):
        permission_id = self.permission.id
        role_id = self.role.id

        service.assign_permission_to_role(permission_id, role_id)

        role_permission_ids_before = get_permission_ids_for_role(self.role)
        assert self.permission_id in role_permission_ids_before

        service.deassign_permission_from_role(permission_id, role_id)

        role_permission_ids_after = get_permission_ids_for_role(self.role)
        assert self.permission_id not in role_permission_ids_after


def get_permission_ids_for_role(role):
    return {p.id for p in role.permissions}
{'fraction_non_alphanumeric': 0.08280430582390284, 'fraction_numerical': 0.004416229643941485, 'mean_word_length': 3.2041763341067284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7059786', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1016, 'n_words': 181}