forked from EnterpriseyIntranet/nextcloud-API
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_group_folders.py
131 lines (105 loc) · 5.06 KB
/
test_group_folders.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from nextcloud.base import Permission, QUOTA_UNLIMITED
from .base import BaseTestCase
class TestGroupFolders(BaseTestCase):
def setUp(self):
super(TestGroupFolders, self).setUp()
self.nxc.enable_app('groupfolders')
def test_crud_group_folder(self):
# create new group folder
folder_mount_point = "test_group_folders_" + self.get_random_string(length=4)
res = self.nxc.create_group_folder(folder_mount_point)
assert res.is_ok
group_folder_id = res.data['id']
# get all group folders and check if just created folder is in the list
res = self.nxc.get_group_folders()
assert res.is_ok
group_folders = res.data
assert str(group_folder_id) in group_folders
assert group_folders[str(group_folder_id)]['mount_point'] == folder_mount_point
# retrieve single folder
res = self.nxc.get_group_folder(group_folder_id)
assert res.is_ok
assert str(res.data['id']) == str(group_folder_id)
assert res.data['mount_point'] == folder_mount_point
# rename group folder
new_folder_mount_point = folder_mount_point + '_new'
res = self.nxc.rename_group_folder(group_folder_id, new_folder_mount_point)
assert res.is_ok and res.data is True
# check if name was changed
res = self.nxc.get_group_folder(group_folder_id)
assert res.data['mount_point'] == new_folder_mount_point
# delete group folder
res = self.nxc.delete_group_folder(group_folder_id)
assert res.is_ok
assert res.data is True
# check that deleted folder isn't retrieved
res = self.nxc.get_group_folder(group_folder_id)
assert res.is_ok
assert res.data is False
def test_grant_revoke_access_to_group_folder(self):
# create group to share with
group_id = 'test_folders_' + self.get_random_string(length=4)
self.nxc.add_group(group_id)
# create new group folder
folder_mount_point = "test_access_" + self.get_random_string(length=4)
res = self.nxc.create_group_folder(folder_mount_point)
group_folder_id = res.data['id']
# assert that no groups have access to just created folder
res = self.nxc.get_group_folder(group_folder_id)
assert len(res.data['groups']) == 0
# grant access to group
res = self.nxc.grant_access_to_group_folder(group_folder_id, group_id)
assert res.is_ok
assert res.data is True
# check that folder has this group
res = self.nxc.get_group_folder(group_folder_id)
assert res.data['groups'] == {group_id: str(Permission.ALL.value)}
# revoke access
res = self.nxc.revoke_access_to_group_folder(group_folder_id, group_id)
assert res.is_ok
assert res.data is True
# check that folder has no groups again
res = self.nxc.get_group_folder(group_folder_id)
assert len(res.data['groups']) == 0
# clear
self.clear(nxc=self.nxc, group_ids=[group_id], group_folder_ids=[group_folder_id])
def test_setting_folder_quotas(self):
# create new group folder
folder_mount_point = "test_folder_quotas_" + self.get_random_string(length=4)
res = self.nxc.create_group_folder(folder_mount_point)
group_folder_id = res.data['id']
# assert quota is unlimited by default
res = self.nxc.get_group_folder(group_folder_id)
assert int(res.data['quota']) == QUOTA_UNLIMITED
# set quota
QUOTA_ONE_GB = 1024 * 1024 * 1024
res = self.nxc.set_quota_of_group_folder(group_folder_id, QUOTA_ONE_GB)
assert res.is_ok and res.data is True
# check if quota changed
res = self.nxc.get_group_folder(group_folder_id)
assert str(res.data['quota']) == str(QUOTA_ONE_GB)
# clear
self.clear(group_folder_ids=[group_folder_id])
def test_setting_folder_permissions(self):
# create group to share with
group_id = 'test_folders_' + self.get_random_string(length=4)
self.nxc.add_group(group_id)
# create new group folder
folder_mount_point = "test_folder_permissions_" + self.get_random_string(length=4)
res = self.nxc.create_group_folder(folder_mount_point)
group_folder_id = res.data['id']
# add new group to folder
self.nxc.grant_access_to_group_folder(group_folder_id, group_id)
# assert permissions is ALL by default
res = self.nxc.get_group_folder(group_folder_id)
assert int(res.data['quota']) == QUOTA_UNLIMITED
# set permissions
new_permission = Permission.READ + Permission.CREATE
res = self.nxc.set_permissions_to_group_folder(group_folder_id, group_id, new_permission)
assert res.is_ok
assert res.data is True
# check if permissions changed
res = self.nxc.get_group_folder(group_folder_id)
assert str(res.data['groups'][group_id]) == str(new_permission)
# clear
self.clear(nxc=self.nxc, group_ids=[group_id], group_folder_ids=[group_folder_id])