示例#1
0
    def test__unit__CandidateWorkspaceRoleChecker__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))
        candidate_workspace = Workspace(workspace_id=3)
        self.session.add(current_user)
        self.session.add(candidate_workspace)
        self.session.flush()
        transaction.commit()

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

            @property
            def candidate_workspace(self):
                return candidate_workspace

        assert CandidateWorkspaceRoleChecker(0).check(FakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            CandidateWorkspaceRoleChecker(1).check(FakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            CandidateWorkspaceRoleChecker(2).check(FakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            CandidateWorkspaceRoleChecker(3).check(FakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            CandidateWorkspaceRoleChecker(4).check(FakeTracimContext())
示例#2
0
    def test__unit__RoleChecker__err_role_insufficient(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=2)
        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(2).check(FakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            RoleChecker(3).check(FakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            RoleChecker(4).check(FakeTracimContext())
示例#3
0
    def test__unit__ContentTypeCreationChecker__err__implicit_insufficent_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)
        candidate_content_type = ContentType(
            slug="test",
            fa_icon="",
            hexcolor="",
            label="Test",
            creation_label="Test",
            available_statuses=[],
            minimal_role_content_creation=WorkspaceRoles.CONTENT_MANAGER,
        )
        role = UserRoleInWorkspace(user_id=2,
                                   workspace_id=3,
                                   role=WorkspaceRoles.CONTRIBUTOR.level)
        self.session.add(current_user)
        self.session.add(current_workspace)
        self.session.add(role)
        self.session.flush()
        transaction.commit()

        class FakeContentTypeList(object):
            def get_one_by_slug(self, slug=str) -> ContentType:
                return candidate_content_type

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

            @property
            def current_workspace(self):
                return current_workspace

            @property
            def candidate_content_type(self):
                return candidate_content_type

        with pytest.raises(InsufficientUserRoleInWorkspace):
            assert ContentTypeCreationChecker(FakeContentTypeList()).check(
                FakeTracimContext())
示例#4
0
    def test__unit__ContentTypeCreationChecker__ok__explicit(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)
        candidate_content_type = ContentType(
            slug='test',
            fa_icon='',
            hexcolor='',
            label='Test',
            creation_label='Test',
            available_statuses=[],
            minimal_role_content_creation=WorkspaceRoles.CONTENT_MANAGER)
        role = UserRoleInWorkspace(user_id=2,
                                   workspace_id=3,
                                   role=WorkspaceRoles.CONTENT_MANAGER.level)
        self.session.add(current_user)
        self.session.add(current_workspace)
        self.session.add(role)
        self.session.flush()
        transaction.commit()

        class FakeContentTypeList(object):
            def get_one_by_slug(self, slug=str) -> ContentType:
                return candidate_content_type

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

            @property
            def current_workspace(self):
                return current_workspace

        assert ContentTypeCreationChecker(FakeContentTypeList(),
                                          content_type_slug='test').check(
                                              FakeTracimContext())
示例#5
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())
示例#6
0
    def insert(self):
        u = User()
        u.display_name = 'Global manager'
        u.email = '*****@*****.**'
        u.password = '******'
        self._session.add(u)
        uapi = UserApi(session=self._session,
                       config=self._config,
                       current_user=u)
        uapi.execute_created_user_actions(u)

        g1 = Group()
        g1.group_id = 1
        g1.group_name = 'users'
        g1.display_name = 'Users'
        g1.users.append(u)
        self._session.add(g1)

        g2 = Group()
        g2.group_id = 2
        g2.group_name = 'trusted-users'
        g2.display_name = 'Trusted Users'
        g2.users.append(u)
        self._session.add(g2)

        g3 = Group()
        g3.group_id = 3
        g3.group_name = 'administrators'
        g3.display_name = 'Administrators'
        g3.users.append(u)
        self._session.add(g3)
示例#7
0
 class FakeTracimContext(TracimContext):
     candidate_user = User(user_id=2)
     candidate_user.groups.append(Group(group_id=2))
示例#8
0
 class FakeTracimContext(TracimContext):
     current_user = User(user_id=2)
     current_user.groups.append(Group(group_id=2))
示例#9
0
    def insert(self):
        u = User()
        u.display_name = "Global manager"
        u.email = "*****@*****.**"
        u.password = "******"
        self._session.add(u)

        g1 = Group()
        g1.group_id = 1
        g1.group_name = "users"
        g1.display_name = "Users"
        g1.users.append(u)
        self._session.add(g1)

        g2 = Group()
        g2.group_id = 2
        g2.group_name = "trusted-users"
        g2.display_name = "Trusted Users"
        g2.users.append(u)
        self._session.add(g2)

        g3 = Group()
        g3.group_id = 3
        g3.group_name = "administrators"
        g3.display_name = "Administrators"
        g3.users.append(u)
        self._session.add(g3)
示例#10
0
    def insert(self):
        u = User()
        u.display_name = 'Global manager'
        u.email = '*****@*****.**'
        u.password = '******'
        self._session.add(u)
        uapi = UserApi(
            session=self._session,
            config=self._config,
            current_user=u)
        uapi.execute_created_user_actions(u)

        g1 = Group()
        g1.group_id = 1
        g1.group_name = 'users'
        g1.display_name = 'Users'
        g1.users.append(u)
        self._session.add(g1)

        g2 = Group()
        g2.group_id = 2
        g2.group_name = 'trusted-users'
        g2.display_name = 'Trusted Users'
        g2.users.append(u)
        self._session.add(g2)

        g3 = Group()
        g3.group_id = 3
        g3.group_name = 'administrators'
        g3.display_name = 'Administrators'
        g3.users.append(u)
        self._session.add(g3)