Ejemplo n.º 1
0
    def test__unit__RoleChecker__err_no_role_in_workspace(self):

        current_user = User(user_id=2, email='*****@*****.**')
        current_user.groups.append(
            Group(group_id=2, group_name=Group.TIM_MANAGER_GROUPNAME))
        current_workspace = Workspace(workspace_id=3)
        self.session.add(current_user)
        self.session.add(current_workspace)
        self.session.flush()
        transaction.commit()

        class FakeTracimContext(TracimContext):
            @property
            def current_user(self):
                return current_user

            @property
            def current_workspace(self):
                return current_workspace

        assert RoleChecker(0).check(FakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            RoleChecker(1).check(FakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            RoleChecker(2).check(FakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            RoleChecker(3).check(FakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            RoleChecker(4).check(FakeTracimContext())
Ejemplo n.º 2
0
    def test__unit__RoleChecker__err_no_role_in_workspace(self, session):

        current_user = User(user_id=2, email="*****@*****.**")
        current_user.profile = Profile.TRUSTED_USER
        current_workspace = Workspace(workspace_id=3, owner=current_user)
        session.add(current_user)
        session.add(current_workspace)
        session.flush()
        transaction.commit()

        class FakeBaseFakeTracimContext(BaseFakeTracimContext):
            @property
            def current_user(self):
                return current_user

            @property
            def current_workspace(self):
                return current_workspace

        assert RoleChecker(0).check(FakeBaseFakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            RoleChecker(1).check(FakeBaseFakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            RoleChecker(2).check(FakeBaseFakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            RoleChecker(3).check(FakeBaseFakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            RoleChecker(4).check(FakeBaseFakeTracimContext())
Ejemplo n.º 3
0
    def test__unit__RoleChecker__ok__nominal_case(self, session):

        current_user = User(user_id=2, email="*****@*****.**")
        current_user.profile = Profile.TRUSTED_USER
        current_workspace = Workspace(workspace_id=3, owner=current_user)
        role = UserRoleInWorkspace(user_id=2, workspace_id=3, role=2)
        session.add(current_user)
        session.add(current_workspace)
        session.add(role)
        session.flush()
        transaction.commit()

        class FakeBaseFakeTracimContext(BaseFakeTracimContext):
            @property
            def current_user(self):
                return current_user

            @property
            def current_workspace(self):
                return current_workspace

        assert RoleChecker(1).check(FakeBaseFakeTracimContext())
        assert RoleChecker(2).check(FakeBaseFakeTracimContext())
Ejemplo n.º 4
0
    def test__unit__RoleChecker__ok__nominal_case(self):

        current_user = User(user_id=2, email='*****@*****.**')
        current_user.groups.append(
            Group(group_id=2, group_name=Group.TIM_MANAGER_GROUPNAME))
        current_workspace = Workspace(workspace_id=3)
        role = UserRoleInWorkspace(user_id=2, workspace_id=3, role=5)
        self.session.add(current_user)
        self.session.add(current_workspace)
        self.session.add(role)
        self.session.flush()
        transaction.commit()

        class FakeTracimContext(TracimContext):
            @property
            def current_user(self):
                return current_user

            @property
            def current_workspace(self):
                return current_workspace

        assert RoleChecker(1).check(FakeTracimContext())
        assert RoleChecker(2).check(FakeTracimContext())