Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test share org to user group #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

INACTIVE_USER = '[email protected]'
INACTIVE_PASSWORD = 'inactiveuser'

ORG_PREFIX = 'seafile_org'
ORG_CREATOR = 'org_user'
20 changes: 18 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from tenacity import retry, stop_after_attempt, wait_fixed
from tests.config import (
ADMIN_PASSWORD, ADMIN_USER, INACTIVE_PASSWORD, INACTIVE_USER, PASSWORD,
PASSWORD2, USER, USER2
PASSWORD2, USER, USER2, ORG_PREFIX, ORG_CREATOR
)
from tests.utils import create_and_get_repo, randstring, create_and_get_group
from tests.utils import create_and_get_repo, randstring, create_and_get_group, create_and_get_org

from seaserv import ccnet_api, seafile_api

Expand Down Expand Up @@ -60,6 +60,22 @@ def group():
finally:
if ccnet_api.get_group(group.id):
ccnet_api.remove_group(group.id)
assert ccnet_api.get_group(group.id) is None

@pytest.yield_fixture(scope='function')
def org():
org = create_and_get_org(
'testorg测试-{}'.format(randstring(10)), ORG_PREFIX, ORG_CREATOR
)
try:
yield org
finally:
if ccnet_api.get_org_by_id(org.org_id):
ccnet_api.remove_org(org.org_id)







135 changes: 126 additions & 9 deletions tests/test_sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def test_share_repo_to_user(repo, permission):
api.share_repo(repo.id, USER, USER2, permission)
assert api.check_permission(repo.id, USER2) == permission

repos = api.get_share_in_repo_list(USER2, 0, 1)
assert_repo_with_permission(repo, repos, permission)
t_repos_list = 0
t_repos_list = api.get_share_in_repo_list(USER2, 0, 1)

assert_repo_with_permission(repo, t_repos_list, permission)

api.remove_share(repo.id, USER, USER2)
assert api.check_permission(repo.id, USER2) is None
Expand All @@ -26,31 +28,146 @@ def test_share_repo_to_group(repo, group, permission):
assert api.check_permission(repo.id, USER) == 'rw'
assert api.check_permission(repo.id, USER2) is None

repos = api.get_repos_by_group(group.id)
assert len(repos) == 0
t_repos = api.get_repos_by_group(group.id)
assert len(t_repos) == 0

group_list = ccnet_api.get_groups(USER)
assert len(group_list) == 1
group_list = ccnet_api.get_groups(USER2)
assert len(group_list) == 0

api.group_share_repo(repo.id, group.id, USER, permission)
repos = api.get_repos_by_group(group.id)
assert_repo_with_permission(repo, repos, permission)
t_repos = api.get_repos_by_group(group.id)
assert_repo_with_permission(repo, t_repos, permission)

group_list = ccnet_api.get_groups(USER2)
assert len(group_list) == 0

ccnet_api.group_add_member(group.id, USER, USER2)
group_list = ccnet_api.get_groups(USER2)
assert len(group_list) == 1
group = group_list[0]
assert group.id == group.id
t_group = group_list[0]
assert t_group.id == group.id

repos2 = api.get_repos_by_group(group.id)
assert_repo_with_permission(repo, repos2, permission)

assert api.check_permission(repo.id, USER2) == permission

api.group_unshare_repo(repo.id, group.id, USER);
api.group_unshare_repo(repo.id, group.id, USER)
repos = api.get_repos_by_group(group.id)
assert len(repos) == 0

assert api.check_permission(repo.id, USER2) is None

@pytest.mark.parametrize('permission', ['r', 'rw'])
def test_share_org_repo_to_user(repo, org, permission):
t_org_list = ccnet_api.get_all_orgs(0, 1)
assert len(t_org_list) == 1

t_orgs = t_org_list[0]
assert t_orgs.org_id == org.org_id

t_org_count = ccnet_api.count_orgs()
assert t_org_count == 1

t_user_orgs = ccnet_api.get_orgs_by_user(USER)
assert len(t_user_orgs) == 0

ccnet_api.add_org_user(org.org_id, USER, False)
t_user_orgs = ccnet_api.get_orgs_by_user(USER)
assert len(t_user_orgs) == 1
t_user_org = t_user_orgs[0]
assert t_user_org.org_id == org.org_id

