mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-03 16:34:33 +00:00
share repo to group (#123)
This commit is contained in:
@@ -9,7 +9,7 @@ from tests.config import (
|
|||||||
ADMIN_PASSWORD, ADMIN_USER, INACTIVE_PASSWORD, INACTIVE_USER, PASSWORD,
|
ADMIN_PASSWORD, ADMIN_USER, INACTIVE_PASSWORD, INACTIVE_USER, PASSWORD,
|
||||||
PASSWORD2, USER, USER2
|
PASSWORD2, USER, USER2
|
||||||
)
|
)
|
||||||
from tests.utils import create_and_get_repo, randstring
|
from tests.utils import create_and_get_repo, randstring, create_and_get_group
|
||||||
|
|
||||||
from seaserv import ccnet_api, seafile_api
|
from seaserv import ccnet_api, seafile_api
|
||||||
|
|
||||||
@@ -49,3 +49,17 @@ def repo():
|
|||||||
if seafile_api.get_repo(repo.id):
|
if seafile_api.get_repo(repo.id):
|
||||||
# The repo may be deleted in the test case
|
# The repo may be deleted in the test case
|
||||||
seafile_api.remove_repo(repo.id)
|
seafile_api.remove_repo(repo.id)
|
||||||
|
|
||||||
|
@pytest.yield_fixture(scope='function')
|
||||||
|
def group():
|
||||||
|
group = create_and_get_group(
|
||||||
|
'test_group测试-{}'.format(randstring(10)), USER, gtype=None
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
yield group
|
||||||
|
finally:
|
||||||
|
if ccnet_api.get_group(group.id):
|
||||||
|
ccnet_api.remove_group(group.id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -6,7 +6,8 @@ from tests.config import ADMIN_USER, USER, USER2
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('permission', ['r', 'rw'])
|
@pytest.mark.parametrize('permission', ['r', 'rw'])
|
||||||
def test_share_repo(repo, permission):
|
def test_share_repo_to_user(repo, permission):
|
||||||
|
assert api.check_permission(repo.id, USER) == 'rw'
|
||||||
assert api.check_permission(repo.id, USER2) is None
|
assert api.check_permission(repo.id, USER2) is None
|
||||||
|
|
||||||
api.share_repo(repo.id, USER, USER2, permission)
|
api.share_repo(repo.id, USER, USER2, permission)
|
||||||
@@ -20,3 +21,44 @@ def test_share_repo(repo, permission):
|
|||||||
|
|
||||||
api.remove_share(repo.id, USER, USER2)
|
api.remove_share(repo.id, USER, USER2)
|
||||||
assert api.check_permission(repo.id, USER2) is None
|
assert api.check_permission(repo.id, USER2) is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('permission', ['r', 'rw'])
|
||||||
|
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
|
||||||
|
|
||||||
|
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 len(repos) == 1
|
||||||
|
r = repos[0]
|
||||||
|
assert r.id == repo.id
|
||||||
|
assert r.permission == permission
|
||||||
|
|
||||||
|
ccnet_api.group_add_member(group.id, USER, USER2)
|
||||||
|
group_list = ccnet_api.get_groups(USER2)
|
||||||
|
assert len(group_list) == 1
|
||||||
|
g = group_list[0]
|
||||||
|
assert g.id == group.id
|
||||||
|
|
||||||
|
repos2 = api.get_repos_by_group(g.id)
|
||||||
|
assert len(repos2) == 1
|
||||||
|
r2 = repos2[0]
|
||||||
|
assert r2.id == repo.id
|
||||||
|
assert r2.permission == permission
|
||||||
|
|
||||||
|
assert api.check_permission(repo.id, USER2) == permission
|
||||||
|
|
||||||
|
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
|
||||||
|
@@ -13,3 +13,8 @@ def create_and_get_repo(*a, **kw):
|
|||||||
|
|
||||||
def randstring(length=12):
|
def randstring(length=12):
|
||||||
return ''.join(random.choice(string.lowercase) for i in range(length))
|
return ''.join(random.choice(string.lowercase) for i in range(length))
|
||||||
|
|
||||||
|
def create_and_get_group(*a, **kw):
|
||||||
|
group_id = ccnet_api.create_group(*a, **kw)
|
||||||
|
group = ccnet_api.get_group(group_id)
|
||||||
|
return group
|
||||||
|
Reference in New Issue
Block a user