1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
|
3
|
|
|
from nose.tools import eq_, ok_ |
|
|
|
|
4
|
|
|
from nose.tools import raises |
|
|
|
|
5
|
|
|
|
6
|
|
|
import transaction |
7
|
|
|
|
8
|
|
|
from tracim.config import CFG |
|
|
|
|
9
|
|
|
from tracim.lib.core.content import compare_content_for_sorting_by_type_and_name |
10
|
|
|
from tracim.lib.core.content import ContentApi |
11
|
|
|
# TODO - G.M - 28-03-2018 - [GroupApi] Re-enable GroupApi |
|
|
|
|
12
|
|
|
from tracim.lib.core.group import GroupApi |
13
|
|
|
from tracim.lib.core.user import UserApi |
14
|
|
|
from tracim.exceptions import SameValueError |
15
|
|
|
# TODO - G.M - 28-03-2018 - [RoleApi] Re-enable RoleApi |
|
|
|
|
16
|
|
|
from tracim.lib.core.workspace import RoleApi |
17
|
|
|
# TODO - G.M - 28-03-2018 - [WorkspaceApi] Re-enable WorkspaceApi |
|
|
|
|
18
|
|
|
from tracim.lib.core.workspace import WorkspaceApi |
19
|
|
|
from tracim.models.revision_protection import new_revision |
20
|
|
|
from tracim.models.auth import User |
21
|
|
|
from tracim.models.auth import Group |
22
|
|
|
|
23
|
|
|
from tracim.models.data import ActionDescription |
24
|
|
|
from tracim.models.data import ContentRevisionRO |
25
|
|
|
from tracim.models.data import Workspace |
26
|
|
|
from tracim.models.data import Content |
27
|
|
|
from tracim.models.data import ContentType |
28
|
|
|
from tracim.models.data import UserRoleInWorkspace |
29
|
|
|
from tracim.fixtures.users_and_groups import Test as FixtureTest |
30
|
|
|
from tracim.tests import DefaultTest |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
class TestContentApi(DefaultTest): |
|
|
|
|
34
|
|
|
|
35
|
|
|
def test_compare_content_for_sorting_by_type(self): |
|
|
|
|
36
|
|
|
c1 = Content() |
|
|
|
|
37
|
|
|
c1.label = '' |
38
|
|
|
c1.type = 'file' |
39
|
|
|
|
40
|
|
|
c2 = Content() |
|
|
|
|
41
|
|
|
c2.label = '' |
42
|
|
|
c2.type = 'folder' |
43
|
|
|
|
44
|
|
|
c11 = c1 |
45
|
|
|
|
46
|
|
|
eq_(1, compare_content_for_sorting_by_type_and_name(c1, c2)) |
47
|
|
|
eq_(-1, compare_content_for_sorting_by_type_and_name(c2, c1)) |
48
|
|
|
eq_(0, compare_content_for_sorting_by_type_and_name(c1, c11)) |
49
|
|
|
|
50
|
|
|
def test_compare_content_for_sorting_by_label(self): |
|
|
|
|
51
|
|
|
c1 = Content() |
|
|
|
|
52
|
|
|
c1.label = 'bbb' |
53
|
|
|
c1.type = 'file' |
54
|
|
|
|
55
|
|
|
c2 = Content() |
|
|
|
|
56
|
|
|
c2.label = 'aaa' |
57
|
|
|
c2.type = 'file' |
58
|
|
|
|
59
|
|
|
c11 = c1 |
60
|
|
|
|
61
|
|
|
eq_(1, compare_content_for_sorting_by_type_and_name(c1, c2)) |
62
|
|
|
eq_(-1, compare_content_for_sorting_by_type_and_name(c2, c1)) |
63
|
|
|
eq_(0, compare_content_for_sorting_by_type_and_name(c1, c11)) |
64
|
|
|
|
65
|
|
|
def test_sort_by_label_or_filename(self): |
|
|
|
|
66
|
|
|
c1 = Content() |
|
|
|
|
67
|
|
|
c1.label = 'ABCD' |
68
|
|
|
c1.type = 'file' |
69
|
|
|
|
70
|
|
|
c2 = Content() |
|
|
|
|
71
|
|
|
c2.label = '' |
72
|
|
|
c2.type = 'file' |
73
|
|
|
c2.file_name = 'AABC' |
74
|
|
|
|
75
|
|
|
c3 = Content() |
|
|
|
|
76
|
|
|
c3.label = 'BCDE' |
77
|
|
|
c3.type = 'file' |
78
|
|
|
|
79
|
|
|
items = [c1, c2, c3] |
80
|
|
|
sorteds = ContentApi.sort_content(items) |
81
|
|
|
|
82
|
|
|
eq_(sorteds[0], c2) |
83
|
|
|
eq_(sorteds[1], c1) |
84
|
|
|
eq_(sorteds[2], c3) |
85
|
|
|
|
86
|
|
|
def test_sort_by_content_type(self): |
|
|
|
|
87
|
|
|
c1 = Content() |
|
|
|
|
88
|
|
|
c1.label = 'AAAA' |
89
|
|
|
c1.type = 'file' |
90
|
|
|
|
91
|
|
|
c2 = Content() |
|
|
|
|
92
|
|
|
c2.label = 'BBBB' |
93
|
|
|
c2.type = 'folder' |
94
|
|
|
|
95
|
|
|
items = [c1, c2] |
96
|
|
|
sorteds = ContentApi.sort_content(items) |
97
|
|
|
|
98
|
|
|
eq_(sorteds[0], c2, |
99
|
|
|
'value is {} instead of {}'.format(sorteds[0].content_id, |
100
|
|
|
c2.content_id)) |
101
|
|
|
eq_(sorteds[1], c1, |
102
|
|
|
'value is {} instead of {}'.format(sorteds[1].content_id, |
103
|
|
|
c1.content_id)) |
104
|
|
|
|
105
|
|
|
def test_delete(self): |
|
|
|
|
106
|
|
|
uapi = UserApi( |
107
|
|
|
session=self.session, |
108
|
|
|
config=self.app_config, |
109
|
|
|
current_user=None, |
110
|
|
|
) |
111
|
|
|
group_api = GroupApi(current_user=None,session=self.session) |
|
|
|
|
112
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
113
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
114
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
115
|
|
|
|
116
|
|
|
user = uapi.create_user(email='this.is@user', |
117
|
|
|
groups=groups, save_now=True) |
118
|
|
|
workspace = WorkspaceApi( |
119
|
|
|
current_user=user, |
120
|
|
|
session=self.session |
121
|
|
|
).create_workspace('test workspace', save_now=True) |
122
|
|
|
api = ContentApi( |
123
|
|
|
current_user=user, |
124
|
|
|
session=self.session, |
125
|
|
|
config=self.app_config, |
126
|
|
|
) |
127
|
|
|
item = api.create(ContentType.Folder, workspace, None, |
|
|
|
|
128
|
|
|
'not_deleted', True) |
129
|
|
|
item2 = api.create(ContentType.Folder, workspace, None, |
|
|
|
|
130
|
|
|
'to_delete', True) |
131
|
|
|
uid = user.user_id |
132
|
|
|
wid = workspace.workspace_id |
133
|
|
|
transaction.commit() |
134
|
|
|
|
135
|
|
|
# Refresh instances after commit |
136
|
|
|
user = uapi.get_one(uid) |
137
|
|
|
workspace_api = WorkspaceApi(current_user=user, session=self.session) |
138
|
|
|
workspace = workspace_api.get_one(wid) |
139
|
|
|
api = ContentApi( |
140
|
|
|
current_user=user, |
141
|
|
|
session=self.session, |
142
|
|
|
config=self.app_config, |
143
|
|
|
) |
144
|
|
|
items = api.get_all(None, ContentType.Any, workspace) |
145
|
|
|
eq_(2, len(items)) |
146
|
|
|
|
147
|
|
|
items = api.get_all(None, ContentType.Any, workspace) |
148
|
|
|
with new_revision( |
149
|
|
|
session=self.session, |
|
|
|
|
150
|
|
|
tm=transaction.manager, |
|
|
|
|
151
|
|
|
content=items[0] |
|
|
|
|
152
|
|
|
): |
153
|
|
|
api.delete(items[0]) |
154
|
|
|
transaction.commit() |
155
|
|
|
|
156
|
|
|
# Refresh instances after commit |
157
|
|
|
user = uapi.get_one(uid) |
158
|
|
|
workspace_api = WorkspaceApi(current_user=user, session=self.session) |
159
|
|
|
workspace = workspace_api.get_one(wid) |
160
|
|
|
api = ContentApi( |
161
|
|
|
current_user=user, |
|
|
|
|
162
|
|
|
session=self.session, |
163
|
|
|
config=self.app_config, |
164
|
|
|
) |
165
|
|
|
items = api.get_all(None, ContentType.Any, workspace) |
166
|
|
|
eq_(1, len(items)) |
167
|
|
|
transaction.commit() |
168
|
|
|
|
169
|
|
|
# Test that the item is still available if "show deleted" is activated |
170
|
|
|
# Refresh instances after commit |
171
|
|
|
user = uapi.get_one(uid) |
172
|
|
|
workspace_api = WorkspaceApi(current_user=user, session=self.session) |
173
|
|
|
api = ContentApi( |
174
|
|
|
current_user=user, |
175
|
|
|
session=self.session, |
176
|
|
|
config=self.app_config, |
177
|
|
|
show_deleted=True, |
178
|
|
|
) |
179
|
|
|
items = api.get_all(None, ContentType.Any, workspace) |
180
|
|
|
eq_(2, len(items)) |
181
|
|
|
|
182
|
|
|
def test_archive(self): |
|
|
|
|
183
|
|
|
uapi = UserApi( |
184
|
|
|
session=self.session, |
185
|
|
|
config=self.app_config, |
186
|
|
|
current_user=None, |
187
|
|
|
) |
188
|
|
|
group_api = GroupApi(current_user=None, session=self.session) |
189
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
190
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
191
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
192
|
|
|
|
193
|
|
|
user = uapi.create_user(email='this.is@user', |
194
|
|
|
groups=groups, save_now=True) |
195
|
|
|
workspace_api = WorkspaceApi(current_user=user, session=self.session) |
196
|
|
|
workspace = workspace_api.create_workspace( |
197
|
|
|
'test workspace', |
198
|
|
|
save_now=True |
199
|
|
|
) |
200
|
|
|
api = ContentApi( |
201
|
|
|
current_user=user, |
202
|
|
|
session=self.session, |
203
|
|
|
config=self.app_config, |
204
|
|
|
) |
205
|
|
|
item = api.create(ContentType.Folder, workspace, None, |
|
|
|
|
206
|
|
|
'not_archived', True) |
207
|
|
|
item2 = api.create(ContentType.Folder, workspace, None, |
|
|
|
|
208
|
|
|
'to_archive', True) |
209
|
|
|
uid = user.user_id |
210
|
|
|
wid = workspace.workspace_id |
211
|
|
|
transaction.commit() |
212
|
|
|
# Refresh instances after commit |
213
|
|
|
user = uapi.get_one(uid) |
214
|
|
|
workspace_api = WorkspaceApi(current_user=user, session=self.session) |
215
|
|
|
api = ContentApi( |
216
|
|
|
session=self.session, |
217
|
|
|
current_user=user, |
218
|
|
|
config=self.app_config, |
219
|
|
|
) |
220
|
|
|
|
221
|
|
|
items = api.get_all(None, ContentType.Any, workspace) |
222
|
|
|
eq_(2, len(items)) |
223
|
|
|
|
224
|
|
|
items = api.get_all(None, ContentType.Any, workspace) |
225
|
|
|
with new_revision( |
226
|
|
|
session=self.session, |
|
|
|
|
227
|
|
|
tm=transaction.manager, |
|
|
|
|
228
|
|
|
content=items[0], |
|
|
|
|
229
|
|
|
): |
230
|
|
|
api.archive(items[0]) |
231
|
|
|
transaction.commit() |
232
|
|
|
|
233
|
|
|
# Refresh instances after commit |
234
|
|
|
user = uapi.get_one(uid) |
235
|
|
|
workspace_api = WorkspaceApi(current_user=user, session=self.session) |
236
|
|
|
workspace = workspace_api.get_one(wid) |
237
|
|
|
api = ContentApi( |
238
|
|
|
current_user=user, |
|
|
|
|
239
|
|
|
session=self.session, |
240
|
|
|
config=self.app_config, |
241
|
|
|
) |
242
|
|
|
|
243
|
|
|
items = api.get_all(None, ContentType.Any, workspace) |
244
|
|
|
eq_(1, len(items)) |
245
|
|
|
transaction.commit() |
246
|
|
|
|
247
|
|
|
# Refresh instances after commit |
248
|
|
|
user = uapi.get_one(uid) |
249
|
|
|
workspace_api = WorkspaceApi(current_user=user, session=self.session) |
250
|
|
|
workspace = workspace_api.get_one(wid) |
251
|
|
|
api = ContentApi( |
252
|
|
|
current_user=user, |
253
|
|
|
session=self.session, |
254
|
|
|
config=self.app_config, |
255
|
|
|
) |
256
|
|
|
|
257
|
|
|
# Test that the item is still available if "show deleted" is activated |
258
|
|
|
api = ContentApi( |
259
|
|
|
current_user=None, |
260
|
|
|
session=self.session, |
261
|
|
|
config=self.app_config, |
262
|
|
|
show_archived=True, |
263
|
|
|
) |
264
|
|
|
items = api.get_all(None, ContentType.Any, workspace) |
265
|
|
|
eq_(2, len(items)) |
266
|
|
|
|
267
|
|
|
def test_get_all_with_filter(self): |
|
|
|
|
268
|
|
|
uapi = UserApi( |
269
|
|
|
session=self.session, |
270
|
|
|
config=self.app_config, |
271
|
|
|
current_user=None, |
272
|
|
|
) |
273
|
|
|
group_api = GroupApi(current_user=None, session=self.session) |
274
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
275
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
276
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
277
|
|
|
|
278
|
|
|
user = uapi.create_user( |
279
|
|
|
email='this.is@user', |
280
|
|
|
groups=groups, |
281
|
|
|
save_now=True |
282
|
|
|
) |
283
|
|
|
workspace = WorkspaceApi( |
284
|
|
|
current_user=user, |
285
|
|
|
session=self.session |
286
|
|
|
).create_workspace( |
287
|
|
|
'test workspace', |
288
|
|
|
save_now=True |
289
|
|
|
) |
290
|
|
|
|
291
|
|
|
api = ContentApi( |
292
|
|
|
current_user=user, |
293
|
|
|
session=self.session, |
294
|
|
|
config=self.app_config, |
295
|
|
|
) |
296
|
|
|
item = api.create(ContentType.Folder, workspace, None, |
|
|
|
|
297
|
|
|
'thefolder', True) |
298
|
|
|
item2 = api.create(ContentType.File, workspace, None, 'thefile', True) |
|
|
|
|
299
|
|
|
uid = user.user_id |
300
|
|
|
wid = workspace.workspace_id |
301
|
|
|
transaction.commit() |
302
|
|
|
|
303
|
|
|
# Refresh instances after commit |
304
|
|
|
user = uapi.get_one(uid) |
305
|
|
|
workspace_api = WorkspaceApi(current_user=user, session=self.session) |
306
|
|
|
workspace = workspace_api.get_one(wid) |
307
|
|
|
api = ContentApi( |
308
|
|
|
current_user=user, |
|
|
|
|
309
|
|
|
session=self.session, |
310
|
|
|
config=self.app_config, |
311
|
|
|
) |
312
|
|
|
|
313
|
|
|
items = api.get_all(None, ContentType.Any, workspace) |
314
|
|
|
eq_(2, len(items)) |
315
|
|
|
|
316
|
|
|
items2 = api.get_all(None, ContentType.File, workspace) |
317
|
|
|
eq_(1, len(items2)) |
318
|
|
|
eq_('thefile', items2[0].label) |
319
|
|
|
|
320
|
|
|
items3 = api.get_all(None, ContentType.Folder, workspace) |
321
|
|
|
eq_(1, len(items3)) |
322
|
|
|
eq_('thefolder', items3[0].label) |
323
|
|
|
|
324
|
|
|
def test_get_all_with_parent_id(self): |
|
|
|
|
325
|
|
|
uapi = UserApi( |
326
|
|
|
session=self.session, |
327
|
|
|
config=self.app_config, |
328
|
|
|
current_user=None, |
329
|
|
|
) |
330
|
|
|
group_api = GroupApi(current_user=None, session=self.session) |
331
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
332
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
333
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
334
|
|
|
|
335
|
|
|
user = uapi.create_user(email='this.is@user', |
336
|
|
|
groups=groups, save_now=True) |
337
|
|
|
workspace = WorkspaceApi( |
338
|
|
|
current_user=user, |
339
|
|
|
session=self.session |
340
|
|
|
).create_workspace('test workspace', save_now=True) |
341
|
|
|
api = ContentApi( |
342
|
|
|
current_user=user, |
|
|
|
|
343
|
|
|
session=self.session, |
344
|
|
|
config=self.app_config, |
345
|
|
|
) |
346
|
|
|
item = api.create( |
347
|
|
|
ContentType.Folder, |
348
|
|
|
workspace, |
349
|
|
|
None, |
350
|
|
|
'parent', |
351
|
|
|
do_save=True, |
352
|
|
|
) |
353
|
|
|
item2 = api.create( |
354
|
|
|
ContentType.File, |
355
|
|
|
workspace, |
356
|
|
|
item, |
357
|
|
|
'file1', |
358
|
|
|
do_save=True, |
359
|
|
|
) |
360
|
|
|
item3 = api.create( |
|
|
|
|
361
|
|
|
ContentType.File, |
362
|
|
|
workspace, |
363
|
|
|
None, |
364
|
|
|
'file2', |
365
|
|
|
do_save=True, |
366
|
|
|
) |
367
|
|
|
parent_id = item.content_id |
368
|
|
|
child_id = item2.content_id |
369
|
|
|
uid = user.user_id |
370
|
|
|
wid = workspace.workspace_id |
371
|
|
|
transaction.commit() |
372
|
|
|
|
373
|
|
|
# Refresh instances after commit |
374
|
|
|
user = uapi.get_one(uid) |
375
|
|
|
workspace_api = WorkspaceApi(current_user=user, session=self.session) |
376
|
|
|
workspace = workspace_api.get_one(wid) |
377
|
|
|
api = ContentApi( |
378
|
|
|
current_user=user, |
379
|
|
|
session=self.session, |
380
|
|
|
config=self.app_config, |
381
|
|
|
) |
382
|
|
|
|
383
|
|
|
items = api.get_all(None, ContentType.Any, workspace) |
384
|
|
|
eq_(3, len(items)) |
385
|
|
|
|
386
|
|
|
items2 = api.get_all(parent_id, ContentType.File, workspace) |
387
|
|
|
eq_(1, len(items2)) |
388
|
|
|
eq_(child_id, items2[0].content_id) |
389
|
|
|
|
390
|
|
|
@raises(ValueError) |
391
|
|
|
def test_set_status_unknown_status(self): |
|
|
|
|
392
|
|
|
uapi = UserApi( |
393
|
|
|
session=self.session, |
394
|
|
|
config=self.app_config, |
395
|
|
|
current_user=None, |
396
|
|
|
) |
397
|
|
|
group_api = GroupApi( |
398
|
|
|
current_user=None, |
399
|
|
|
session=self.session |
400
|
|
|
) |
401
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
402
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
403
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
404
|
|
|
|
405
|
|
|
user = uapi.create_user(email='this.is@user', |
406
|
|
|
groups=groups, save_now=True) |
407
|
|
|
|
408
|
|
|
workspace = WorkspaceApi( |
409
|
|
|
current_user=user, |
410
|
|
|
session=self.session |
411
|
|
|
).create_workspace( |
412
|
|
|
'test workspace', |
413
|
|
|
save_now=True |
414
|
|
|
) |
415
|
|
|
api = ContentApi( |
416
|
|
|
current_user=user, |
|
|
|
|
417
|
|
|
session=self.session, |
418
|
|
|
config=self.app_config, |
419
|
|
|
) |
420
|
|
|
c = api.create(ContentType.Folder, workspace, None, 'parent', True) |
|
|
|
|
421
|
|
|
with new_revision( |
422
|
|
|
session=self.session, |
423
|
|
|
tm=transaction.manager, |
424
|
|
|
content=c, |
425
|
|
|
): |
426
|
|
|
api.set_status(c, 'unknown-status') |
427
|
|
|
|
428
|
|
|
def test_set_status_ok(self): |
|
|
|
|
429
|
|
|
uapi = UserApi( |
430
|
|
|
session=self.session, |
431
|
|
|
config=self.app_config, |
432
|
|
|
current_user=None, |
433
|
|
|
) |
434
|
|
|
group_api = GroupApi( |
435
|
|
|
current_user=None, |
436
|
|
|
session=self.session |
437
|
|
|
) |
438
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
439
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
440
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
441
|
|
|
|
442
|
|
|
user = uapi.create_user(email='this.is@user', |
443
|
|
|
groups=groups, save_now=True) |
444
|
|
|
|
445
|
|
|
workspace = WorkspaceApi( |
446
|
|
|
current_user=user, |
447
|
|
|
session=self.session |
448
|
|
|
).create_workspace( |
449
|
|
|
'test workspace', |
450
|
|
|
save_now=True |
451
|
|
|
) |
452
|
|
|
api = ContentApi( |
453
|
|
|
current_user=user, |
454
|
|
|
session=self.session, |
455
|
|
|
config=self.app_config, |
456
|
|
|
) |
457
|
|
|
c = api.create(ContentType.Folder, workspace, None, 'parent', True) |
|
|
|
|
458
|
|
|
with new_revision( |
459
|
|
|
session=self.session, |
460
|
|
|
tm=transaction.manager, |
461
|
|
|
content=c, |
462
|
|
|
): |
463
|
|
|
for new_status in ['open', 'closed-validated', 'closed-unvalidated', |
464
|
|
|
'closed-deprecated']: |
465
|
|
|
api.set_status(c, new_status) |
466
|
|
|
|
467
|
|
|
eq_(new_status, c.status) |
468
|
|
|
eq_(ActionDescription.STATUS_UPDATE, c.revision_type) |
469
|
|
|
|
470
|
|
|
def test_create_comment_ok(self): |
|
|
|
|
471
|
|
|
uapi = UserApi( |
472
|
|
|
session=self.session, |
473
|
|
|
config=self.app_config, |
474
|
|
|
current_user=None, |
475
|
|
|
) |
476
|
|
|
group_api = GroupApi( |
477
|
|
|
current_user=None, |
478
|
|
|
session=self.session |
479
|
|
|
) |
480
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
481
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
482
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
483
|
|
|
|
484
|
|
|
user = uapi.create_user(email='this.is@user', |
485
|
|
|
groups=groups, save_now=True) |
486
|
|
|
|
487
|
|
|
workspace = WorkspaceApi( |
488
|
|
|
current_user=user, |
489
|
|
|
session=self.session |
490
|
|
|
).create_workspace( |
491
|
|
|
'test workspace', |
492
|
|
|
save_now=True |
493
|
|
|
) |
494
|
|
|
|
495
|
|
|
api = ContentApi( |
496
|
|
|
current_user=user, |
497
|
|
|
session=self.session, |
498
|
|
|
config=self.app_config, |
499
|
|
|
) |
500
|
|
|
p = api.create(ContentType.Page, workspace, None, 'this_is_a_page') |
|
|
|
|
501
|
|
|
c = api.create_comment(workspace, p, 'this is the comment', True) |
|
|
|
|
502
|
|
|
|
503
|
|
|
eq_(Content, c.__class__) |
504
|
|
|
eq_(p.content_id, c.parent_id) |
505
|
|
|
eq_(user, c.owner) |
506
|
|
|
eq_(workspace, c.workspace) |
507
|
|
|
eq_(ContentType.Comment, c.type) |
508
|
|
|
eq_('this is the comment', c.description) |
509
|
|
|
eq_('', c.label) |
510
|
|
|
eq_(ActionDescription.COMMENT, c.revision_type) |
511
|
|
|
|
512
|
|
View Code Duplication |
def test_unit_copy_file_different_label_different_parent_ok(self): |
|
|
|
|
513
|
|
|
uapi = UserApi( |
514
|
|
|
session=self.session, |
515
|
|
|
config=self.app_config, |
516
|
|
|
current_user=None, |
517
|
|
|
) |
518
|
|
|
group_api = GroupApi( |
519
|
|
|
current_user=None, |
520
|
|
|
session=self.session |
521
|
|
|
) |
522
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
523
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
524
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
525
|
|
|
|
526
|
|
|
user = uapi.create_user( |
527
|
|
|
email='user1@user', |
528
|
|
|
groups=groups, |
529
|
|
|
save_now=True |
530
|
|
|
) |
531
|
|
|
user2 = uapi.create_user( |
532
|
|
|
email='user2@user', |
533
|
|
|
groups=groups, |
534
|
|
|
save_now=True |
535
|
|
|
) |
536
|
|
|
workspace = WorkspaceApi( |
537
|
|
|
current_user=user, |
538
|
|
|
session=self.session |
539
|
|
|
).create_workspace( |
540
|
|
|
'test workspace', |
541
|
|
|
save_now=True |
542
|
|
|
) |
543
|
|
|
RoleApi(current_user=user, session=self.session).create_one( |
544
|
|
|
user2, |
545
|
|
|
workspace, |
546
|
|
|
UserRoleInWorkspace.WORKSPACE_MANAGER, |
547
|
|
|
with_notif=False |
548
|
|
|
) |
549
|
|
|
api = ContentApi( |
550
|
|
|
current_user=user, |
551
|
|
|
session=self.session, |
552
|
|
|
config=self.app_config, |
553
|
|
|
) |
554
|
|
|
foldera = api.create( |
555
|
|
|
ContentType.Folder, |
556
|
|
|
workspace, |
557
|
|
|
None, |
558
|
|
|
'folder a', |
559
|
|
|
True |
560
|
|
|
) |
561
|
|
|
with self.session.no_autoflush: |
562
|
|
|
text_file = api.create( |
563
|
|
|
content_type=ContentType.File, |
564
|
|
|
workspace=workspace, |
565
|
|
|
parent=foldera, |
566
|
|
|
label='test_file', |
567
|
|
|
do_save=False, |
568
|
|
|
) |
569
|
|
|
api.update_file_data( |
570
|
|
|
text_file, |
571
|
|
|
'test_file', |
572
|
|
|
'text/plain', |
573
|
|
|
b'test_content' |
574
|
|
|
) |
575
|
|
|
|
576
|
|
|
api.save(text_file, ActionDescription.CREATION) |
577
|
|
|
api2 = ContentApi( |
578
|
|
|
current_user=user2, |
579
|
|
|
session=self.session, |
580
|
|
|
config=self.app_config, |
581
|
|
|
) |
582
|
|
|
workspace2 = WorkspaceApi( |
583
|
|
|
current_user=user2, |
584
|
|
|
session=self.session, |
585
|
|
|
).create_workspace( |
586
|
|
|
'test workspace2', |
587
|
|
|
save_now=True |
588
|
|
|
) |
589
|
|
|
folderb = api2.create( |
590
|
|
|
ContentType.Folder, |
591
|
|
|
workspace2, |
592
|
|
|
None, |
593
|
|
|
'folder b', |
594
|
|
|
True |
595
|
|
|
) |
596
|
|
|
|
597
|
|
|
api2.copy( |
598
|
|
|
item=text_file, |
599
|
|
|
new_parent=folderb, |
600
|
|
|
new_label='test_file_copy' |
601
|
|
|
) |
602
|
|
|
|
603
|
|
|
transaction.commit() |
604
|
|
|
text_file_copy = api2.get_one_by_label_and_parent( |
605
|
|
|
'test_file_copy', |
606
|
|
|
folderb, |
607
|
|
|
) |
608
|
|
|
|
609
|
|
|
assert text_file != text_file_copy |
610
|
|
|
assert text_file_copy.content_id != text_file.content_id |
611
|
|
|
assert text_file_copy.workspace_id == workspace2.workspace_id |
612
|
|
|
assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8 |
|
|
|
|
613
|
|
|
assert text_file_copy.depot_file.path != text_file.depot_file.path |
|
|
|
|
614
|
|
|
assert text_file_copy.label == 'test_file_copy' |
615
|
|
|
assert text_file_copy.type == text_file.type |
616
|
|
|
assert text_file_copy.parent.content_id == folderb.content_id |
617
|
|
|
assert text_file_copy.owner.user_id == user.user_id |
618
|
|
|
assert text_file_copy.description == text_file.description |
619
|
|
|
assert text_file_copy.file_extension == text_file.file_extension |
620
|
|
|
assert text_file_copy.file_mimetype == text_file.file_mimetype |
621
|
|
|
assert text_file_copy.revision_type == ActionDescription.COPY |
622
|
|
|
assert len(text_file_copy.revisions) == len(text_file.revisions) + 1 |
623
|
|
|
|
624
|
|
View Code Duplication |
def test_unit_copy_file__same_label_different_parent_ok(self): |
|
|
|
|
625
|
|
|
uapi = UserApi( |
626
|
|
|
session=self.session, |
627
|
|
|
config=self.app_config, |
628
|
|
|
current_user=None, |
629
|
|
|
) |
630
|
|
|
group_api = GroupApi( |
631
|
|
|
current_user=None, |
632
|
|
|
session=self.session |
633
|
|
|
) |
634
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
635
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
636
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
637
|
|
|
|
638
|
|
|
user = uapi.create_user( |
639
|
|
|
email='user1@user', |
640
|
|
|
groups=groups, |
641
|
|
|
save_now=True |
642
|
|
|
) |
643
|
|
|
user2 = uapi.create_user( |
644
|
|
|
email='user2@user', |
645
|
|
|
groups=groups, |
646
|
|
|
save_now=True |
647
|
|
|
) |
648
|
|
|
workspace = WorkspaceApi( |
649
|
|
|
current_user=user, |
650
|
|
|
session=self.session |
651
|
|
|
).create_workspace( |
652
|
|
|
'test workspace', |
653
|
|
|
save_now=True |
654
|
|
|
) |
655
|
|
|
RoleApi(current_user=user, session=self.session).create_one( |
656
|
|
|
user2, |
657
|
|
|
workspace, |
658
|
|
|
UserRoleInWorkspace.WORKSPACE_MANAGER, |
659
|
|
|
with_notif=False |
660
|
|
|
) |
661
|
|
|
api = ContentApi( |
662
|
|
|
current_user=user, |
663
|
|
|
session=self.session, |
664
|
|
|
config=self.app_config, |
665
|
|
|
) |
666
|
|
|
foldera = api.create( |
667
|
|
|
ContentType.Folder, |
668
|
|
|
workspace, |
669
|
|
|
None, |
670
|
|
|
'folder a', |
671
|
|
|
True |
672
|
|
|
) |
673
|
|
|
with self.session.no_autoflush: |
674
|
|
|
text_file = api.create( |
675
|
|
|
content_type=ContentType.File, |
676
|
|
|
workspace=workspace, |
677
|
|
|
parent=foldera, |
678
|
|
|
label='test_file', |
679
|
|
|
do_save=False, |
680
|
|
|
) |
681
|
|
|
api.update_file_data( |
682
|
|
|
text_file, |
683
|
|
|
'test_file', |
684
|
|
|
'text/plain', |
685
|
|
|
b'test_content' |
686
|
|
|
) |
687
|
|
|
|
688
|
|
|
api.save(text_file, ActionDescription.CREATION) |
689
|
|
|
api2 = ContentApi( |
690
|
|
|
current_user=user2, |
691
|
|
|
session=self.session, |
692
|
|
|
config=self.app_config, |
693
|
|
|
) |
694
|
|
|
workspace2 = WorkspaceApi( |
695
|
|
|
current_user=user2, |
696
|
|
|
session=self.session |
697
|
|
|
).create_workspace( |
698
|
|
|
'test workspace2', |
699
|
|
|
save_now=True |
700
|
|
|
) |
701
|
|
|
folderb = api2.create( |
702
|
|
|
ContentType.Folder, |
703
|
|
|
workspace2, |
704
|
|
|
None, |
705
|
|
|
'folder b', |
706
|
|
|
True |
707
|
|
|
) |
708
|
|
|
api2.copy( |
709
|
|
|
item=text_file, |
710
|
|
|
new_parent=folderb, |
711
|
|
|
) |
712
|
|
|
|
713
|
|
|
transaction.commit() |
714
|
|
|
text_file_copy = api2.get_one_by_label_and_parent( |
715
|
|
|
'test_file', |
716
|
|
|
folderb, |
717
|
|
|
) |
718
|
|
|
|
719
|
|
|
assert text_file != text_file_copy |
720
|
|
|
assert text_file_copy.content_id != text_file.content_id |
721
|
|
|
assert text_file_copy.workspace_id == workspace2.workspace_id |
722
|
|
|
assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8 |
|
|
|
|
723
|
|
|
assert text_file_copy.depot_file.path != text_file.depot_file.path |
|
|
|
|
724
|
|
|
assert text_file_copy.label == text_file.label |
725
|
|
|
assert text_file_copy.type == text_file.type |
726
|
|
|
assert text_file_copy.parent.content_id == folderb.content_id |
727
|
|
|
assert text_file_copy.owner.user_id == user.user_id |
728
|
|
|
assert text_file_copy.description == text_file.description |
729
|
|
|
assert text_file_copy.file_extension == text_file.file_extension |
730
|
|
|
assert text_file_copy.file_mimetype == text_file.file_mimetype |
731
|
|
|
assert text_file_copy.revision_type == ActionDescription.COPY |
732
|
|
|
assert len(text_file_copy.revisions) == len(text_file.revisions) + 1 |
733
|
|
|
|
734
|
|
|
def test_unit_copy_file_different_label_same_parent_ok(self): |
|
|
|
|
735
|
|
|
uapi = UserApi( |
736
|
|
|
session=self.session, |
737
|
|
|
config=self.app_config, |
738
|
|
|
current_user=None, |
739
|
|
|
) |
740
|
|
|
group_api = GroupApi( |
741
|
|
|
current_user=None, |
742
|
|
|
session=self.session |
743
|
|
|
) |
744
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
745
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
746
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
747
|
|
|
|
748
|
|
|
user = uapi.create_user( |
749
|
|
|
email='user1@user', |
750
|
|
|
groups=groups, |
751
|
|
|
save_now=True, |
752
|
|
|
) |
753
|
|
|
user2 = uapi.create_user( |
754
|
|
|
email='user2@user', |
755
|
|
|
groups=groups, |
756
|
|
|
save_now=True |
757
|
|
|
) |
758
|
|
|
workspace = WorkspaceApi( |
759
|
|
|
current_user=user, |
760
|
|
|
session=self.session |
761
|
|
|
).create_workspace( |
762
|
|
|
'test workspace', |
763
|
|
|
save_now=True |
764
|
|
|
) |
765
|
|
|
RoleApi(current_user=user, session=self.session).create_one( |
766
|
|
|
user2, workspace, |
767
|
|
|
UserRoleInWorkspace.WORKSPACE_MANAGER, |
768
|
|
|
with_notif=False |
769
|
|
|
) |
770
|
|
|
api = ContentApi( |
771
|
|
|
current_user=user, |
772
|
|
|
session=self.session, |
773
|
|
|
config=self.app_config, |
774
|
|
|
) |
775
|
|
|
foldera = api.create( |
776
|
|
|
ContentType.Folder, |
777
|
|
|
workspace, |
778
|
|
|
None, |
779
|
|
|
'folder a', |
780
|
|
|
True |
781
|
|
|
) |
782
|
|
|
with self.session.no_autoflush: |
783
|
|
|
text_file = api.create( |
784
|
|
|
content_type=ContentType.File, |
785
|
|
|
workspace=workspace, |
786
|
|
|
parent=foldera, |
787
|
|
|
label='test_file', |
788
|
|
|
do_save=False, |
789
|
|
|
) |
790
|
|
|
api.update_file_data( |
791
|
|
|
text_file, |
792
|
|
|
'test_file', |
793
|
|
|
'text/plain', |
794
|
|
|
b'test_content' |
795
|
|
|
) |
796
|
|
|
|
797
|
|
|
api.save( |
798
|
|
|
text_file, |
799
|
|
|
ActionDescription.CREATION |
800
|
|
|
) |
801
|
|
|
api2 = ContentApi( |
802
|
|
|
current_user=user2, |
803
|
|
|
session=self.session, |
804
|
|
|
config=self.app_config, |
805
|
|
|
) |
806
|
|
|
|
807
|
|
|
api2.copy( |
808
|
|
|
item=text_file, |
809
|
|
|
new_label='test_file_copy' |
810
|
|
|
) |
811
|
|
|
|
812
|
|
|
transaction.commit() |
813
|
|
|
text_file_copy = api2.get_one_by_label_and_parent( |
814
|
|
|
'test_file_copy', |
815
|
|
|
foldera, |
816
|
|
|
) |
817
|
|
|
|
818
|
|
|
assert text_file != text_file_copy |
819
|
|
|
assert text_file_copy.content_id != text_file.content_id |
820
|
|
|
assert text_file_copy.workspace_id == workspace.workspace_id |
821
|
|
|
assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8 |
|
|
|
|
822
|
|
|
assert text_file_copy.depot_file.path != text_file.depot_file.path |
|
|
|
|
823
|
|
|
assert text_file_copy.label == 'test_file_copy' |
824
|
|
|
assert text_file_copy.type == text_file.type |
825
|
|
|
assert text_file_copy.parent.content_id == foldera.content_id |
826
|
|
|
assert text_file_copy.owner.user_id == user.user_id |
827
|
|
|
assert text_file_copy.description == text_file.description |
828
|
|
|
assert text_file_copy.file_extension == text_file.file_extension |
829
|
|
|
assert text_file_copy.file_mimetype == text_file.file_mimetype |
830
|
|
|
assert text_file_copy.revision_type == ActionDescription.COPY |
831
|
|
|
assert len(text_file_copy.revisions) == len(text_file.revisions) + 1 |
832
|
|
|
|
833
|
|
|
def test_mark_read__workspace(self): |
|
|
|
|
834
|
|
|
uapi = UserApi( |
835
|
|
|
session=self.session, |
836
|
|
|
config=self.app_config, |
837
|
|
|
current_user=None, |
838
|
|
|
) |
839
|
|
|
group_api = GroupApi( |
840
|
|
|
current_user=None, |
841
|
|
|
session=self.session |
842
|
|
|
) |
843
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
844
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
845
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
846
|
|
|
|
847
|
|
|
user_a = uapi.create_user(email='this.is@user', |
848
|
|
|
groups=groups, save_now=True) |
849
|
|
|
user_b = uapi.create_user(email='[email protected]', |
850
|
|
|
groups=groups, save_now=True) |
851
|
|
|
|
852
|
|
|
wapi = WorkspaceApi( |
853
|
|
|
current_user=user_a, |
854
|
|
|
session=self.session, |
855
|
|
|
) |
856
|
|
|
workspace1 = wapi.create_workspace( |
857
|
|
|
'test workspace n°1', |
858
|
|
|
save_now=True) |
859
|
|
|
workspace2 = wapi.create_workspace( |
860
|
|
|
'test workspace n°2', |
861
|
|
|
save_now=True) |
862
|
|
|
|
863
|
|
|
role_api1 = RoleApi( |
864
|
|
|
current_user=user_a, |
865
|
|
|
session=self.session, |
866
|
|
|
) |
867
|
|
|
role_api1.create_one( |
868
|
|
|
user_b, |
869
|
|
|
workspace1, |
870
|
|
|
UserRoleInWorkspace.READER, |
871
|
|
|
False |
872
|
|
|
) |
873
|
|
|
|
874
|
|
|
role_api2 = RoleApi( |
875
|
|
|
current_user=user_b, |
876
|
|
|
session=self.session, |
877
|
|
|
) |
878
|
|
|
role_api2.create_one(user_b, workspace2, UserRoleInWorkspace.READER, |
879
|
|
|
False) |
880
|
|
|
|
881
|
|
|
cont_api_a = ContentApi( |
882
|
|
|
current_user=user_a, |
883
|
|
|
session=self.session, |
884
|
|
|
config=self.app_config, |
885
|
|
|
) |
886
|
|
|
cont_api_b = ContentApi( |
887
|
|
|
current_user=user_b, |
888
|
|
|
session=self.session, |
889
|
|
|
config=self.app_config, |
890
|
|
|
) |
891
|
|
|
|
892
|
|
|
# Creates page_1 & page_2 in workspace 1 |
893
|
|
|
# and page_3 & page_4 in workspace 2 |
894
|
|
|
page_1 = cont_api_a.create(ContentType.Page, workspace1, None, |
895
|
|
|
'this is a page', do_save=True) |
896
|
|
|
page_2 = cont_api_a.create(ContentType.Page, workspace1, None, |
897
|
|
|
'this is page1', do_save=True) |
898
|
|
|
page_3 = cont_api_a.create(ContentType.Thread, workspace2, None, |
899
|
|
|
'this is page2', do_save=True) |
900
|
|
|
page_4 = cont_api_a.create(ContentType.File, workspace2, None, |
901
|
|
|
'this is page3', do_save=True) |
902
|
|
|
|
903
|
|
|
for rev in page_1.revisions: |
904
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
905
|
|
|
for rev in page_2.revisions: |
906
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
907
|
|
|
for rev in page_3.revisions: |
908
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
909
|
|
|
for rev in page_4.revisions: |
910
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
911
|
|
|
|
912
|
|
|
# Set as read the workspace n°1 |
913
|
|
|
cont_api_b.mark_read__workspace(workspace=workspace1) |
914
|
|
|
|
915
|
|
|
for rev in page_1.revisions: |
916
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
917
|
|
|
for rev in page_2.revisions: |
918
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
919
|
|
|
for rev in page_3.revisions: |
920
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
921
|
|
|
for rev in page_4.revisions: |
922
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
923
|
|
|
|
924
|
|
|
# Set as read the workspace n°2 |
925
|
|
|
cont_api_b.mark_read__workspace(workspace=workspace2) |
926
|
|
|
|
927
|
|
|
for rev in page_1.revisions: |
928
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
929
|
|
|
for rev in page_2.revisions: |
930
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
931
|
|
|
for rev in page_3.revisions: |
932
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
933
|
|
|
for rev in page_4.revisions: |
934
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
935
|
|
|
|
936
|
|
|
def test_mark_read(self): |
|
|
|
|
937
|
|
|
uapi = UserApi( |
938
|
|
|
session=self.session, |
939
|
|
|
config=self.app_config, |
940
|
|
|
current_user=None, |
941
|
|
|
) |
942
|
|
|
group_api = GroupApi( |
943
|
|
|
current_user=None, |
944
|
|
|
session=self.session |
945
|
|
|
) |
946
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
947
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
948
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
949
|
|
|
|
950
|
|
|
user_a = uapi.create_user( |
951
|
|
|
email='this.is@user', |
952
|
|
|
groups=groups, |
953
|
|
|
save_now=True |
954
|
|
|
) |
955
|
|
|
user_b = uapi.create_user( |
956
|
|
|
email='[email protected]', |
957
|
|
|
groups=groups, |
958
|
|
|
save_now=True |
959
|
|
|
) |
960
|
|
|
|
961
|
|
|
wapi = WorkspaceApi(current_user=user_a, session=self.session) |
962
|
|
|
workspace_api = WorkspaceApi( |
|
|
|
|
963
|
|
|
current_user=user_a, |
964
|
|
|
session=self.session |
965
|
|
|
) |
966
|
|
|
workspace = wapi.create_workspace( |
967
|
|
|
'test workspace', |
968
|
|
|
save_now=True) |
969
|
|
|
|
970
|
|
|
role_api = RoleApi( |
971
|
|
|
current_user=user_a, |
972
|
|
|
session=self.session, |
973
|
|
|
) |
974
|
|
|
role_api.create_one( |
975
|
|
|
user_b, |
976
|
|
|
workspace, |
977
|
|
|
UserRoleInWorkspace.READER, |
978
|
|
|
False |
979
|
|
|
) |
980
|
|
|
cont_api_a = ContentApi( |
981
|
|
|
current_user=user_a, |
982
|
|
|
session=self.session, |
983
|
|
|
config=self.app_config, |
984
|
|
|
) |
985
|
|
|
cont_api_b = ContentApi( |
986
|
|
|
current_user=user_b, |
987
|
|
|
session=self.session, |
988
|
|
|
config=self.app_config, |
989
|
|
|
) |
990
|
|
|
|
991
|
|
|
page_1 = cont_api_a.create(ContentType.Page, workspace, None, |
992
|
|
|
'this is a page', do_save=True) |
993
|
|
|
|
994
|
|
|
for rev in page_1.revisions: |
995
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
996
|
|
|
|
997
|
|
|
cont_api_b.mark_read(page_1) |
998
|
|
|
|
999
|
|
|
for rev in page_1.revisions: |
1000
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1001
|
|
|
|
1002
|
|
|
def test_mark_read__all(self): |
|
|
|
|
1003
|
|
|
uapi = UserApi( |
1004
|
|
|
session=self.session, |
1005
|
|
|
config=self.app_config, |
1006
|
|
|
current_user=None, |
1007
|
|
|
) |
1008
|
|
|
group_api = GroupApi(current_user=None, session=self.session) |
1009
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1010
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1011
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1012
|
|
|
|
1013
|
|
|
user_a = uapi.create_user( |
1014
|
|
|
email='this.is@user', |
1015
|
|
|
groups=groups, |
1016
|
|
|
save_now=True |
1017
|
|
|
) |
1018
|
|
|
user_b = uapi.create_user( |
1019
|
|
|
email='[email protected]', |
1020
|
|
|
groups=groups, |
1021
|
|
|
save_now=True |
1022
|
|
|
) |
1023
|
|
|
|
1024
|
|
|
wapi = WorkspaceApi( |
1025
|
|
|
current_user=user_a, |
1026
|
|
|
session=self.session, |
1027
|
|
|
) |
1028
|
|
|
workspace = wapi.create_workspace( |
1029
|
|
|
'test workspace', |
1030
|
|
|
save_now=True) |
1031
|
|
|
|
1032
|
|
|
role_api = RoleApi( |
1033
|
|
|
current_user=user_a, |
1034
|
|
|
session=self.session, |
1035
|
|
|
) |
1036
|
|
|
role_api.create_one( |
1037
|
|
|
user_b, |
1038
|
|
|
workspace, |
1039
|
|
|
UserRoleInWorkspace.READER, |
1040
|
|
|
False |
1041
|
|
|
) |
1042
|
|
|
cont_api_a = ContentApi( |
1043
|
|
|
current_user=user_a, |
1044
|
|
|
session=self.session, |
1045
|
|
|
config=self.app_config, |
1046
|
|
|
) |
1047
|
|
|
cont_api_b = ContentApi( |
1048
|
|
|
current_user=user_b, |
1049
|
|
|
session=self.session, |
1050
|
|
|
config=self.app_config, |
1051
|
|
|
) |
1052
|
|
|
|
1053
|
|
|
page_2 = cont_api_a.create( |
1054
|
|
|
ContentType.Page, |
1055
|
|
|
workspace, |
1056
|
|
|
None, |
1057
|
|
|
'this is page1', |
1058
|
|
|
do_save=True |
1059
|
|
|
) |
1060
|
|
|
page_3 = cont_api_a.create( |
1061
|
|
|
ContentType.Thread, |
1062
|
|
|
workspace, |
1063
|
|
|
None, |
1064
|
|
|
'this is page2', |
1065
|
|
|
do_save=True |
1066
|
|
|
) |
1067
|
|
|
page_4 = cont_api_a.create( |
1068
|
|
|
ContentType.File, |
1069
|
|
|
workspace, |
1070
|
|
|
None, |
1071
|
|
|
'this is page3', |
1072
|
|
|
do_save=True |
1073
|
|
|
) |
1074
|
|
|
|
1075
|
|
|
for rev in page_2.revisions: |
1076
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1077
|
|
|
for rev in page_3.revisions: |
1078
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1079
|
|
|
for rev in page_4.revisions: |
1080
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1081
|
|
|
|
1082
|
|
|
self.session.refresh(page_2) |
1083
|
|
|
self.session.refresh(page_3) |
1084
|
|
|
self.session.refresh(page_4) |
1085
|
|
|
|
1086
|
|
|
cont_api_b.mark_read__all() |
1087
|
|
|
|
1088
|
|
|
for rev in page_2.revisions: |
1089
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1090
|
|
|
for rev in page_3.revisions: |
1091
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1092
|
|
|
for rev in page_4.revisions: |
1093
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1094
|
|
|
|
1095
|
|
|
def test_update(self): |
|
|
|
|
1096
|
|
|
uapi = UserApi( |
1097
|
|
|
session=self.session, |
1098
|
|
|
config=self.app_config, |
1099
|
|
|
current_user=None, |
1100
|
|
|
) |
1101
|
|
|
group_api = GroupApi(current_user=None, session=self.session) |
1102
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1103
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1104
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1105
|
|
|
|
1106
|
|
|
user1 = uapi.create_user( |
1107
|
|
|
email='this.is@user', |
1108
|
|
|
groups=groups, |
1109
|
|
|
save_now=True |
1110
|
|
|
) |
1111
|
|
|
|
1112
|
|
|
workspace_api = WorkspaceApi(current_user=user1, session=self.session) |
1113
|
|
|
workspace = workspace_api.create_workspace( |
1114
|
|
|
'test workspace', |
1115
|
|
|
save_now=True |
1116
|
|
|
) |
1117
|
|
|
|
|
|
|
|
1118
|
|
|
wid = workspace.workspace_id |
1119
|
|
|
|
1120
|
|
|
user2 = uapi.create_user() |
1121
|
|
|
user2.email = '[email protected]' |
1122
|
|
|
uapi.save(user2) |
1123
|
|
|
|
1124
|
|
|
RoleApi( |
1125
|
|
|
current_user=user1, |
1126
|
|
|
session=self.session |
1127
|
|
|
).create_one( |
1128
|
|
|
user2, |
1129
|
|
|
workspace, |
1130
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
1131
|
|
|
with_notif=False, |
1132
|
|
|
flush=True |
1133
|
|
|
) |
1134
|
|
|
|
1135
|
|
|
# Test starts here |
1136
|
|
|
|
1137
|
|
|
api = ContentApi( |
1138
|
|
|
current_user=user1, |
1139
|
|
|
session=self.session, |
1140
|
|
|
config=self.app_config, |
1141
|
|
|
) |
1142
|
|
|
|
1143
|
|
|
p = api.create(ContentType.Page, workspace, None, |
|
|
|
|
1144
|
|
|
'this_is_a_page', True) |
1145
|
|
|
|
1146
|
|
|
u1id = user1.user_id |
1147
|
|
|
u2id = user2.user_id |
1148
|
|
|
pcid = p.content_id |
1149
|
|
|
poid = p.owner_id |
1150
|
|
|
|
1151
|
|
|
transaction.commit() |
1152
|
|
|
|
1153
|
|
|
# Refresh instances after commit |
1154
|
|
|
user1 = uapi.get_one(u1id) |
1155
|
|
|
workspace = WorkspaceApi( |
1156
|
|
|
current_user=user1, |
1157
|
|
|
session=self.session |
1158
|
|
|
).get_one(wid) |
1159
|
|
|
api = ContentApi( |
1160
|
|
|
current_user=user1, |
1161
|
|
|
session=self.session, |
1162
|
|
|
config=self.app_config, |
1163
|
|
|
) |
1164
|
|
|
|
1165
|
|
|
content = api.get_one(pcid, ContentType.Any, workspace) |
1166
|
|
|
eq_(u1id, content.owner_id) |
1167
|
|
|
eq_(poid, content.owner_id) |
1168
|
|
|
|
1169
|
|
|
u2 = UserApi( |
|
|
|
|
1170
|
|
|
session=self.session, |
1171
|
|
|
config=self.app_config, |
1172
|
|
|
current_user=None, |
1173
|
|
|
).get_one(u2id) |
1174
|
|
|
api2 = ContentApi( |
1175
|
|
|
current_user=u2, |
1176
|
|
|
session=self.session, |
1177
|
|
|
config=self.app_config, |
1178
|
|
|
) |
1179
|
|
|
content2 = api2.get_one(pcid, ContentType.Any, workspace) |
1180
|
|
|
with new_revision( |
1181
|
|
|
session=self.session, |
|
|
|
|
1182
|
|
|
tm=transaction.manager, |
|
|
|
|
1183
|
|
|
content=content2, |
|
|
|
|
1184
|
|
|
): |
1185
|
|
|
api2.update_content( |
1186
|
|
|
content2, |
1187
|
|
|
'this is an updated page', |
1188
|
|
|
'new content' |
1189
|
|
|
) |
1190
|
|
|
api2.save(content2) |
1191
|
|
|
transaction.commit() |
1192
|
|
|
|
1193
|
|
|
# Refresh instances after commit |
1194
|
|
|
user1 = uapi.get_one(u1id) |
1195
|
|
|
workspace = WorkspaceApi( |
1196
|
|
|
current_user=user1, |
1197
|
|
|
session=self.session, |
1198
|
|
|
).get_one(wid) |
1199
|
|
|
api = ContentApi( |
1200
|
|
|
current_user=user1, |
1201
|
|
|
session=self.session, |
1202
|
|
|
config=self.app_config, |
1203
|
|
|
) |
1204
|
|
|
|
1205
|
|
|
updated = api.get_one(pcid, ContentType.Any, workspace) |
1206
|
|
|
eq_(u2id, updated.owner_id, |
1207
|
|
|
'the owner id should be {} (found {})'.format(u2id, |
1208
|
|
|
updated.owner_id)) |
1209
|
|
|
eq_('this is an updated page', updated.label) |
1210
|
|
|
eq_('new content', updated.description) |
1211
|
|
|
eq_(ActionDescription.EDITION, updated.revision_type) |
1212
|
|
|
|
1213
|
|
|
@raises(SameValueError) |
1214
|
|
|
def test_update_no_change(self): |
|
|
|
|
1215
|
|
|
uapi = UserApi( |
1216
|
|
|
session=self.session, |
1217
|
|
|
config=self.app_config, |
1218
|
|
|
current_user=None, |
1219
|
|
|
) |
1220
|
|
|
group_api = GroupApi( |
1221
|
|
|
current_user=None, |
1222
|
|
|
session=self.session |
1223
|
|
|
) |
1224
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1225
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1226
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1227
|
|
|
|
1228
|
|
|
user1 = uapi.create_user( |
1229
|
|
|
email='this.is@user', |
1230
|
|
|
groups=groups, |
1231
|
|
|
save_now=True, |
1232
|
|
|
) |
1233
|
|
|
|
1234
|
|
|
workspace = WorkspaceApi( |
1235
|
|
|
current_user=user1, |
1236
|
|
|
session=self.session, |
1237
|
|
|
).create_workspace( |
1238
|
|
|
'test workspace', |
1239
|
|
|
save_now=True |
1240
|
|
|
) |
1241
|
|
|
|
1242
|
|
|
user2 = uapi.create_user() |
1243
|
|
|
user2.email = '[email protected]' |
1244
|
|
|
uapi.save(user2) |
1245
|
|
|
|
1246
|
|
|
RoleApi( |
1247
|
|
|
current_user=user1, |
1248
|
|
|
session=self.session |
1249
|
|
|
).create_one( |
1250
|
|
|
user2, |
1251
|
|
|
workspace, |
1252
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
1253
|
|
|
with_notif=False, |
1254
|
|
|
flush=True |
1255
|
|
|
) |
1256
|
|
|
api = ContentApi( |
1257
|
|
|
current_user=user1, |
1258
|
|
|
session=self.session, |
1259
|
|
|
config=self.app_config, |
1260
|
|
|
) |
1261
|
|
|
with self.session.no_autoflush: |
1262
|
|
|
page = api.create( |
1263
|
|
|
content_type=ContentType.Page, |
1264
|
|
|
workspace=workspace, |
1265
|
|
|
label="same_content", |
1266
|
|
|
do_save=False |
1267
|
|
|
) |
1268
|
|
|
page.description = "Same_content_here" |
1269
|
|
|
api.save(page, ActionDescription.CREATION, do_notify=True) |
1270
|
|
|
transaction.commit() |
1271
|
|
|
|
1272
|
|
|
api2 = ContentApi( |
1273
|
|
|
current_user=user2, |
1274
|
|
|
session=self.session, |
1275
|
|
|
config=self.app_config, |
1276
|
|
|
) |
1277
|
|
|
content2 = api2.get_one(page.content_id, ContentType.Any, workspace) |
1278
|
|
|
with new_revision( |
1279
|
|
|
session=self.session, |
|
|
|
|
1280
|
|
|
tm=transaction.manager, |
|
|
|
|
1281
|
|
|
content=content2, |
|
|
|
|
1282
|
|
|
): |
1283
|
|
|
api2.update_content( |
1284
|
|
|
item=content2, |
1285
|
|
|
new_label='same_content', |
1286
|
|
|
new_content='Same_content_here' |
1287
|
|
|
) |
1288
|
|
|
api2.save(content2) |
1289
|
|
|
transaction.commit() |
1290
|
|
|
|
1291
|
|
|
def test_update_file_data(self): |
|
|
|
|
1292
|
|
|
uapi = UserApi( |
1293
|
|
|
session=self.session, |
1294
|
|
|
config=self.app_config, |
1295
|
|
|
current_user=None, |
1296
|
|
|
) |
1297
|
|
|
group_api = GroupApi( |
1298
|
|
|
current_user=None, |
1299
|
|
|
session=self.session |
1300
|
|
|
) |
1301
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1302
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1303
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1304
|
|
|
|
1305
|
|
|
user1 = uapi.create_user( |
1306
|
|
|
email='this.is@user', |
1307
|
|
|
groups=groups, |
1308
|
|
|
save_now=True |
1309
|
|
|
) |
1310
|
|
|
|
1311
|
|
|
workspace_api = WorkspaceApi(current_user=user1, session=self.session) |
1312
|
|
|
workspace = workspace_api.create_workspace( |
1313
|
|
|
'test workspace', |
1314
|
|
|
save_now=True |
1315
|
|
|
) |
1316
|
|
|
wid = workspace.workspace_id |
1317
|
|
|
|
1318
|
|
|
user2 = uapi.create_user() |
1319
|
|
|
user2.email = '[email protected]' |
1320
|
|
|
uapi.save(user2) |
1321
|
|
|
|
1322
|
|
|
RoleApi( |
1323
|
|
|
current_user=user1, |
1324
|
|
|
session=self.session, |
1325
|
|
|
).create_one( |
1326
|
|
|
user2, |
1327
|
|
|
workspace, |
1328
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
1329
|
|
|
with_notif=True, |
1330
|
|
|
flush=True |
1331
|
|
|
) |
1332
|
|
|
|
1333
|
|
|
# Test starts here |
1334
|
|
|
api = ContentApi( |
1335
|
|
|
current_user=user1, |
1336
|
|
|
session=self.session, |
1337
|
|
|
config=self.app_config, |
1338
|
|
|
) |
1339
|
|
|
p = api.create(ContentType.File, workspace, None, |
|
|
|
|
1340
|
|
|
'this_is_a_page', True) |
1341
|
|
|
|
1342
|
|
|
u1id = user1.user_id |
1343
|
|
|
u2id = user2.user_id |
1344
|
|
|
pcid = p.content_id |
1345
|
|
|
poid = p.owner_id |
1346
|
|
|
|
1347
|
|
|
api.save(p) |
1348
|
|
|
transaction.commit() |
1349
|
|
|
|
1350
|
|
|
# Refresh instances after commit |
1351
|
|
|
user1 = uapi.get_one(u1id) |
1352
|
|
|
workspace_api2 = WorkspaceApi(current_user=user1, session=self.session) |
1353
|
|
|
workspace = workspace_api2.get_one(wid) |
1354
|
|
|
api = ContentApi( |
1355
|
|
|
current_user=user1, |
1356
|
|
|
session=self.session, |
1357
|
|
|
config=self.app_config, |
1358
|
|
|
) |
1359
|
|
|
|
1360
|
|
|
content = api.get_one(pcid, ContentType.Any, workspace) |
1361
|
|
|
eq_(u1id, content.owner_id) |
1362
|
|
|
eq_(poid, content.owner_id) |
1363
|
|
|
|
1364
|
|
|
u2 = UserApi( |
|
|
|
|
1365
|
|
|
current_user=None, |
1366
|
|
|
session=self.session, |
1367
|
|
|
config=self.app_config, |
1368
|
|
|
).get_one(u2id) |
1369
|
|
|
api2 = ContentApi( |
1370
|
|
|
current_user=u2, |
1371
|
|
|
session=self.session, |
1372
|
|
|
config=self.app_config, |
1373
|
|
|
) |
1374
|
|
|
content2 = api2.get_one(pcid, ContentType.Any, workspace) |
1375
|
|
|
with new_revision( |
1376
|
|
|
session=self.session, |
1377
|
|
|
tm=transaction.manager, |
1378
|
|
|
content=content2, |
1379
|
|
|
): |
1380
|
|
|
api2.update_file_data(content2, 'index.html', 'text/html', |
1381
|
|
|
b'<html>hello world</html>') |
1382
|
|
|
api2.save(content2) |
1383
|
|
|
transaction.commit() |
1384
|
|
|
|
1385
|
|
|
# Refresh instances after commit |
1386
|
|
|
user1 = uapi.get_one(u1id) |
1387
|
|
|
workspace = WorkspaceApi( |
1388
|
|
|
current_user=user1, |
1389
|
|
|
session=self.session, |
1390
|
|
|
).get_one(wid) |
1391
|
|
|
|
1392
|
|
|
updated = api.get_one(pcid, ContentType.Any, workspace) |
1393
|
|
|
eq_(u2id, updated.owner_id, |
1394
|
|
|
'the owner id should be {} (found {})'.format(u2id, |
1395
|
|
|
updated.owner_id)) |
1396
|
|
|
eq_('this_is_a_page.html', updated.file_name) |
1397
|
|
|
eq_('text/html', updated.file_mimetype) |
1398
|
|
|
eq_(b'<html>hello world</html>', updated.depot_file.file.read()) |
1399
|
|
|
eq_(ActionDescription.REVISION, updated.revision_type) |
1400
|
|
|
|
1401
|
|
|
@raises(SameValueError) |
1402
|
|
|
def test_update_no_change(self): |
|
|
|
|
1403
|
|
|
uapi = UserApi( |
1404
|
|
|
session=self.session, |
1405
|
|
|
config=self.app_config, |
1406
|
|
|
current_user=None, |
1407
|
|
|
) |
1408
|
|
|
group_api = GroupApi( |
1409
|
|
|
current_user=None, |
1410
|
|
|
session=self.session, |
1411
|
|
|
) |
1412
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1413
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1414
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1415
|
|
|
|
1416
|
|
|
user1 = uapi.create_user( |
1417
|
|
|
email='this.is@user', |
1418
|
|
|
groups=groups, |
1419
|
|
|
save_now=True, |
1420
|
|
|
) |
1421
|
|
|
|
1422
|
|
|
workspace_api = WorkspaceApi(current_user=user1, session=self.session) |
1423
|
|
|
workspace = workspace_api.create_workspace( |
1424
|
|
|
'test workspace', |
1425
|
|
|
save_now=True |
1426
|
|
|
) |
1427
|
|
|
|
1428
|
|
|
user2 = uapi.create_user() |
1429
|
|
|
user2.email = '[email protected]' |
1430
|
|
|
uapi.save(user2) |
1431
|
|
|
|
1432
|
|
|
RoleApi( |
1433
|
|
|
current_user=user1, |
1434
|
|
|
session=self.session, |
1435
|
|
|
).create_one( |
1436
|
|
|
user2, |
1437
|
|
|
workspace, |
1438
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
1439
|
|
|
with_notif=False, |
1440
|
|
|
flush=True |
1441
|
|
|
) |
1442
|
|
|
api = ContentApi( |
1443
|
|
|
current_user=user1, |
1444
|
|
|
session=self.session, |
1445
|
|
|
config=self.app_config, |
1446
|
|
|
) |
1447
|
|
|
with self.session.no_autoflush: |
1448
|
|
|
page = api.create( |
1449
|
|
|
content_type=ContentType.Page, |
1450
|
|
|
workspace=workspace, |
1451
|
|
|
label="same_content", |
1452
|
|
|
do_save=False |
1453
|
|
|
) |
1454
|
|
|
api.update_file_data( |
1455
|
|
|
page, |
1456
|
|
|
'index.html', |
1457
|
|
|
'text/html', |
1458
|
|
|
b'<html>Same Content Here</html>' |
1459
|
|
|
) |
1460
|
|
|
api.save(page, ActionDescription.CREATION, do_notify=True) |
1461
|
|
|
transaction.commit() |
1462
|
|
|
|
1463
|
|
|
api2 = ContentApi( |
1464
|
|
|
current_user=user2, |
1465
|
|
|
session=self.session, |
1466
|
|
|
config=self.app_config, |
1467
|
|
|
) |
1468
|
|
|
content2 = api2.get_one(page.content_id, ContentType.Any, workspace) |
1469
|
|
|
with new_revision( |
1470
|
|
|
session=self.session, |
1471
|
|
|
tm=transaction.manager, |
1472
|
|
|
content=content2, |
1473
|
|
|
): |
1474
|
|
|
api2.update_file_data( |
1475
|
|
|
page, |
1476
|
|
|
'index.html', |
1477
|
|
|
'text/html', |
1478
|
|
|
b'<html>Same Content Here</html>' |
1479
|
|
|
) |
1480
|
|
|
api2.save(content2) |
1481
|
|
|
transaction.commit() |
1482
|
|
|
|
1483
|
|
View Code Duplication |
def test_archive_unarchive(self): |
|
|
|
|
1484
|
|
|
uapi = UserApi( |
1485
|
|
|
session=self.session, |
1486
|
|
|
config=self.app_config, |
1487
|
|
|
current_user=None, |
1488
|
|
|
) |
1489
|
|
|
group_api = GroupApi(current_user=None, session=self.session) |
1490
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1491
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1492
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1493
|
|
|
|
1494
|
|
|
user1 = uapi.create_user( |
1495
|
|
|
email='this.is@user', |
1496
|
|
|
groups=groups, |
1497
|
|
|
save_now=True |
1498
|
|
|
) |
1499
|
|
|
u1id = user1.user_id |
1500
|
|
|
|
1501
|
|
|
workspace_api = WorkspaceApi(current_user=user1, session=self.session) |
1502
|
|
|
workspace = workspace_api.create_workspace( |
1503
|
|
|
'test workspace', |
1504
|
|
|
save_now=True |
1505
|
|
|
) |
1506
|
|
|
wid = workspace.workspace_id |
1507
|
|
|
|
1508
|
|
|
user2 = uapi.create_user() |
1509
|
|
|
user2.email = '[email protected]' |
1510
|
|
|
uapi.save(user2) |
1511
|
|
|
|
1512
|
|
|
RoleApi( |
1513
|
|
|
current_user=user1, |
1514
|
|
|
session=self.session |
1515
|
|
|
).create_one( |
1516
|
|
|
user2, |
1517
|
|
|
workspace, |
1518
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
1519
|
|
|
with_notif=True, |
1520
|
|
|
flush=True |
1521
|
|
|
) |
1522
|
|
|
|
1523
|
|
|
# show archived is used at the top end of the test |
1524
|
|
|
api = ContentApi( |
1525
|
|
|
current_user=user1, |
1526
|
|
|
session=self.session, |
1527
|
|
|
show_archived=True, |
1528
|
|
|
config=self.app_config, |
1529
|
|
|
) |
1530
|
|
|
p = api.create(ContentType.File, workspace, None, |
|
|
|
|
1531
|
|
|
'this_is_a_page', True) |
1532
|
|
|
|
1533
|
|
|
u1id = user1.user_id |
1534
|
|
|
u2id = user2.user_id |
1535
|
|
|
pcid = p.content_id |
1536
|
|
|
poid = p.owner_id |
1537
|
|
|
|
1538
|
|
|
transaction.commit() |
1539
|
|
|
|
1540
|
|
|
#### |
1541
|
|
|
|
1542
|
|
|
# refresh after commit |
1543
|
|
|
user1 = UserApi( |
1544
|
|
|
current_user=None, |
1545
|
|
|
config=self.app_config, |
1546
|
|
|
session=self.session |
1547
|
|
|
).get_one(u1id) |
1548
|
|
|
workspace = WorkspaceApi( |
1549
|
|
|
current_user=user1, |
1550
|
|
|
session=self.session |
1551
|
|
|
).get_one(wid) |
1552
|
|
|
|
1553
|
|
|
content = api.get_one(pcid, ContentType.Any, workspace) |
1554
|
|
|
eq_(u1id, content.owner_id) |
1555
|
|
|
eq_(poid, content.owner_id) |
1556
|
|
|
|
1557
|
|
|
u2api = UserApi( |
1558
|
|
|
session=self.session, |
1559
|
|
|
config=self.app_config, |
1560
|
|
|
current_user=None, |
1561
|
|
|
) |
1562
|
|
|
u2 = u2api.get_one(u2id) |
|
|
|
|
1563
|
|
|
api2 = ContentApi( |
1564
|
|
|
current_user=u2, |
1565
|
|
|
session=self.session, |
1566
|
|
|
config=self.app_config, |
1567
|
|
|
show_archived=True, |
1568
|
|
|
) |
1569
|
|
|
content2 = api2.get_one(pcid, ContentType.Any, workspace) |
1570
|
|
|
with new_revision( |
1571
|
|
|
session=self.session, |
|
|
|
|
1572
|
|
|
tm=transaction.manager, |
|
|
|
|
1573
|
|
|
content=content2, |
|
|
|
|
1574
|
|
|
): |
1575
|
|
|
api2.archive(content2) |
1576
|
|
|
api2.save(content2) |
1577
|
|
|
transaction.commit() |
1578
|
|
|
|
1579
|
|
|
# refresh after commit |
1580
|
|
|
user1 = UserApi( |
1581
|
|
|
current_user=None, |
1582
|
|
|
session=self.session, |
1583
|
|
|
config=self.app_config, |
1584
|
|
|
).get_one(u1id) |
1585
|
|
|
workspace = WorkspaceApi( |
1586
|
|
|
current_user=user1, |
1587
|
|
|
session=self.session, |
1588
|
|
|
).get_one(wid) |
1589
|
|
|
u2 = UserApi( |
|
|
|
|
1590
|
|
|
current_user=None, |
1591
|
|
|
session=self.session, |
1592
|
|
|
config=self.app_config, |
1593
|
|
|
).get_one(u2id) |
1594
|
|
|
api = ContentApi( |
1595
|
|
|
current_user=user1, |
1596
|
|
|
session=self.session, |
1597
|
|
|
config=self.app_config, |
1598
|
|
|
show_archived=True, |
1599
|
|
|
) |
1600
|
|
|
api2 = ContentApi( |
1601
|
|
|
current_user=u2, |
1602
|
|
|
session=self.session, |
1603
|
|
|
config=self.app_config, |
1604
|
|
|
show_archived=True, |
1605
|
|
|
) |
1606
|
|
|
|
1607
|
|
|
updated = api2.get_one(pcid, ContentType.Any, workspace) |
1608
|
|
|
eq_(u2id, updated.owner_id, |
1609
|
|
|
'the owner id should be {} (found {})'.format(u2id, |
1610
|
|
|
updated.owner_id)) |
1611
|
|
|
eq_(True, updated.is_archived) |
1612
|
|
|
eq_(ActionDescription.ARCHIVING, updated.revision_type) |
1613
|
|
|
|
1614
|
|
|
#### |
1615
|
|
|
|
1616
|
|
|
updated2 = api.get_one(pcid, ContentType.Any, workspace) |
1617
|
|
|
with new_revision( |
1618
|
|
|
session=self.session, |
1619
|
|
|
tm=transaction.manager, |
1620
|
|
|
content=updated, |
1621
|
|
|
|
1622
|
|
|
): |
1623
|
|
|
api.unarchive(updated) |
1624
|
|
|
api.save(updated2) |
1625
|
|
|
eq_(False, updated2.is_archived) |
1626
|
|
|
eq_(ActionDescription.UNARCHIVING, updated2.revision_type) |
1627
|
|
|
eq_(u1id, updated2.owner_id) |
1628
|
|
|
|
1629
|
|
View Code Duplication |
def test_delete_undelete(self): |
|
|
|
|
1630
|
|
|
uapi = UserApi( |
1631
|
|
|
session=self.session, |
1632
|
|
|
config=self.app_config, |
1633
|
|
|
current_user=None, |
1634
|
|
|
) |
1635
|
|
|
group_api = GroupApi( |
1636
|
|
|
current_user=None, |
1637
|
|
|
session=self.session |
1638
|
|
|
) |
1639
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1640
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1641
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1642
|
|
|
|
1643
|
|
|
user1 = uapi.create_user( |
1644
|
|
|
email='this.is@user', |
1645
|
|
|
groups=groups, |
1646
|
|
|
save_now=True |
1647
|
|
|
) |
1648
|
|
|
u1id = user1.user_id |
1649
|
|
|
|
1650
|
|
|
workspace_api = WorkspaceApi(current_user=user1, session=self.session) |
1651
|
|
|
workspace = workspace_api.create_workspace( |
1652
|
|
|
'test workspace', |
1653
|
|
|
save_now=True |
1654
|
|
|
) |
1655
|
|
|
wid = workspace.workspace_id |
1656
|
|
|
|
1657
|
|
|
user2 = uapi.create_user() |
1658
|
|
|
user2.email = '[email protected]' |
1659
|
|
|
uapi.save(user2) |
1660
|
|
|
|
1661
|
|
|
RoleApi( |
1662
|
|
|
current_user=user1, |
1663
|
|
|
session=self.session |
1664
|
|
|
).create_one( |
1665
|
|
|
user2, |
1666
|
|
|
workspace, |
1667
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
1668
|
|
|
with_notif=True, |
1669
|
|
|
flush=True |
1670
|
|
|
) |
1671
|
|
|
|
1672
|
|
|
# show archived is used at the top end of the test |
1673
|
|
|
api = ContentApi( |
1674
|
|
|
current_user=user1, |
1675
|
|
|
session=self.session, |
1676
|
|
|
config=self.app_config, |
1677
|
|
|
show_deleted=True, |
1678
|
|
|
) |
1679
|
|
|
p = api.create(ContentType.File, workspace, None, |
|
|
|
|
1680
|
|
|
'this_is_a_page', True) |
1681
|
|
|
|
1682
|
|
|
u1id = user1.user_id |
1683
|
|
|
u2id = user2.user_id |
1684
|
|
|
pcid = p.content_id |
1685
|
|
|
poid = p.owner_id |
1686
|
|
|
|
1687
|
|
|
transaction.commit() |
1688
|
|
|
|
1689
|
|
|
#### |
1690
|
|
|
user1 = UserApi( |
1691
|
|
|
current_user=None, |
1692
|
|
|
session=self.session, |
1693
|
|
|
config=self.app_config, |
1694
|
|
|
).get_one(u1id) |
1695
|
|
|
workspace = WorkspaceApi( |
1696
|
|
|
current_user=user1, |
1697
|
|
|
session=self.session, |
1698
|
|
|
).get_one(wid) |
1699
|
|
|
|
1700
|
|
|
content = api.get_one(pcid, ContentType.Any, workspace) |
1701
|
|
|
eq_(u1id, content.owner_id) |
1702
|
|
|
eq_(poid, content.owner_id) |
1703
|
|
|
|
1704
|
|
|
u2 = UserApi( |
|
|
|
|
1705
|
|
|
current_user=None, |
1706
|
|
|
session=self.session, |
1707
|
|
|
config=self.app_config, |
1708
|
|
|
).get_one(u2id) |
1709
|
|
|
api2 = ContentApi( |
1710
|
|
|
current_user=u2, |
1711
|
|
|
session=self.session, |
1712
|
|
|
config=self.app_config, |
1713
|
|
|
show_deleted=True, |
1714
|
|
|
) |
1715
|
|
|
content2 = api2.get_one(pcid, ContentType.Any, workspace) |
1716
|
|
|
with new_revision( |
1717
|
|
|
session=self.session, |
|
|
|
|
1718
|
|
|
tm=transaction.manager, |
|
|
|
|
1719
|
|
|
content=content2, |
|
|
|
|
1720
|
|
|
): |
1721
|
|
|
api2.delete(content2) |
1722
|
|
|
api2.save(content2) |
1723
|
|
|
transaction.commit() |
1724
|
|
|
|
1725
|
|
|
#### |
1726
|
|
|
|
1727
|
|
|
user1 = UserApi( |
1728
|
|
|
current_user=None, |
1729
|
|
|
session=self.session, |
1730
|
|
|
config=self.app_config, |
1731
|
|
|
).get_one(u1id) |
1732
|
|
|
workspace = WorkspaceApi( |
1733
|
|
|
current_user=user1, |
1734
|
|
|
session=self.session, |
1735
|
|
|
).get_one(wid) |
1736
|
|
|
# show archived is used at the top end of the test |
1737
|
|
|
api = ContentApi( |
1738
|
|
|
current_user=user1, |
1739
|
|
|
session=self.session, |
1740
|
|
|
config=self.app_config, |
1741
|
|
|
show_deleted=True, |
1742
|
|
|
) |
1743
|
|
|
u2 = UserApi( |
|
|
|
|
1744
|
|
|
current_user=None, |
1745
|
|
|
session=self.session, |
1746
|
|
|
config=self.app_config, |
1747
|
|
|
).get_one(u2id) |
1748
|
|
|
api2 = ContentApi( |
1749
|
|
|
current_user=u2, |
1750
|
|
|
session=self.session, |
1751
|
|
|
config=self.app_config, |
1752
|
|
|
show_deleted=True |
1753
|
|
|
) |
1754
|
|
|
|
1755
|
|
|
updated = api2.get_one(pcid, ContentType.Any, workspace) |
1756
|
|
|
eq_(u2id, updated.owner_id, |
1757
|
|
|
'the owner id should be {} (found {})'.format(u2id, |
1758
|
|
|
updated.owner_id)) |
1759
|
|
|
eq_(True, updated.is_deleted) |
1760
|
|
|
eq_(ActionDescription.DELETION, updated.revision_type) |
1761
|
|
|
|
1762
|
|
|
#### |
1763
|
|
|
|
1764
|
|
|
updated2 = api.get_one(pcid, ContentType.Any, workspace) |
1765
|
|
|
with new_revision( |
1766
|
|
|
tm=transaction.manager, |
1767
|
|
|
session=self.session, |
1768
|
|
|
content=updated2, |
1769
|
|
|
): |
1770
|
|
|
api.undelete(updated2) |
1771
|
|
|
api.save(updated2) |
1772
|
|
|
eq_(False, updated2.is_deleted) |
1773
|
|
|
eq_(ActionDescription.UNDELETION, updated2.revision_type) |
1774
|
|
|
eq_(u1id, updated2.owner_id) |
1775
|
|
|
|
1776
|
|
View Code Duplication |
def test_search_in_label(self): |
|
|
|
|
1777
|
|
|
# HACK - D.A. - 2015-03-09 |
1778
|
|
|
# This test is based on a bug which does NOT return results found |
1779
|
|
|
# at root of a workspace (eg a folder) |
1780
|
|
|
uapi = UserApi( |
1781
|
|
|
session=self.session, |
1782
|
|
|
config=self.app_config, |
1783
|
|
|
current_user=None, |
1784
|
|
|
) |
1785
|
|
|
group_api = GroupApi( |
1786
|
|
|
current_user=None, |
1787
|
|
|
session=self.session, |
1788
|
|
|
) |
1789
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1790
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1791
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1792
|
|
|
|
1793
|
|
|
user = uapi.create_user(email='this.is@user', |
1794
|
|
|
groups=groups, save_now=True) |
1795
|
|
|
|
1796
|
|
|
workspace = WorkspaceApi( |
1797
|
|
|
current_user=user, |
1798
|
|
|
session=self.session |
1799
|
|
|
).create_workspace( |
1800
|
|
|
'test workspace', |
1801
|
|
|
save_now=True |
1802
|
|
|
) |
1803
|
|
|
|
1804
|
|
|
api = ContentApi( |
1805
|
|
|
current_user=user, |
|
|
|
|
1806
|
|
|
session=self.session, |
1807
|
|
|
config=self.app_config, |
1808
|
|
|
|
1809
|
|
|
) |
1810
|
|
|
a = api.create(ContentType.Folder, workspace, None, |
|
|
|
|
1811
|
|
|
'this is randomized folder', True) |
1812
|
|
|
p = api.create(ContentType.Page, workspace, a, |
|
|
|
|
1813
|
|
|
'this is randomized label content', True) |
1814
|
|
|
|
1815
|
|
|
with new_revision( |
1816
|
|
|
session=self.session, |
1817
|
|
|
tm=transaction.manager, |
1818
|
|
|
content=p, |
1819
|
|
|
): |
1820
|
|
|
p.description = 'This is some amazing test' |
1821
|
|
|
|
1822
|
|
|
api.save(p) |
1823
|
|
|
original_id = p.content_id |
1824
|
|
|
|
1825
|
|
|
res = api.search(['randomized']) |
1826
|
|
|
eq_(1, len(res.all())) |
1827
|
|
|
item = res.all()[0] |
1828
|
|
|
eq_(original_id, item.content_id) |
1829
|
|
|
|
1830
|
|
View Code Duplication |
def test_search_in_description(self): |
|
|
|
|
1831
|
|
|
# HACK - D.A. - 2015-03-09 |
1832
|
|
|
# This test is based on a bug which does NOT return results found |
1833
|
|
|
# at root of a workspace (eg a folder) |
1834
|
|
|
|
1835
|
|
|
uapi = UserApi( |
1836
|
|
|
session=self.session, |
1837
|
|
|
config=self.app_config, |
1838
|
|
|
current_user=None, |
1839
|
|
|
) |
1840
|
|
|
group_api = GroupApi( |
1841
|
|
|
current_user=None, |
1842
|
|
|
session=self.session, |
1843
|
|
|
) |
1844
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1845
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1846
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1847
|
|
|
|
1848
|
|
|
user = uapi.create_user(email='this.is@user', |
1849
|
|
|
groups=groups, save_now=True) |
1850
|
|
|
|
1851
|
|
|
workspace = WorkspaceApi( |
1852
|
|
|
current_user=user, |
1853
|
|
|
session=self.session |
1854
|
|
|
).create_workspace( |
1855
|
|
|
'test workspace', |
1856
|
|
|
save_now=True, |
1857
|
|
|
) |
1858
|
|
|
|
1859
|
|
|
api = ContentApi( |
1860
|
|
|
current_user=user, |
|
|
|
|
1861
|
|
|
session=self.session, |
1862
|
|
|
config=self.app_config, |
1863
|
|
|
) |
1864
|
|
|
a = api.create(ContentType.Folder, workspace, None, |
|
|
|
|
1865
|
|
|
'this is randomized folder', True) |
1866
|
|
|
p = api.create(ContentType.Page, workspace, a, |
|
|
|
|
1867
|
|
|
'this is dummy label content', True) |
1868
|
|
|
|
1869
|
|
|
with new_revision( |
1870
|
|
|
tm=transaction.manager, |
1871
|
|
|
session=self.session, |
1872
|
|
|
content=p, |
1873
|
|
|
): |
1874
|
|
|
p.description = 'This is some amazing test' |
1875
|
|
|
|
1876
|
|
|
api.save(p) |
1877
|
|
|
original_id = p.content_id |
1878
|
|
|
|
1879
|
|
|
res = api.search(['dummy']) |
1880
|
|
|
eq_(1, len(res.all())) |
1881
|
|
|
item = res.all()[0] |
1882
|
|
|
eq_(original_id, item.content_id) |
1883
|
|
|
|
1884
|
|
|
def test_search_in_label_or_description(self): |
|
|
|
|
1885
|
|
|
# HACK - D.A. - 2015-03-09 |
1886
|
|
|
# This test is based on a bug which does NOT return results found |
1887
|
|
|
# at root of a workspace (eg a folder) |
1888
|
|
|
|
1889
|
|
|
uapi = UserApi( |
1890
|
|
|
session=self.session, |
1891
|
|
|
config=self.app_config, |
1892
|
|
|
current_user=None, |
1893
|
|
|
) |
1894
|
|
|
group_api = GroupApi(current_user=None, session=self.session) |
1895
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1896
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1897
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1898
|
|
|
|
1899
|
|
|
user = uapi.create_user(email='this.is@user', |
1900
|
|
|
groups=groups, save_now=True) |
1901
|
|
|
|
1902
|
|
|
workspace = WorkspaceApi( |
1903
|
|
|
current_user=user, |
1904
|
|
|
session=self.session |
1905
|
|
|
).create_workspace('test workspace', save_now=True) |
1906
|
|
|
|
1907
|
|
|
api = ContentApi( |
1908
|
|
|
current_user=user, |
|
|
|
|
1909
|
|
|
session=self.session, |
1910
|
|
|
config=self.app_config, |
1911
|
|
|
) |
1912
|
|
|
a = api.create(ContentType.Folder, workspace, None, |
|
|
|
|
1913
|
|
|
'this is randomized folder', True) |
1914
|
|
|
p1 = api.create(ContentType.Page, workspace, a, |
|
|
|
|
1915
|
|
|
'this is dummy label content', True) |
1916
|
|
|
p2 = api.create(ContentType.Page, workspace, a, 'Hey ! Jon !', True) |
|
|
|
|
1917
|
|
|
|
1918
|
|
|
with new_revision( |
1919
|
|
|
session=self.session, |
1920
|
|
|
tm=transaction.manager, |
1921
|
|
|
content=p1, |
1922
|
|
|
): |
1923
|
|
|
p1.description = 'This is some amazing test' |
1924
|
|
|
|
1925
|
|
|
with new_revision( |
1926
|
|
|
session=self.session, |
1927
|
|
|
tm=transaction.manager, |
1928
|
|
|
content=p2, |
1929
|
|
|
): |
1930
|
|
|
p2.description = 'What\'s up ?' |
1931
|
|
|
|
1932
|
|
|
api.save(p1) |
1933
|
|
|
api.save(p2) |
1934
|
|
|
|
1935
|
|
|
id1 = p1.content_id |
1936
|
|
|
id2 = p2.content_id |
1937
|
|
|
|
1938
|
|
|
eq_(1, self.session.query(Workspace).filter(Workspace.label == 'test workspace').count()) |
1939
|
|
|
eq_(1, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'this is randomized folder').count()) |
|
|
|
|
1940
|
|
|
eq_(2, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'this is dummy label content').count()) |
|
|
|
|
1941
|
|
|
eq_(1, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.description == 'This is some amazing test').count()) |
|
|
|
|
1942
|
|
|
eq_(2, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'Hey ! Jon !').count()) |
|
|
|
|
1943
|
|
|
eq_(1, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.description == 'What\'s up ?').count()) |
|
|
|
|
1944
|
|
|
|
1945
|
|
|
res = api.search(['dummy', 'jon']) |
1946
|
|
|
eq_(2, len(res.all())) |
1947
|
|
|
|
1948
|
|
|
eq_(True, id1 in [o.content_id for o in res.all()]) |
1949
|
|
|
eq_(True, id2 in [o.content_id for o in res.all()]) |
1950
|
|
|
|
1951
|
|
|
def test_unit__search_exclude_content_under_deleted_or_archived_parents__ok(self): # nopep8 |
|
|
|
|
1952
|
|
|
admin = self.session.query(User)\ |
1953
|
|
|
.filter(User.email == '[email protected]').one() |
1954
|
|
|
workspace = self._create_workspace_and_test( |
1955
|
|
|
'workspace_1', |
1956
|
|
|
admin |
1957
|
|
|
) |
1958
|
|
|
folder_1 = self._create_content_and_test( |
1959
|
|
|
'folder_1', |
1960
|
|
|
workspace=workspace, |
1961
|
|
|
type=ContentType.Folder |
1962
|
|
|
) |
1963
|
|
|
folder_2 = self._create_content_and_test( |
1964
|
|
|
'folder_2', |
1965
|
|
|
workspace=workspace, |
1966
|
|
|
type=ContentType.Folder |
1967
|
|
|
) |
1968
|
|
|
page_1 = self._create_content_and_test( |
1969
|
|
|
'foo', workspace=workspace, |
1970
|
|
|
type=ContentType.Page, |
1971
|
|
|
parent=folder_1 |
1972
|
|
|
) |
1973
|
|
|
page_2 = self._create_content_and_test( |
1974
|
|
|
'bar', |
1975
|
|
|
workspace=workspace, |
1976
|
|
|
type=ContentType.Page, |
1977
|
|
|
parent=folder_2 |
1978
|
|
|
) |
1979
|
|
|
|
1980
|
|
|
api = ContentApi( |
1981
|
|
|
current_user=admin, |
1982
|
|
|
session=self.session, |
1983
|
|
|
config=self.app_config, |
1984
|
|
|
) |
1985
|
|
|
|
1986
|
|
|
foo_result = api.search(['foo']).all() |
1987
|
|
|
eq_(1, len(foo_result)) |
1988
|
|
|
ok_(page_1 in foo_result) |
1989
|
|
|
|
1990
|
|
|
bar_result = api.search(['bar']).all() |
1991
|
|
|
eq_(1, len(bar_result)) |
1992
|
|
|
ok_(page_2 in bar_result) |
1993
|
|
|
|
1994
|
|
|
with new_revision( |
1995
|
|
|
session=self.session, |
1996
|
|
|
tm=transaction.manager, |
1997
|
|
|
content=folder_1, |
1998
|
|
|
): |
1999
|
|
|
api.delete(folder_1) |
2000
|
|
|
with new_revision( |
2001
|
|
|
session=self.session, |
2002
|
|
|
tm=transaction.manager, |
2003
|
|
|
content=folder_2, |
2004
|
|
|
): |
2005
|
|
|
api.archive(folder_2) |
2006
|
|
|
|
2007
|
|
|
# Actually ContentApi.search don't filter it |
2008
|
|
|
foo_result = api.search(['foo']).all() |
2009
|
|
|
eq_(1, len(foo_result)) |
2010
|
|
|
ok_(page_1 in foo_result) |
2011
|
|
|
|
2012
|
|
|
bar_result = api.search(['bar']).all() |
2013
|
|
|
eq_(1, len(bar_result)) |
2014
|
|
|
ok_(page_2 in bar_result) |
2015
|
|
|
|
2016
|
|
|
# ContentApi offer exclude_unavailable method to do it |
2017
|
|
|
foo_result = api.search(['foo']).all() |
2018
|
|
|
api.exclude_unavailable(foo_result) |
2019
|
|
|
eq_(0, len(foo_result)) |
2020
|
|
|
|
2021
|
|
|
bar_result = api.search(['bar']).all() |
2022
|
|
|
api.exclude_unavailable(bar_result) |
2023
|
|
|
eq_(0, len(bar_result)) |
2024
|
|
|
|
2025
|
|
|
|
2026
|
|
|
class TestContentApiSecurity(DefaultTest): |
|
|
|
|
2027
|
|
|
fixtures = [FixtureTest, ] |
2028
|
|
|
|
2029
|
|
|
def test_unit__cant_get_non_access_content__ok__nominal_case(self): |
|
|
|
|
2030
|
|
|
admin = self.session.query(User)\ |
2031
|
|
|
.filter(User.email == '[email protected]').one() |
2032
|
|
|
bob = self.session.query(User)\ |
2033
|
|
|
.filter(User.email == '[email protected]').one() |
2034
|
|
|
|
2035
|
|
|
bob_workspace = WorkspaceApi( |
2036
|
|
|
current_user=bob, |
2037
|
|
|
session=self.session, |
2038
|
|
|
).create_workspace( |
2039
|
|
|
'bob_workspace', |
2040
|
|
|
save_now=True, |
2041
|
|
|
) |
2042
|
|
|
admin_workspace = WorkspaceApi( |
2043
|
|
|
current_user=admin, |
2044
|
|
|
session=self.session, |
2045
|
|
|
).create_workspace( |
2046
|
|
|
'admin_workspace', |
2047
|
|
|
save_now=True, |
2048
|
|
|
) |
2049
|
|
|
|
2050
|
|
|
bob_page = ContentApi( |
|
|
|
|
2051
|
|
|
current_user=bob, |
2052
|
|
|
session=self.session, |
2053
|
|
|
config=self.app_config, |
2054
|
|
|
).create( |
2055
|
|
|
content_type=ContentType.Page, |
2056
|
|
|
workspace=bob_workspace, |
2057
|
|
|
label='bob_page', |
2058
|
|
|
do_save=True, |
2059
|
|
|
) |
2060
|
|
|
|
2061
|
|
|
admin_page = ContentApi( |
|
|
|
|
2062
|
|
|
current_user=admin, |
2063
|
|
|
session=self.session, |
2064
|
|
|
config=self.app_config, |
2065
|
|
|
).create( |
2066
|
|
|
content_type=ContentType.Page, |
2067
|
|
|
workspace=admin_workspace, |
2068
|
|
|
label='admin_page', |
2069
|
|
|
do_save=True, |
2070
|
|
|
) |
2071
|
|
|
|
2072
|
|
|
bob_viewable = ContentApi( |
2073
|
|
|
current_user=bob, |
2074
|
|
|
session=self.session, |
2075
|
|
|
config=self.app_config, |
2076
|
|
|
).get_all() |
2077
|
|
|
eq_(1, len(bob_viewable), 'Bob should view only one content') |
2078
|
|
|
eq_( |
2079
|
|
|
'bob_page', |
2080
|
|
|
bob_viewable[0].label, |
2081
|
|
|
'Bob should not view "{0}" content'.format( |
2082
|
|
|
bob_viewable[0].label, |
2083
|
|
|
) |
2084
|
|
|
) |
2085
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.