assert api.check_permission(repo.id, USER) == 'rw'
assert api.check_permission(repo.id, USER2) is None

api.share_repo(repo.id, USER, USER2, permission)

t_user_orgs = ccnet_api.get_orgs_by_user(USER2)
assert len(t_user_orgs) == 0

assert api.check_permission(repo.id, USER2) == permission

api.remove_share(repo.id, USER, USER2)
assert api.check_permission(repo.id, USER2) is None

ccnet_api.add_org_user(org.org_id, USER2, False)
t_user_orgs = ccnet_api.get_orgs_by_user(USER2)
assert len(t_user_orgs) == 1
t_user_org = t_user_orgs[0]
assert t_user_org.org_id == org.org_id

assert api.check_permission(repo.id, USER2) is None
api.share_repo(repo.id, USER, USER2, permission)
assert api.check_permission(repo.id, USER2) == permission

api.remove_share(repo.id, USER, USER2)
assert api.check_permission(repo.id, USER2) is None

ccnet_api.remove_org_user(org.org_id, USER)
orgs = ccnet_api.get_orgs_by_user(USER)
assert len(orgs) ==0

ccnet_api.remove_org_user(org.org_id, USER2)
orgs = ccnet_api.get_orgs_by_user(USER2)
assert len(orgs) ==0


@pytest.mark.parametrize('permission', ['r', 'rw'])
def test_share_org_repo_to_group(repo, org, permission):
ccnet_api.add_org_user(org.org_id, USER, False)

assert api.check_permission(repo.id, USER) == 'rw'
assert api.check_permission(repo.id, USER2) is None

t_group_list = ccnet_api.get_groups(USER)
assert len(t_group_list) == 0

t_org_group_id = ccnet_api.create_org_group(org.org_id, 'org_group_test1', USER)
t_group_list = ccnet_api.get_groups(USER)
assert len(t_group_list) == 1

t_group_list = ccnet_api.get_groups(USER2)
assert len(t_group_list) == 0

api.group_share_repo(repo.id, t_org_group_id, USER, permission)
t_repos = api.get_repos_by_group(t_org_group_id)
assert_repo_with_permission(repo, t_repos, permission)

ccnet_api.group_add_member(t_org_group_id, USER, USER2)
t_group_list = ccnet_api.get_groups(USER2)
assert len(t_group_list) == 1
t_group = t_group_list[0]
assert t_group.id == t_org_group_id

t_group_repo = api.get_repos_by_group(t_org_group_id)
assert_repo_with_permission(repo, t_group_repo, permission)

assert api.check_permission(repo.id, USER2) == permission

api.group_unshare_repo(repo.id, t_org_group_id, USER)
t_repos_list = api.get_repos_by_group(t_org_group_id)
assert len(t_repos_list) == 0

assert api.check_permission(repo.id, USER2) is None

ccnet_api.group_remove_member(t_org_group_id, USER, USER2)
group_list = ccnet_api.get_groups(USER2)
assert len(group_list) == 0

ccnet_api.add_org_user(org.org_id, USER2, False)

group_list = ccnet_api.get_groups(USER2)
assert len(group_list) == 0

ccnet_api.group_add_member(t_org_group_id, USER, USER2)
group_list = ccnet_api.get_groups(USER2)
assert len(group_list) == 1
t_group = t_group_list[0]
assert t_group.id == t_org_group_id

ccnet_api.group_remove_member(t_org_group_id, USER, USER2)
group_list = ccnet_api.get_groups(USER2)
assert len(group_list) == 0
12 changes: 12 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@


def create_and_get_repo(*a, **kw):
repo_id = 0
repo_id = seafile_api.create_repo(*a, **kw)
assert repo_id != 0

repo = 0
repo = seafile_api.get_repo(repo_id)
assert repo != 0
assert repo.id == repo_id

return repo


Expand All @@ -25,3 +32,8 @@ def assert_repo_with_permission(r1, r2, permission):
r2 = r2[0]
assert r2.id == r1.id
assert r2.permission == permission

def create_and_get_org(*a, **kw):
org_id = ccnet_api.create_org(*a, **kw)
org = ccnet_api.get_org_by_id(org_id)
return org