Exemplo n.º 1
0
    def test_is_allowed_perms_1_layer_multi_param_str(self, role_model_instances):
        d1, s1, c1 = role_model_instances()

        role = Role.create(d1)
        role.permissions.add('modify-district', 'create-school')

        input_str = f'District-{d1.id}/perms=[modify-district]'
        assert role.is_allowed(role=Role.from_str(input_str)) is False

        input_str = f'District-{d1.id}/perms=[create-school, modify-district]'
        assert role.is_allowed(role=Role.from_str(input_str)) is True

        input_str = f'District-{d1.id}/perms=[]'
        assert role.is_allowed(role=Role.from_str(input_str)) is False
Exemplo n.º 2
0
    def test_role_from_str(self, role_model_instances):
        d1, s1, c1 = role_model_instances()

        # The possible perms for School Admins are 'create-club', 'modify-school', 'hide-school'
        role_expected = Role.create(d1, s1)

        role_expected.permissions.add('modify-school', 'hide-school')

        perm_str = f'District-{d1.id}/School-{s1.id}/perms=[modify-school, hide-school]'
        role_test = Role.from_str(perm_str)

        assert str(role_expected) == str(role_test)
        perm_str = f'District-{d1.id}/School-{s1.id}/perms=[]'
        role_test = Role.from_str(perm_str)
        assert role_test.permissions.permissions == set()
Exemplo n.º 3
0
    def test_allowed_higher_level(self, role_model_instances):
        d1, s1, c1 = role_model_instances()

        role = Role.create(d1)
        input_str = f'District-{d1.id}/School-{s1.id}/perms=[create-club, modify-school]'

        assert Role.from_str(input_str).is_allowed(role=role) == True
Exemplo n.º 4
0
    def test_is_allowed_perms_3_layer_str(self, create_club, role_model_instances):
        d1, s1, c1 = role_model_instances()

        role = Role.create(d1)
        role.permissions.add('modify-district', 'create-school')

        # Check that School-2 is a part of District-1, and Club-52 is a part of School-2
        input_str = f'District-{d1.id}/School-{s1.id}/Club-{c1.id}/perms=[modify-club]'
        assert Role.from_str(input_str).is_allowed(role=role) == True

        d2, s2, c2 = role_model_instances()

        # Check that School-5 is not a part of District-1 and Club-1 not part of School-5, raises exception
        input_str = f'District-{d1.id}/School-{s2.id}/Club-{c2.id}/perms=[update-club]'
        with pytest.raises(InvalidRoleCreated):
            assert role.is_allowed(role=Role.from_str(input_str))
Exemplo n.º 5
0
    def test_not_allowed(self, create_club, role_model_instances):
        d1, s1, c1 = role_model_instances()
        d2, s2, c2 = role_model_instances()

        role = Role.create(d1, s1, c1)
        role.permissions.add('modify-club')

        input_str = f'District-{d2.id}/School-{s2.id}/Club-{c2.id}/perms=[add-admin]'
        assert role.is_allowed(role=Role.from_str(input_str)) == False
Exemplo n.º 6
0
    def test_role_from_str_given_perms(self, role_model_instances):
        d1, s1, c1 = role_model_instances()

        # The possible perms for School Admins are 'create-club', 'modify-school', 'hide-school'
        role_expected = Role.create(d1, s1)

        role_expected.permissions.add('modify-school', 'hide-school')

        given_str = f'District-{d1.id}/School-{s1.id}'
        role_test = Role.from_str(
            given_str, perms=['modify-school', 'hide-school'])

        assert str(role_expected) == str(role_test)