mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-05-11 01:27:27 +00:00
Merge 5c871b2b10
into 2a6ddc4851
This commit is contained in:
commit
2a36670706
68
tests/test_folder.py
Normal file
68
tests/test_folder.py
Normal file
@ -0,0 +1,68 @@
|
||||
import pytest
|
||||
from seaserv import seafile_api as api
|
||||
from seaserv import ccnet_api
|
||||
|
||||
from tests.config import USER, USER2
|
||||
|
||||
@pytest.mark.parametrize('permission', ['r', 'rw'])
|
||||
def test_share_folder_to_user(repo, permission):
|
||||
parent_dir = '/'
|
||||
test_fold = 'fold_test'
|
||||
path = parent_dir + test_fold
|
||||
api.post_dir(repo.id, parent_dir, test_fold, USER)
|
||||
|
||||
api.share_subdir_to_user(repo.id, path, USER, USER2, permission)
|
||||
api.check_permission_by_path(repo.id, path, USER) == 'rw'
|
||||
|
||||
repos = api.get_share_in_repo_list(USER2, 0, 1)
|
||||
|
||||
if isinstance(repos, list):
|
||||
assert len(repos) == 1
|
||||
dir_repo = repos[0]
|
||||
assert dir_repo.name == test_fold
|
||||
assert dir_repo.permission == permission
|
||||
assert api.get_repo_owner(dir_repo.id) == USER
|
||||
|
||||
subdir = 'sub_test'
|
||||
path_sub = path + subdir
|
||||
api.post_dir(repo.id, path, subdir, USER)
|
||||
|
||||
assert api.check_permission_by_path(repo.id, path_sub, USER) == 'rw'
|
||||
assert api.check_permission_by_path(dir_repo.id, path_sub, USER2) == permission
|
||||
|
||||
api.unshare_subdir_for_user(repo.id, path, USER, USER2)
|
||||
folds = api.get_share_in_repo_list(USER2, 0, 1)
|
||||
assert len(folds) == 0
|
||||
|
||||
api.del_file(repo.id, parent_dir, test_fold, USER)
|
||||
api.check_permission_by_path(repo.id, path, USER) is None
|
||||
|
||||
@pytest.mark.parametrize('permission', ['r', 'rw'])
|
||||
def test_share_folder_to_group(repo, group, permission):
|
||||
parent_dir = '/'
|
||||
test_fold = 'fold2'
|
||||
path = parent_dir + test_fold
|
||||
api.post_dir(repo.id, parent_dir, test_fold, USER)
|
||||
api.check_permission_by_path(repo.id, path, USER) == 'rw'
|
||||
|
||||
ccnet_api.group_add_member(group.id, USER, USER2)
|
||||
api.share_subdir_to_group(repo.id, path, USER, group.id, permission, passwd='')
|
||||
group_list = ccnet_api.get_groups(USER2)
|
||||
if isinstance(group_list, list):
|
||||
assert len(group_list) == 1
|
||||
s_group = group_list[0]
|
||||
assert group.id == s_group.id
|
||||
|
||||
repos_list = api.get_repos_by_group(s_group.id)
|
||||
assert len(repos_list) == 1
|
||||
g_repo = repos_list[0]
|
||||
|
||||
assert g_repo.name == test_fold
|
||||
assert api.check_permission_by_path(g_repo.id, path, USER2) == permission
|
||||
assert api.get_repo_owner(g_repo.id) == USER
|
||||
|
||||
api.unshare_subdir_for_group(repo.id, path, USER, group.id)
|
||||
assert api.check_permission_by_path(g_repo.id, path, USER2) is None
|
||||
|
||||
api.del_file(repo.id, parent_dir, test_fold, USER)
|
||||
api.check_permission_by_path(repo.id, path, USER) is None
|
40
tests/test_users.py
Normal file
40
tests/test_users.py
Normal file
@ -0,0 +1,40 @@
|
||||
import pytest
|
||||
from seaserv import seafile_api as api
|
||||
from seaserv import ccnet_api
|
||||
from tests.utils import randstring
|
||||
from tests.config import USER, USER2, ADMIN_USER
|
||||
|
||||
def test_user_management(repo):
|
||||
email1 = '%s@%s.com' % (randstring(6), randstring(6))
|
||||
email2 = '%s@%s.com' % (randstring(6), randstring(6))
|
||||
passwd1 = 'randstring(6)'
|
||||
passwd2 = 'randstring(6)'
|
||||
|
||||
ccnet_api.add_emailuser(email1, passwd1, 1, 1)
|
||||
ccnet_api.add_emailuser(email2, passwd2, 0, 0)
|
||||
|
||||
ccnet_email1 = ccnet_api.get_emailuser(email1)
|
||||
ccnet_email2 = ccnet_api.get_emailuser(email2)
|
||||
assert ccnet_email1.is_active == True
|
||||
assert ccnet_email1.is_staff == True
|
||||
assert ccnet_email2.is_active == False
|
||||
assert ccnet_email2.is_staff == False
|
||||
|
||||
assert ccnet_api.validate_emailuser(email1, passwd1) == 0
|
||||
assert ccnet_api.validate_emailuser(email2, passwd2) == 0
|
||||
|
||||
users_from_ccnet = ccnet_api.search_emailusers('DB',email1, -1, -1)
|
||||
assert len(users_from_ccnet) == 1
|
||||
user_ccnet = users_from_ccnet[0]
|
||||
assert user_ccnet.email == email1
|
||||
|
||||
user_counts = ccnet_api.count_emailusers('DB')
|
||||
user_numbers = ccnet_api.get_emailusers('DB', -1, -1)
|
||||
|
||||
ccnet_api.update_emailuser('DB', ccnet_email2.id, passwd2, 1, 1)
|
||||
email2_new = ccnet_api.get_emailuser(email2)
|
||||
assert email2_new.is_active == True
|
||||
assert email2_new.is_staff == True
|
||||
|
||||
ccnet_api.remove_emailuser('DB', email1)
|
||||
ccnet_api.remove_emailuser('DB', email2)
|
Loading…
Reference in New Issue
Block a user