1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
import pytest |
3
|
|
|
import transaction |
4
|
|
|
|
5
|
|
|
from tracim_backend.app_models.contents import CONTENT_TYPES |
6
|
|
|
from tracim_backend.exceptions import ContentLabelAlreadyUsedHere |
7
|
|
|
from tracim_backend.exceptions import EmptyLabelNotAllowed |
8
|
|
|
from tracim_backend.exceptions import SameValueError |
9
|
|
|
from tracim_backend.exceptions import UnallowedSubContent |
10
|
|
|
from tracim_backend.fixtures.users_and_groups import Test as FixtureTest |
11
|
|
|
from tracim_backend.lib.core.content import ContentApi |
12
|
|
|
from tracim_backend.lib.core.content import compare_content_for_sorting_by_type_and_name # nopep8 |
13
|
|
|
# TODO - G.M - 28-03-2018 - [GroupApi] Re-enable GroupApi |
14
|
|
|
from tracim_backend.lib.core.group import GroupApi |
15
|
|
|
from tracim_backend.lib.core.user import UserApi |
16
|
|
|
# TODO - G.M - 28-03-2018 - [WorkspaceApi] Re-enable WorkspaceApi |
17
|
|
|
# TODO - G.M - 28-03-2018 - [RoleApi] Re-enable RoleApi |
18
|
|
|
from tracim_backend.lib.core.workspace import RoleApi |
19
|
|
|
from tracim_backend.lib.core.workspace import WorkspaceApi |
20
|
|
|
from tracim_backend.models.auth import Group |
21
|
|
|
from tracim_backend.models.auth import User |
22
|
|
|
from tracim_backend.models.data import ActionDescription |
23
|
|
|
from tracim_backend.models.data import Content |
24
|
|
|
from tracim_backend.models.data import ContentRevisionRO |
25
|
|
|
from tracim_backend.models.data import UserRoleInWorkspace |
26
|
|
|
from tracim_backend.models.data import Workspace |
27
|
|
|
from tracim_backend.models.revision_protection import new_revision |
28
|
|
|
from tracim_backend.tests import DefaultTest |
29
|
|
|
from tracim_backend.tests import eq_ |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class TestContentApi(DefaultTest): |
33
|
|
|
|
34
|
|
|
def test_compare_content_for_sorting_by_type(self): |
35
|
|
|
c1 = Content() |
36
|
|
|
c1.label = '' |
37
|
|
|
c1.type = 'file' |
38
|
|
|
|
39
|
|
|
c2 = Content() |
40
|
|
|
c2.label = '' |
41
|
|
|
c2.type = 'folder' |
42
|
|
|
|
43
|
|
|
c11 = c1 |
44
|
|
|
|
45
|
|
|
eq_(1, compare_content_for_sorting_by_type_and_name(c1, c2)) |
46
|
|
|
eq_(-1, compare_content_for_sorting_by_type_and_name(c2, c1)) |
47
|
|
|
eq_(0, compare_content_for_sorting_by_type_and_name(c1, c11)) |
48
|
|
|
|
49
|
|
|
def test_compare_content_for_sorting_by_label(self): |
50
|
|
|
c1 = Content() |
51
|
|
|
c1.label = 'bbb' |
52
|
|
|
c1.type = 'file' |
53
|
|
|
|
54
|
|
|
c2 = Content() |
55
|
|
|
c2.label = 'aaa' |
56
|
|
|
c2.type = 'file' |
57
|
|
|
|
58
|
|
|
c11 = c1 |
59
|
|
|
|
60
|
|
|
eq_(1, compare_content_for_sorting_by_type_and_name(c1, c2)) |
61
|
|
|
eq_(-1, compare_content_for_sorting_by_type_and_name(c2, c1)) |
62
|
|
|
eq_(0, compare_content_for_sorting_by_type_and_name(c1, c11)) |
63
|
|
|
|
64
|
|
|
def test_sort_by_label_or_filename(self): |
65
|
|
|
c1 = Content() |
66
|
|
|
c1.label = 'ABCD' |
67
|
|
|
c1.type = 'file' |
68
|
|
|
|
69
|
|
|
c2 = Content() |
70
|
|
|
c2.label = '' |
71
|
|
|
c2.type = 'file' |
72
|
|
|
c2.file_name = 'AABC' |
73
|
|
|
|
74
|
|
|
c3 = Content() |
75
|
|
|
c3.label = 'BCDE' |
76
|
|
|
c3.type = 'file' |
77
|
|
|
|
78
|
|
|
items = [c1, c2, c3] |
79
|
|
|
sorteds = ContentApi.sort_content(items) |
80
|
|
|
|
81
|
|
|
eq_(sorteds[0], c2) |
82
|
|
|
eq_(sorteds[1], c1) |
83
|
|
|
eq_(sorteds[2], c3) |
84
|
|
|
|
85
|
|
|
def test_sort_by_content_type(self): |
86
|
|
|
c1 = Content() |
87
|
|
|
c1.label = 'AAAA' |
88
|
|
|
c1.type = 'file' |
89
|
|
|
|
90
|
|
|
c2 = Content() |
91
|
|
|
c2.label = 'BBBB' |
92
|
|
|
c2.type = 'folder' |
93
|
|
|
|
94
|
|
|
items = [c1, c2] |
95
|
|
|
sorteds = ContentApi.sort_content(items) |
96
|
|
|
|
97
|
|
|
eq_(sorteds[0], c2, |
98
|
|
|
'value is {} instead of {}'.format(sorteds[0].content_id, |
99
|
|
|
c2.content_id)) |
100
|
|
|
eq_(sorteds[1], c1, |
101
|
|
|
'value is {} instead of {}'.format(sorteds[1].content_id, |
102
|
|
|
c1.content_id)) |
103
|
|
|
|
104
|
|
View Code Duplication |
def test_unit__create_content__OK_nominal_case(self): |
|
|
|
|
105
|
|
|
uapi = UserApi( |
106
|
|
|
session=self.session, |
107
|
|
|
config=self.app_config, |
108
|
|
|
current_user=None, |
109
|
|
|
) |
110
|
|
|
group_api = GroupApi( |
111
|
|
|
current_user=None, |
112
|
|
|
session=self.session, |
113
|
|
|
config=self.app_config, |
114
|
|
|
) |
115
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
116
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
117
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
118
|
|
|
|
119
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
120
|
|
|
groups=groups, save_now=True) |
121
|
|
|
workspace = WorkspaceApi( |
122
|
|
|
current_user=user, |
123
|
|
|
session=self.session, |
124
|
|
|
config=self.app_config, |
125
|
|
|
).create_workspace('test workspace', save_now=True) |
126
|
|
|
api = ContentApi( |
127
|
|
|
current_user=user, |
128
|
|
|
session=self.session, |
129
|
|
|
config=self.app_config, |
130
|
|
|
) |
131
|
|
|
item = api.create( |
132
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
133
|
|
|
workspace=workspace, |
134
|
|
|
parent=None, |
135
|
|
|
label='not_deleted', |
136
|
|
|
do_save=True |
137
|
|
|
) |
138
|
|
|
assert isinstance(item, Content) |
139
|
|
|
|
140
|
|
View Code Duplication |
def test_unit__create_content__err_empty_label(self): |
|
|
|
|
141
|
|
|
uapi = UserApi( |
142
|
|
|
session=self.session, |
143
|
|
|
config=self.app_config, |
144
|
|
|
current_user=None, |
145
|
|
|
) |
146
|
|
|
group_api = GroupApi( |
147
|
|
|
current_user=None, |
148
|
|
|
session=self.session, |
149
|
|
|
config=self.app_config, |
150
|
|
|
) |
151
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
152
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
153
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
154
|
|
|
|
155
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
156
|
|
|
groups=groups, save_now=True) |
157
|
|
|
workspace = WorkspaceApi( |
158
|
|
|
current_user=user, |
159
|
|
|
session=self.session, |
160
|
|
|
config=self.app_config, |
161
|
|
|
).create_workspace('test workspace', save_now=True) |
162
|
|
|
api = ContentApi( |
163
|
|
|
current_user=user, |
164
|
|
|
session=self.session, |
165
|
|
|
config=self.app_config, |
166
|
|
|
) |
167
|
|
|
with pytest.raises(EmptyLabelNotAllowed): |
168
|
|
|
api.create( |
169
|
|
|
content_type_slug=CONTENT_TYPES.Thread.slug, |
170
|
|
|
workspace=workspace, |
171
|
|
|
parent=None, |
172
|
|
|
label='', |
173
|
|
|
do_save=True |
174
|
|
|
) |
175
|
|
|
|
176
|
|
|
def test_unit__create_content__err_content_type_not_allowed_in_this_folder(self): |
177
|
|
|
uapi = UserApi( |
178
|
|
|
session=self.session, |
179
|
|
|
config=self.app_config, |
180
|
|
|
current_user=None, |
181
|
|
|
) |
182
|
|
|
group_api = GroupApi( |
183
|
|
|
current_user=None, |
184
|
|
|
session=self.session, |
185
|
|
|
config=self.app_config, |
186
|
|
|
) |
187
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
188
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
189
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
190
|
|
|
|
191
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
192
|
|
|
groups=groups, save_now=True) |
193
|
|
|
workspace = WorkspaceApi( |
194
|
|
|
current_user=user, |
195
|
|
|
session=self.session, |
196
|
|
|
config=self.app_config, |
197
|
|
|
).create_workspace('test workspace', save_now=True) |
198
|
|
|
api = ContentApi( |
199
|
|
|
current_user=user, |
200
|
|
|
session=self.session, |
201
|
|
|
config=self.app_config, |
202
|
|
|
) |
203
|
|
|
folder = api.create( |
204
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
205
|
|
|
workspace=workspace, |
206
|
|
|
parent=None, |
207
|
|
|
label='plop', |
208
|
|
|
do_save=False |
209
|
|
|
) |
210
|
|
|
allowed_content_dict = {CONTENT_TYPES.Folder.slug: True, CONTENT_TYPES.File.slug: False} # nopep8 |
211
|
|
|
api._set_allowed_content( |
212
|
|
|
folder, |
213
|
|
|
allowed_content_dict=allowed_content_dict |
214
|
|
|
) |
215
|
|
|
api.save(content=folder) |
216
|
|
|
# not in list -> do not allow |
217
|
|
|
with pytest.raises(UnallowedSubContent): |
218
|
|
|
api.create( |
219
|
|
|
content_type_slug=CONTENT_TYPES.Event.slug, |
220
|
|
|
workspace=workspace, |
221
|
|
|
parent=folder, |
222
|
|
|
label='lapin', |
223
|
|
|
do_save=True |
224
|
|
|
) |
225
|
|
|
# in list but false -> do not allow |
226
|
|
|
with pytest.raises(UnallowedSubContent): |
227
|
|
|
api.create( |
228
|
|
|
content_type_slug=CONTENT_TYPES.File.slug, |
229
|
|
|
workspace=workspace, |
230
|
|
|
parent=folder, |
231
|
|
|
label='lapin', |
232
|
|
|
do_save=True |
233
|
|
|
) |
234
|
|
|
# in list and true -> allow |
235
|
|
|
api.create( |
236
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
237
|
|
|
workspace=workspace, |
238
|
|
|
parent=folder, |
239
|
|
|
label='lapin', |
240
|
|
|
do_save=True |
241
|
|
|
) |
242
|
|
|
|
243
|
|
View Code Duplication |
def test_unit__create_content__err_content_type_not_allowed_in_this_workspace(self): |
|
|
|
|
244
|
|
|
uapi = UserApi( |
245
|
|
|
session=self.session, |
246
|
|
|
config=self.app_config, |
247
|
|
|
current_user=None, |
248
|
|
|
) |
249
|
|
|
group_api = GroupApi( |
250
|
|
|
current_user=None, |
251
|
|
|
session=self.session, |
252
|
|
|
config=self.app_config, |
253
|
|
|
) |
254
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
255
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
256
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
257
|
|
|
|
258
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
259
|
|
|
groups=groups, save_now=True) |
260
|
|
|
workspace = WorkspaceApi( |
261
|
|
|
current_user=user, |
262
|
|
|
session=self.session, |
263
|
|
|
config=self.app_config, |
264
|
|
|
).create_workspace('test workspace', save_now=True) |
265
|
|
|
api = ContentApi( |
266
|
|
|
current_user=user, |
267
|
|
|
session=self.session, |
268
|
|
|
config=self.app_config, |
269
|
|
|
) |
270
|
|
|
with pytest.raises(UnallowedSubContent): |
271
|
|
|
api.create( |
272
|
|
|
content_type_slug=CONTENT_TYPES.Event.slug, |
273
|
|
|
workspace=workspace, |
274
|
|
|
parent=None, |
275
|
|
|
label='lapin', |
276
|
|
|
do_save=True |
277
|
|
|
) |
278
|
|
|
|
279
|
|
|
def test_unit__create_content__err_same_label_as_another_content(self): |
280
|
|
|
uapi = UserApi( |
281
|
|
|
session=self.session, |
282
|
|
|
config=self.app_config, |
283
|
|
|
current_user=None, |
284
|
|
|
) |
285
|
|
|
group_api = GroupApi( |
286
|
|
|
current_user=None, |
287
|
|
|
session=self.session, |
288
|
|
|
config=self.app_config, |
289
|
|
|
) |
290
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
291
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
292
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
293
|
|
|
|
294
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
295
|
|
|
groups=groups, save_now=True) |
296
|
|
|
workspace = WorkspaceApi( |
297
|
|
|
current_user=user, |
298
|
|
|
session=self.session, |
299
|
|
|
config=self.app_config, |
300
|
|
|
).create_workspace('test workspace', save_now=True) |
301
|
|
|
api = ContentApi( |
302
|
|
|
current_user=user, |
303
|
|
|
session=self.session, |
304
|
|
|
config=self.app_config, |
305
|
|
|
) |
306
|
|
|
api.create( |
307
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
308
|
|
|
workspace=workspace, |
309
|
|
|
parent=None, |
310
|
|
|
label='file', |
311
|
|
|
do_save=True |
312
|
|
|
) |
313
|
|
|
with pytest.raises(ContentLabelAlreadyUsedHere): |
314
|
|
|
api.create( |
315
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
316
|
|
|
workspace=workspace, |
317
|
|
|
parent=None, |
318
|
|
|
label='file', |
319
|
|
|
do_save=True |
320
|
|
|
) |
321
|
|
|
|
322
|
|
|
def test_unit__is_content_label_is_free__ok__nominal_case(self): |
323
|
|
|
uapi = UserApi( |
324
|
|
|
session=self.session, |
325
|
|
|
config=self.app_config, |
326
|
|
|
current_user=None, |
327
|
|
|
) |
328
|
|
|
group_api = GroupApi( |
329
|
|
|
current_user=None, |
330
|
|
|
session=self.session, |
331
|
|
|
config=self.app_config, |
332
|
|
|
) |
333
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
334
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
335
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
336
|
|
|
|
337
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
338
|
|
|
groups=groups, save_now=True) |
339
|
|
|
workspace = WorkspaceApi( |
340
|
|
|
current_user=user, |
341
|
|
|
session=self.session, |
342
|
|
|
config=self.app_config, |
343
|
|
|
).create_workspace('test workspace', save_now=True) |
344
|
|
|
api = ContentApi( |
345
|
|
|
current_user=user, |
346
|
|
|
session=self.session, |
347
|
|
|
config=self.app_config, |
348
|
|
|
) |
349
|
|
|
assert api._is_content_label_free('test', workspace, parent=None) == True # nopep8 |
350
|
|
|
content = Content() |
351
|
|
|
content.label = 'test' |
352
|
|
|
content.owner = user |
353
|
|
|
content.parent = None |
354
|
|
|
content.workspace = workspace |
355
|
|
|
content.type = CONTENT_TYPES.Page.slug |
356
|
|
|
content.revision_type = ActionDescription.CREATION |
357
|
|
|
self.session.add(content) |
358
|
|
|
api.save(content, ActionDescription.CREATION, do_notify=False) |
359
|
|
|
assert api._is_content_label_free('test', workspace, parent=None) is False # nopep8 |
360
|
|
|
content = Content() |
361
|
|
|
content.label = 'test' |
362
|
|
|
content.owner = user |
363
|
|
|
content.parent = None |
364
|
|
|
content.workspace = workspace |
365
|
|
|
content.type = CONTENT_TYPES.Page.slug |
366
|
|
|
content.revision_type = ActionDescription.CREATION |
367
|
|
|
self.session.add(content) |
368
|
|
|
api.save(content, ActionDescription.CREATION, do_notify=False) |
369
|
|
|
assert api._is_content_label_free('test', workspace, parent=None) is False # nopep8 |
370
|
|
|
|
371
|
|
|
def test_unit__is_content_label_is_free__ok__different_workspace(self): |
372
|
|
|
uapi = UserApi( |
373
|
|
|
session=self.session, |
374
|
|
|
config=self.app_config, |
375
|
|
|
current_user=None, |
376
|
|
|
) |
377
|
|
|
group_api = GroupApi( |
378
|
|
|
current_user=None, |
379
|
|
|
session=self.session, |
380
|
|
|
config=self.app_config, |
381
|
|
|
) |
382
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
383
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
384
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
385
|
|
|
|
386
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
387
|
|
|
groups=groups, save_now=True) |
388
|
|
|
workspace = WorkspaceApi( |
389
|
|
|
current_user=user, |
390
|
|
|
session=self.session, |
391
|
|
|
config=self.app_config, |
392
|
|
|
).create_workspace('test workspace', save_now=True) |
393
|
|
|
workspace2 = WorkspaceApi( |
394
|
|
|
current_user=user, |
395
|
|
|
session=self.session, |
396
|
|
|
config=self.app_config, |
397
|
|
|
).create_workspace('test workspace2', save_now=True) |
398
|
|
|
api = ContentApi( |
399
|
|
|
current_user=user, |
400
|
|
|
session=self.session, |
401
|
|
|
config=self.app_config, |
402
|
|
|
) |
403
|
|
|
assert api._is_content_label_free('test', workspace, parent=None) == True # nopep8 |
404
|
|
|
content = Content() |
405
|
|
|
content.label = 'test' |
406
|
|
|
content.owner = user |
407
|
|
|
content.parent = None |
408
|
|
|
content.workspace = workspace2 |
409
|
|
|
content.type = CONTENT_TYPES.Page.slug |
410
|
|
|
content.revision_type = ActionDescription.CREATION |
411
|
|
|
self.session.add(content) |
412
|
|
|
api.save(content, ActionDescription.CREATION, do_notify=False) |
413
|
|
|
assert api._is_content_label_free('test', workspace, parent=None) == True # nopep8 |
414
|
|
|
|
415
|
|
|
def test_unit__is_content_label_is_free__ok__different_parent(self): |
416
|
|
|
uapi = UserApi( |
417
|
|
|
session=self.session, |
418
|
|
|
config=self.app_config, |
419
|
|
|
current_user=None, |
420
|
|
|
) |
421
|
|
|
group_api = GroupApi( |
422
|
|
|
current_user=None, |
423
|
|
|
session=self.session, |
424
|
|
|
config=self.app_config, |
425
|
|
|
) |
426
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
427
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
428
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
429
|
|
|
|
430
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
431
|
|
|
groups=groups, save_now=True) |
432
|
|
|
workspace = WorkspaceApi( |
433
|
|
|
current_user=user, |
434
|
|
|
session=self.session, |
435
|
|
|
config=self.app_config, |
436
|
|
|
).create_workspace('test workspace', save_now=True) |
437
|
|
|
workspace = WorkspaceApi( |
438
|
|
|
current_user=user, |
439
|
|
|
session=self.session, |
440
|
|
|
config=self.app_config, |
441
|
|
|
).create_workspace('test workspace2', save_now=True) |
442
|
|
|
api = ContentApi( |
443
|
|
|
current_user=user, |
444
|
|
|
session=self.session, |
445
|
|
|
config=self.app_config, |
446
|
|
|
) |
447
|
|
|
folder = Content() |
448
|
|
|
folder.label = 'folder' |
449
|
|
|
folder.owner = user |
450
|
|
|
folder.parent = None |
451
|
|
|
folder.workspace = workspace |
452
|
|
|
folder.type = CONTENT_TYPES.Folder.slug |
453
|
|
|
folder.revision_type = ActionDescription.CREATION |
454
|
|
|
self.session.add(folder) |
455
|
|
|
folder2 = Content() |
456
|
|
|
folder2.label = 'folder2' |
457
|
|
|
folder2.owner = user |
458
|
|
|
folder2.parent = None |
459
|
|
|
folder2.workspace = workspace |
460
|
|
|
folder2.type = CONTENT_TYPES.Folder.slug |
461
|
|
|
folder2.revision_type = ActionDescription.CREATION |
462
|
|
|
self.session.add(folder) |
463
|
|
|
assert api._is_content_label_free('test', workspace, parent=None) == True # nopep8 |
464
|
|
|
content = Content() |
465
|
|
|
content.label = 'test' |
466
|
|
|
content.owner = user |
467
|
|
|
content.parent = folder |
468
|
|
|
content.workspace = workspace |
469
|
|
|
content.type = CONTENT_TYPES.Page.slug |
470
|
|
|
content.revision_type = ActionDescription.CREATION |
471
|
|
|
self.session.add(content) |
472
|
|
|
api.save(content, ActionDescription.CREATION, do_notify=False) |
473
|
|
|
assert api._is_content_label_free('test', workspace, parent=None) == True # nopep8 |
474
|
|
|
content = Content() |
475
|
|
|
content.label = 'test' |
476
|
|
|
content.owner = user |
477
|
|
|
content.parent = folder2 |
478
|
|
|
content.workspace = workspace |
479
|
|
|
content.type = CONTENT_TYPES.Page.slug |
480
|
|
|
content.revision_type = ActionDescription.CREATION |
481
|
|
|
self.session.add(content) |
482
|
|
|
api.save(content, ActionDescription.CREATION, do_notify=False) |
483
|
|
|
assert api._is_content_label_free('test', workspace, parent=None) == True # nopep8 |
484
|
|
|
content = Content() |
485
|
|
|
content.label = 'test' |
486
|
|
|
content.owner = user |
487
|
|
|
content.parent = None |
488
|
|
|
content.workspace = workspace |
489
|
|
|
content.type = CONTENT_TYPES.Page.slug |
490
|
|
|
content.revision_type = ActionDescription.CREATION |
491
|
|
|
self.session.add(content) |
492
|
|
|
api.save(content, ActionDescription.CREATION, do_notify=False) |
493
|
|
|
assert api._is_content_label_free('test', workspace, parent=None) == False # nopep8 |
494
|
|
|
|
495
|
|
View Code Duplication |
def test_unit__set_allowed_content__ok__private_method(self): |
|
|
|
|
496
|
|
|
uapi = UserApi( |
497
|
|
|
session=self.session, |
498
|
|
|
config=self.app_config, |
499
|
|
|
current_user=None, |
500
|
|
|
) |
501
|
|
|
group_api = GroupApi( |
502
|
|
|
current_user=None, |
503
|
|
|
session=self.session, |
504
|
|
|
config=self.app_config, |
505
|
|
|
) |
506
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
507
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
508
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
509
|
|
|
|
510
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
511
|
|
|
groups=groups, save_now=True) |
512
|
|
|
workspace = WorkspaceApi( |
513
|
|
|
current_user=user, |
514
|
|
|
session=self.session, |
515
|
|
|
config=self.app_config, |
516
|
|
|
).create_workspace('test workspace', save_now=True) |
517
|
|
|
api = ContentApi( |
518
|
|
|
current_user=user, |
519
|
|
|
session=self.session, |
520
|
|
|
config=self.app_config, |
521
|
|
|
) |
522
|
|
|
folder = api.create( |
523
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
524
|
|
|
workspace=workspace, |
525
|
|
|
parent=None, |
526
|
|
|
label='plop', |
527
|
|
|
do_save=False |
528
|
|
|
) |
529
|
|
|
allowed_content_dict = {CONTENT_TYPES.Folder.slug: True, CONTENT_TYPES.File.slug: False} # nopep8 |
530
|
|
|
api._set_allowed_content( |
531
|
|
|
folder, |
532
|
|
|
allowed_content_dict=allowed_content_dict |
533
|
|
|
) |
534
|
|
|
assert 'allowed_content' in folder.properties |
535
|
|
|
assert folder.properties['allowed_content'] == {CONTENT_TYPES.Folder.slug: True, CONTENT_TYPES.File.slug: False} |
536
|
|
|
|
537
|
|
View Code Duplication |
def test_unit__set_allowed_content__ok__nominal_case(self): |
|
|
|
|
538
|
|
|
uapi = UserApi( |
539
|
|
|
session=self.session, |
540
|
|
|
config=self.app_config, |
541
|
|
|
current_user=None, |
542
|
|
|
) |
543
|
|
|
group_api = GroupApi( |
544
|
|
|
current_user=None, |
545
|
|
|
session=self.session, |
546
|
|
|
config=self.app_config, |
547
|
|
|
) |
548
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
549
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
550
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
551
|
|
|
|
552
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
553
|
|
|
groups=groups, save_now=True) |
554
|
|
|
workspace = WorkspaceApi( |
555
|
|
|
current_user=user, |
556
|
|
|
session=self.session, |
557
|
|
|
config=self.app_config, |
558
|
|
|
).create_workspace('test workspace', save_now=True) |
559
|
|
|
api = ContentApi( |
560
|
|
|
current_user=user, |
561
|
|
|
session=self.session, |
562
|
|
|
config=self.app_config, |
563
|
|
|
) |
564
|
|
|
folder = api.create( |
565
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
566
|
|
|
workspace=workspace, |
567
|
|
|
parent=None, |
568
|
|
|
label='plop', |
569
|
|
|
do_save=False |
570
|
|
|
) |
571
|
|
|
allowed_content_type_slug_list = [CONTENT_TYPES.Folder.slug, CONTENT_TYPES.File.slug] # nopep8 |
572
|
|
|
api.set_allowed_content( |
573
|
|
|
folder, |
574
|
|
|
allowed_content_type_slug_list=allowed_content_type_slug_list |
575
|
|
|
) |
576
|
|
|
assert 'allowed_content' in folder.properties |
577
|
|
|
assert folder.properties['allowed_content'] == {CONTENT_TYPES.Folder.slug: True, CONTENT_TYPES.File.slug: True} |
578
|
|
|
|
579
|
|
|
def test_unit__restore_content_default_allowed_content__ok__nominal_case(self): |
580
|
|
|
uapi = UserApi( |
581
|
|
|
session=self.session, |
582
|
|
|
config=self.app_config, |
583
|
|
|
current_user=None, |
584
|
|
|
) |
585
|
|
|
group_api = GroupApi( |
586
|
|
|
current_user=None, |
587
|
|
|
session=self.session, |
588
|
|
|
config=self.app_config, |
589
|
|
|
) |
590
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
591
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
592
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
593
|
|
|
|
594
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
595
|
|
|
groups=groups, save_now=True) |
596
|
|
|
workspace = WorkspaceApi( |
597
|
|
|
current_user=user, |
598
|
|
|
session=self.session, |
599
|
|
|
config=self.app_config, |
600
|
|
|
).create_workspace('test workspace', save_now=True) |
601
|
|
|
api = ContentApi( |
602
|
|
|
current_user=user, |
603
|
|
|
session=self.session, |
604
|
|
|
config=self.app_config, |
605
|
|
|
) |
606
|
|
|
folder = api.create( |
607
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
608
|
|
|
workspace=workspace, |
609
|
|
|
parent=None, |
610
|
|
|
label='plop', |
611
|
|
|
do_save=False |
612
|
|
|
) |
613
|
|
|
allowed_content_type_slug_list = [CONTENT_TYPES.Folder.slug, CONTENT_TYPES.File.slug] # nopep8 |
614
|
|
|
api.set_allowed_content( |
615
|
|
|
folder, |
616
|
|
|
allowed_content_type_slug_list=allowed_content_type_slug_list |
617
|
|
|
) |
618
|
|
|
assert 'allowed_content' in folder.properties |
619
|
|
|
assert folder.properties['allowed_content'] == {CONTENT_TYPES.Folder.slug: True, CONTENT_TYPES.File.slug: True} # nopep8 |
620
|
|
|
api.restore_content_default_allowed_content(folder) |
621
|
|
|
assert 'allowed_content' in folder.properties |
622
|
|
|
assert folder.properties['allowed_content'] == CONTENT_TYPES.default_allowed_content_properties(folder.type) # nopep8 |
623
|
|
|
|
624
|
|
|
def test_delete(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
|
|
|
config=self.app_config, |
634
|
|
|
) |
635
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
636
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
637
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
638
|
|
|
|
639
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
640
|
|
|
groups=groups, save_now=True) |
641
|
|
|
workspace = WorkspaceApi( |
642
|
|
|
current_user=user, |
643
|
|
|
session=self.session, |
644
|
|
|
config=self.app_config, |
645
|
|
|
).create_workspace('test workspace', save_now=True) |
646
|
|
|
api = ContentApi( |
647
|
|
|
current_user=user, |
648
|
|
|
session=self.session, |
649
|
|
|
config=self.app_config, |
650
|
|
|
) |
651
|
|
|
item = api.create( |
652
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
653
|
|
|
workspace=workspace, |
654
|
|
|
parent=None, |
655
|
|
|
label='not_deleted', |
656
|
|
|
do_save=True |
657
|
|
|
) |
658
|
|
|
item2 = api.create( |
659
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
660
|
|
|
workspace=workspace, |
661
|
|
|
parent=None, |
662
|
|
|
label='to_delete', |
663
|
|
|
do_save=True |
664
|
|
|
) |
665
|
|
|
uid = user.user_id |
666
|
|
|
wid = workspace.workspace_id |
667
|
|
|
transaction.commit() |
668
|
|
|
|
669
|
|
|
# Refresh instances after commit |
670
|
|
|
user = uapi.get_one(uid) |
671
|
|
|
workspace_api = WorkspaceApi( |
672
|
|
|
current_user=user, |
673
|
|
|
session=self.session, |
674
|
|
|
config=self.app_config |
675
|
|
|
) |
676
|
|
|
workspace = workspace_api.get_one(wid) |
677
|
|
|
api = ContentApi( |
678
|
|
|
current_user=user, |
679
|
|
|
session=self.session, |
680
|
|
|
config=self.app_config, |
681
|
|
|
) |
682
|
|
|
items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace) |
683
|
|
|
eq_(2, len(items)) |
684
|
|
|
|
685
|
|
|
items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace) |
686
|
|
|
with new_revision( |
687
|
|
|
session=self.session, |
688
|
|
|
tm=transaction.manager, |
689
|
|
|
content=items[0] |
690
|
|
|
): |
691
|
|
|
api.delete(items[0]) |
692
|
|
|
transaction.commit() |
693
|
|
|
|
694
|
|
|
# Refresh instances after commit |
695
|
|
|
user = uapi.get_one(uid) |
696
|
|
|
workspace_api = WorkspaceApi( |
697
|
|
|
current_user=user, |
698
|
|
|
session=self.session, |
699
|
|
|
config=self.app_config |
700
|
|
|
) |
701
|
|
|
workspace = workspace_api.get_one(wid) |
702
|
|
|
api = ContentApi( |
703
|
|
|
current_user=user, |
704
|
|
|
session=self.session, |
705
|
|
|
config=self.app_config, |
706
|
|
|
) |
707
|
|
|
items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace) |
708
|
|
|
eq_(1, len(items)) |
709
|
|
|
transaction.commit() |
710
|
|
|
|
711
|
|
|
# Test that the item is still available if "show deleted" is activated |
712
|
|
|
# Refresh instances after commit |
713
|
|
|
user = uapi.get_one(uid) |
714
|
|
|
workspace_api = WorkspaceApi( |
715
|
|
|
current_user=user, |
716
|
|
|
session=self.session, |
717
|
|
|
config=self.app_config, |
718
|
|
|
) |
719
|
|
|
api = ContentApi( |
720
|
|
|
current_user=user, |
721
|
|
|
session=self.session, |
722
|
|
|
config=self.app_config, |
723
|
|
|
show_deleted=True, |
724
|
|
|
) |
725
|
|
|
items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace) |
726
|
|
|
eq_(2, len(items)) |
727
|
|
|
|
728
|
|
|
def test_archive(self): |
729
|
|
|
uapi = UserApi( |
730
|
|
|
session=self.session, |
731
|
|
|
config=self.app_config, |
732
|
|
|
current_user=None, |
733
|
|
|
) |
734
|
|
|
group_api = GroupApi( |
735
|
|
|
current_user=None, |
736
|
|
|
session=self.session, |
737
|
|
|
config=self.app_config, |
738
|
|
|
) |
739
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
740
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
741
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
742
|
|
|
|
743
|
|
|
user = uapi.create_minimal_user( |
744
|
|
|
email='this.is@user', |
745
|
|
|
groups=groups, |
746
|
|
|
save_now=True, |
747
|
|
|
) |
748
|
|
|
workspace_api = WorkspaceApi( |
749
|
|
|
current_user=user, |
750
|
|
|
session=self.session, |
751
|
|
|
config=self.app_config, |
752
|
|
|
) |
753
|
|
|
workspace = workspace_api.create_workspace( |
754
|
|
|
'test workspace', |
755
|
|
|
save_now=True |
756
|
|
|
) |
757
|
|
|
api = ContentApi( |
758
|
|
|
current_user=user, |
759
|
|
|
session=self.session, |
760
|
|
|
config=self.app_config, |
761
|
|
|
) |
762
|
|
|
item = api.create( |
763
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
764
|
|
|
workspace=workspace, |
765
|
|
|
parent=None, |
766
|
|
|
label='not_archived', |
767
|
|
|
do_save=True |
768
|
|
|
) |
769
|
|
|
item2 = api.create( |
770
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
771
|
|
|
workspace=workspace, |
772
|
|
|
parent=None, |
773
|
|
|
label='to_archive', |
774
|
|
|
do_save=True |
775
|
|
|
) |
776
|
|
|
uid = user.user_id |
777
|
|
|
wid = workspace.workspace_id |
778
|
|
|
transaction.commit() |
779
|
|
|
# Refresh instances after commit |
780
|
|
|
user = uapi.get_one(uid) |
781
|
|
|
workspace_api = WorkspaceApi( |
782
|
|
|
current_user=user, |
783
|
|
|
session=self.session, |
784
|
|
|
config=self.app_config, |
785
|
|
|
) |
786
|
|
|
api = ContentApi( |
787
|
|
|
session=self.session, |
788
|
|
|
current_user=user, |
789
|
|
|
config=self.app_config, |
790
|
|
|
) |
791
|
|
|
|
792
|
|
|
items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace) |
793
|
|
|
eq_(2, len(items)) |
794
|
|
|
|
795
|
|
|
items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace) |
796
|
|
|
with new_revision( |
797
|
|
|
session=self.session, |
798
|
|
|
tm=transaction.manager, |
799
|
|
|
content=items[0], |
800
|
|
|
): |
801
|
|
|
api.archive(items[0]) |
802
|
|
|
transaction.commit() |
803
|
|
|
|
804
|
|
|
# Refresh instances after commit |
805
|
|
|
user = uapi.get_one(uid) |
806
|
|
|
workspace_api = WorkspaceApi( |
807
|
|
|
current_user=user, |
808
|
|
|
session=self.session, |
809
|
|
|
config=self.app_config, |
810
|
|
|
) |
811
|
|
|
workspace = workspace_api.get_one(wid) |
812
|
|
|
api = ContentApi( |
813
|
|
|
current_user=user, |
814
|
|
|
session=self.session, |
815
|
|
|
config=self.app_config, |
816
|
|
|
) |
817
|
|
|
|
818
|
|
|
items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace) |
819
|
|
|
eq_(1, len(items)) |
820
|
|
|
transaction.commit() |
821
|
|
|
|
822
|
|
|
# Refresh instances after commit |
823
|
|
|
user = uapi.get_one(uid) |
824
|
|
|
workspace_api = WorkspaceApi( |
825
|
|
|
current_user=user, |
826
|
|
|
session=self.session, |
827
|
|
|
config=self.app_config, |
828
|
|
|
) |
829
|
|
|
workspace = workspace_api.get_one(wid) |
830
|
|
|
api = ContentApi( |
831
|
|
|
current_user=user, |
832
|
|
|
session=self.session, |
833
|
|
|
config=self.app_config, |
834
|
|
|
) |
835
|
|
|
|
836
|
|
|
# Test that the item is still available if "show deleted" is activated |
837
|
|
|
api = ContentApi( |
838
|
|
|
current_user=None, |
839
|
|
|
session=self.session, |
840
|
|
|
config=self.app_config, |
841
|
|
|
show_archived=True, |
842
|
|
|
) |
843
|
|
|
items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace) |
844
|
|
|
eq_(2, len(items)) |
845
|
|
|
|
846
|
|
|
def test_get_all_with_filter(self): |
847
|
|
|
uapi = UserApi( |
848
|
|
|
session=self.session, |
849
|
|
|
config=self.app_config, |
850
|
|
|
current_user=None, |
851
|
|
|
) |
852
|
|
|
group_api = GroupApi( |
853
|
|
|
current_user=None, |
854
|
|
|
session=self.session, |
855
|
|
|
config=self.app_config, |
856
|
|
|
) |
857
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
858
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
859
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
860
|
|
|
|
861
|
|
|
user = uapi.create_minimal_user( |
862
|
|
|
email='this.is@user', |
863
|
|
|
groups=groups, |
864
|
|
|
save_now=True |
865
|
|
|
) |
866
|
|
|
workspace = WorkspaceApi( |
867
|
|
|
current_user=user, |
868
|
|
|
session=self.session, |
869
|
|
|
config=self.app_config, |
870
|
|
|
).create_workspace( |
871
|
|
|
'test workspace', |
872
|
|
|
save_now=True |
873
|
|
|
) |
874
|
|
|
|
875
|
|
|
api = ContentApi( |
876
|
|
|
current_user=user, |
877
|
|
|
session=self.session, |
878
|
|
|
config=self.app_config, |
879
|
|
|
) |
880
|
|
|
item = api.create( |
881
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
882
|
|
|
workspace=workspace, |
883
|
|
|
parent=None, |
884
|
|
|
label='thefolder', |
885
|
|
|
do_save=True |
886
|
|
|
) |
887
|
|
|
item2 = api.create( |
888
|
|
|
content_type_slug=CONTENT_TYPES.File.slug, |
889
|
|
|
workspace=workspace, |
890
|
|
|
parent=None, |
891
|
|
|
label='thefile', |
892
|
|
|
do_save=True |
893
|
|
|
) |
894
|
|
|
uid = user.user_id |
895
|
|
|
wid = workspace.workspace_id |
896
|
|
|
transaction.commit() |
897
|
|
|
|
898
|
|
|
# Refresh instances after commit |
899
|
|
|
user = uapi.get_one(uid) |
900
|
|
|
workspace_api = WorkspaceApi( |
901
|
|
|
current_user=user, |
902
|
|
|
session=self.session, |
903
|
|
|
config=self.app_config, |
904
|
|
|
) |
905
|
|
|
workspace = workspace_api.get_one(wid) |
906
|
|
|
api = ContentApi( |
907
|
|
|
current_user=user, |
908
|
|
|
session=self.session, |
909
|
|
|
config=self.app_config, |
910
|
|
|
) |
911
|
|
|
|
912
|
|
|
items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace) |
913
|
|
|
eq_(2, len(items)) |
914
|
|
|
|
915
|
|
|
items2 = api.get_all(None, CONTENT_TYPES.File.slug, workspace) |
916
|
|
|
eq_(1, len(items2)) |
917
|
|
|
eq_('thefile', items2[0].label) |
918
|
|
|
|
919
|
|
|
items3 = api.get_all(None, CONTENT_TYPES.Folder.slug, workspace) |
920
|
|
|
eq_(1, len(items3)) |
921
|
|
|
eq_('thefolder', items3[0].label) |
922
|
|
|
|
923
|
|
|
def test_get_all_with_parent_id(self): |
924
|
|
|
uapi = UserApi( |
925
|
|
|
session=self.session, |
926
|
|
|
config=self.app_config, |
927
|
|
|
current_user=None, |
928
|
|
|
) |
929
|
|
|
group_api = GroupApi( |
930
|
|
|
current_user=None, |
931
|
|
|
session=self.session, |
932
|
|
|
config=self.app_config |
933
|
|
|
) |
934
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
935
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
936
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
937
|
|
|
|
938
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
939
|
|
|
groups=groups, save_now=True) |
940
|
|
|
workspace = WorkspaceApi( |
941
|
|
|
current_user=user, |
942
|
|
|
session=self.session, |
943
|
|
|
config=self.app_config |
944
|
|
|
).create_workspace('test workspace', save_now=True) |
945
|
|
|
api = ContentApi( |
946
|
|
|
current_user=user, |
947
|
|
|
session=self.session, |
948
|
|
|
config=self.app_config, |
949
|
|
|
) |
950
|
|
|
item = api.create( |
951
|
|
|
CONTENT_TYPES.Folder.slug, |
952
|
|
|
workspace, |
953
|
|
|
None, |
954
|
|
|
'parent', |
955
|
|
|
do_save=True, |
956
|
|
|
) |
957
|
|
|
item2 = api.create( |
958
|
|
|
CONTENT_TYPES.File.slug, |
959
|
|
|
workspace, |
960
|
|
|
item, |
961
|
|
|
'file1', |
962
|
|
|
do_save=True, |
963
|
|
|
) |
964
|
|
|
item3 = api.create( |
965
|
|
|
CONTENT_TYPES.File.slug, |
966
|
|
|
workspace, |
967
|
|
|
None, |
968
|
|
|
'file2', |
969
|
|
|
do_save=True, |
970
|
|
|
) |
971
|
|
|
parent_id = item.content_id |
972
|
|
|
child_id = item2.content_id |
973
|
|
|
uid = user.user_id |
974
|
|
|
wid = workspace.workspace_id |
975
|
|
|
transaction.commit() |
976
|
|
|
|
977
|
|
|
# Refresh instances after commit |
978
|
|
|
user = uapi.get_one(uid) |
979
|
|
|
workspace_api = WorkspaceApi( |
980
|
|
|
current_user=user, |
981
|
|
|
session=self.session, |
982
|
|
|
config=self.app_config, |
983
|
|
|
) |
984
|
|
|
workspace = workspace_api.get_one(wid) |
985
|
|
|
api = ContentApi( |
986
|
|
|
current_user=user, |
987
|
|
|
session=self.session, |
988
|
|
|
config=self.app_config, |
989
|
|
|
) |
990
|
|
|
|
991
|
|
|
items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace) |
992
|
|
|
eq_(3, len(items)) |
993
|
|
|
|
994
|
|
|
items2 = api.get_all(parent_id, CONTENT_TYPES.File.slug, workspace) |
995
|
|
|
eq_(1, len(items2)) |
996
|
|
|
eq_(child_id, items2[0].content_id) |
997
|
|
|
|
998
|
|
|
def test_set_status_unknown_status(self): |
999
|
|
|
uapi = UserApi( |
1000
|
|
|
session=self.session, |
1001
|
|
|
config=self.app_config, |
1002
|
|
|
current_user=None, |
1003
|
|
|
) |
1004
|
|
|
group_api = GroupApi( |
1005
|
|
|
current_user=None, |
1006
|
|
|
session=self.session, |
1007
|
|
|
config=self.app_config, |
1008
|
|
|
) |
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 = uapi.create_minimal_user(email='this.is@user', |
1014
|
|
|
groups=groups, save_now=True) |
1015
|
|
|
|
1016
|
|
|
workspace = WorkspaceApi( |
1017
|
|
|
current_user=user, |
1018
|
|
|
session=self.session, |
1019
|
|
|
config=self.app_config, |
1020
|
|
|
).create_workspace( |
1021
|
|
|
'test workspace', |
1022
|
|
|
save_now=True |
1023
|
|
|
) |
1024
|
|
|
api = ContentApi( |
1025
|
|
|
current_user=user, |
1026
|
|
|
session=self.session, |
1027
|
|
|
config=self.app_config, |
1028
|
|
|
) |
1029
|
|
|
c = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'parent', '', True) |
1030
|
|
|
with new_revision( |
1031
|
|
|
session=self.session, |
1032
|
|
|
tm=transaction.manager, |
1033
|
|
|
content=c, |
1034
|
|
|
): |
1035
|
|
|
with pytest.raises(ValueError): |
1036
|
|
|
api.set_status(c, 'unknown-status') |
1037
|
|
|
|
1038
|
|
|
def test_set_status_ok(self): |
1039
|
|
|
uapi = UserApi( |
1040
|
|
|
session=self.session, |
1041
|
|
|
config=self.app_config, |
1042
|
|
|
current_user=None, |
1043
|
|
|
) |
1044
|
|
|
group_api = GroupApi( |
1045
|
|
|
current_user=None, |
1046
|
|
|
session=self.session, |
1047
|
|
|
config=self.app_config, |
1048
|
|
|
) |
1049
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1050
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1051
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1052
|
|
|
|
1053
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
1054
|
|
|
groups=groups, save_now=True) |
1055
|
|
|
|
1056
|
|
|
workspace = WorkspaceApi( |
1057
|
|
|
current_user=user, |
1058
|
|
|
session=self.session, |
1059
|
|
|
config=self.app_config, |
1060
|
|
|
).create_workspace( |
1061
|
|
|
'test workspace', |
1062
|
|
|
save_now=True |
1063
|
|
|
) |
1064
|
|
|
api = ContentApi( |
1065
|
|
|
current_user=user, |
1066
|
|
|
session=self.session, |
1067
|
|
|
config=self.app_config, |
1068
|
|
|
) |
1069
|
|
|
c = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'parent', '', True) |
1070
|
|
|
with new_revision( |
1071
|
|
|
session=self.session, |
1072
|
|
|
tm=transaction.manager, |
1073
|
|
|
content=c, |
1074
|
|
|
): |
1075
|
|
|
for new_status in ['open', 'closed-validated', 'closed-unvalidated', |
1076
|
|
|
'closed-deprecated']: |
1077
|
|
|
api.set_status(c, new_status) |
1078
|
|
|
|
1079
|
|
|
eq_(new_status, c.status) |
1080
|
|
|
eq_(ActionDescription.STATUS_UPDATE, c.revision_type) |
1081
|
|
|
|
1082
|
|
|
def test_create_comment_ok(self): |
1083
|
|
|
uapi = UserApi( |
1084
|
|
|
session=self.session, |
1085
|
|
|
config=self.app_config, |
1086
|
|
|
current_user=None, |
1087
|
|
|
) |
1088
|
|
|
group_api = GroupApi( |
1089
|
|
|
current_user=None, |
1090
|
|
|
session=self.session, |
1091
|
|
|
config=self.config, |
1092
|
|
|
) |
1093
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1094
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1095
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1096
|
|
|
|
1097
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
1098
|
|
|
groups=groups, save_now=True) |
1099
|
|
|
|
1100
|
|
|
workspace = WorkspaceApi( |
1101
|
|
|
current_user=user, |
1102
|
|
|
session=self.session, |
1103
|
|
|
config=self.app_config, |
1104
|
|
|
).create_workspace( |
1105
|
|
|
'test workspace', |
1106
|
|
|
save_now=True |
1107
|
|
|
) |
1108
|
|
|
|
1109
|
|
|
api = ContentApi( |
1110
|
|
|
current_user=user, |
1111
|
|
|
session=self.session, |
1112
|
|
|
config=self.app_config, |
1113
|
|
|
) |
1114
|
|
|
p = api.create(CONTENT_TYPES.Page.slug, workspace, None, 'this_is_a_page') |
1115
|
|
|
c = api.create_comment(workspace, p, 'this is the comment', True) |
1116
|
|
|
|
1117
|
|
|
eq_(Content, c.__class__) |
1118
|
|
|
eq_(p.content_id, c.parent_id) |
1119
|
|
|
eq_(user, c.owner) |
1120
|
|
|
eq_(workspace, c.workspace) |
1121
|
|
|
eq_(CONTENT_TYPES.Comment.slug, c.type) |
1122
|
|
|
eq_('this is the comment', c.description) |
1123
|
|
|
eq_('', c.label) |
1124
|
|
|
eq_(ActionDescription.COMMENT, c.revision_type) |
1125
|
|
|
|
1126
|
|
View Code Duplication |
def test_unit_copy_file_different_label_different_parent_ok(self): |
|
|
|
|
1127
|
|
|
uapi = UserApi( |
1128
|
|
|
session=self.session, |
1129
|
|
|
config=self.app_config, |
1130
|
|
|
current_user=None, |
1131
|
|
|
) |
1132
|
|
|
group_api = GroupApi( |
1133
|
|
|
current_user=None, |
1134
|
|
|
session=self.session, |
1135
|
|
|
config=self.app_config |
1136
|
|
|
) |
1137
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1138
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1139
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1140
|
|
|
|
1141
|
|
|
user = uapi.create_minimal_user( |
1142
|
|
|
email='user1@user', |
1143
|
|
|
groups=groups, |
1144
|
|
|
save_now=True |
1145
|
|
|
) |
1146
|
|
|
user2 = uapi.create_minimal_user( |
1147
|
|
|
email='user2@user', |
1148
|
|
|
groups=groups, |
1149
|
|
|
save_now=True |
1150
|
|
|
) |
1151
|
|
|
workspace = WorkspaceApi( |
1152
|
|
|
current_user=user, |
1153
|
|
|
session=self.session, |
1154
|
|
|
config=self.app_config, |
1155
|
|
|
).create_workspace( |
1156
|
|
|
'test workspace', |
1157
|
|
|
save_now=True |
1158
|
|
|
) |
1159
|
|
|
RoleApi( |
1160
|
|
|
current_user=user, |
1161
|
|
|
session=self.session, |
1162
|
|
|
config=self.app_config, |
1163
|
|
|
).create_one( |
1164
|
|
|
user2, |
1165
|
|
|
workspace, |
1166
|
|
|
UserRoleInWorkspace.WORKSPACE_MANAGER, |
1167
|
|
|
with_notif=False |
1168
|
|
|
) |
1169
|
|
|
api = ContentApi( |
1170
|
|
|
current_user=user, |
1171
|
|
|
session=self.session, |
1172
|
|
|
config=self.app_config, |
1173
|
|
|
) |
1174
|
|
|
foldera = api.create( |
1175
|
|
|
CONTENT_TYPES.Folder.slug, |
1176
|
|
|
workspace, |
1177
|
|
|
None, |
1178
|
|
|
'folder a', |
1179
|
|
|
'', |
1180
|
|
|
True |
1181
|
|
|
) |
1182
|
|
|
with self.session.no_autoflush: |
1183
|
|
|
text_file = api.create( |
1184
|
|
|
content_type_slug=CONTENT_TYPES.File.slug, |
1185
|
|
|
workspace=workspace, |
1186
|
|
|
parent=foldera, |
1187
|
|
|
label='test_file', |
1188
|
|
|
do_save=False, |
1189
|
|
|
) |
1190
|
|
|
api.update_file_data( |
1191
|
|
|
text_file, |
1192
|
|
|
'test_file', |
1193
|
|
|
'text/plain', |
1194
|
|
|
b'test_content' |
1195
|
|
|
) |
1196
|
|
|
|
1197
|
|
|
api.save(text_file, ActionDescription.CREATION) |
1198
|
|
|
api2 = ContentApi( |
1199
|
|
|
current_user=user2, |
1200
|
|
|
session=self.session, |
1201
|
|
|
config=self.app_config, |
1202
|
|
|
) |
1203
|
|
|
workspace2 = WorkspaceApi( |
1204
|
|
|
current_user=user2, |
1205
|
|
|
session=self.session, |
1206
|
|
|
config=self.app_config, |
1207
|
|
|
).create_workspace( |
1208
|
|
|
'test workspace2', |
1209
|
|
|
save_now=True |
1210
|
|
|
) |
1211
|
|
|
folderb = api2.create( |
1212
|
|
|
CONTENT_TYPES.Folder.slug, |
1213
|
|
|
workspace2, |
1214
|
|
|
None, |
1215
|
|
|
'folder b', |
1216
|
|
|
'', |
1217
|
|
|
True |
1218
|
|
|
) |
1219
|
|
|
|
1220
|
|
|
api2.copy( |
1221
|
|
|
item=text_file, |
1222
|
|
|
new_parent=folderb, |
1223
|
|
|
new_label='test_file_copy' |
1224
|
|
|
) |
1225
|
|
|
|
1226
|
|
|
transaction.commit() |
1227
|
|
|
text_file_copy = api2.get_one_by_label_and_parent( |
1228
|
|
|
'test_file_copy', |
1229
|
|
|
folderb, |
1230
|
|
|
) |
1231
|
|
|
|
1232
|
|
|
assert text_file != text_file_copy |
1233
|
|
|
assert text_file_copy.content_id != text_file.content_id |
1234
|
|
|
assert text_file_copy.workspace_id == workspace2.workspace_id |
1235
|
|
|
assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8 |
1236
|
|
|
assert text_file_copy.depot_file.path != text_file.depot_file.path |
1237
|
|
|
assert text_file_copy.label == 'test_file_copy' |
1238
|
|
|
assert text_file_copy.type == text_file.type |
1239
|
|
|
assert text_file_copy.parent.content_id == folderb.content_id |
1240
|
|
|
assert text_file_copy.owner.user_id == user.user_id |
1241
|
|
|
assert text_file_copy.description == text_file.description |
1242
|
|
|
assert text_file_copy.file_extension == text_file.file_extension |
1243
|
|
|
assert text_file_copy.file_mimetype == text_file.file_mimetype |
1244
|
|
|
assert text_file_copy.revision_type == ActionDescription.COPY |
1245
|
|
|
assert len(text_file_copy.revisions) == len(text_file.revisions) + 1 |
1246
|
|
|
|
1247
|
|
View Code Duplication |
def test_unit_copy_file__same_label_different_parent_ok(self): |
|
|
|
|
1248
|
|
|
uapi = UserApi( |
1249
|
|
|
session=self.session, |
1250
|
|
|
config=self.app_config, |
1251
|
|
|
current_user=None, |
1252
|
|
|
) |
1253
|
|
|
group_api = GroupApi( |
1254
|
|
|
current_user=None, |
1255
|
|
|
session=self.session, |
1256
|
|
|
config=self.app_config, |
1257
|
|
|
) |
1258
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1259
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1260
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1261
|
|
|
|
1262
|
|
|
user = uapi.create_minimal_user( |
1263
|
|
|
email='user1@user', |
1264
|
|
|
groups=groups, |
1265
|
|
|
save_now=True |
1266
|
|
|
) |
1267
|
|
|
user2 = uapi.create_minimal_user( |
1268
|
|
|
email='user2@user', |
1269
|
|
|
groups=groups, |
1270
|
|
|
save_now=True |
1271
|
|
|
) |
1272
|
|
|
workspace = WorkspaceApi( |
1273
|
|
|
current_user=user, |
1274
|
|
|
session=self.session, |
1275
|
|
|
config=self.app_config, |
1276
|
|
|
).create_workspace( |
1277
|
|
|
'test workspace', |
1278
|
|
|
save_now=True |
1279
|
|
|
) |
1280
|
|
|
RoleApi( |
1281
|
|
|
current_user=user, |
1282
|
|
|
session=self.session, |
1283
|
|
|
config=self.app_config, |
1284
|
|
|
).create_one( |
1285
|
|
|
user2, |
1286
|
|
|
workspace, |
1287
|
|
|
UserRoleInWorkspace.WORKSPACE_MANAGER, |
1288
|
|
|
with_notif=False |
1289
|
|
|
) |
1290
|
|
|
api = ContentApi( |
1291
|
|
|
current_user=user, |
1292
|
|
|
session=self.session, |
1293
|
|
|
config=self.app_config, |
1294
|
|
|
) |
1295
|
|
|
foldera = api.create( |
1296
|
|
|
CONTENT_TYPES.Folder.slug, |
1297
|
|
|
workspace, |
1298
|
|
|
None, |
1299
|
|
|
'folder a', |
1300
|
|
|
'', |
1301
|
|
|
True |
1302
|
|
|
) |
1303
|
|
|
with self.session.no_autoflush: |
1304
|
|
|
text_file = api.create( |
1305
|
|
|
content_type_slug=CONTENT_TYPES.File.slug, |
1306
|
|
|
workspace=workspace, |
1307
|
|
|
parent=foldera, |
1308
|
|
|
label='test_file', |
1309
|
|
|
do_save=False, |
1310
|
|
|
) |
1311
|
|
|
api.update_file_data( |
1312
|
|
|
text_file, |
1313
|
|
|
'test_file', |
1314
|
|
|
'text/plain', |
1315
|
|
|
b'test_content' |
1316
|
|
|
) |
1317
|
|
|
|
1318
|
|
|
api.save(text_file, ActionDescription.CREATION) |
1319
|
|
|
api2 = ContentApi( |
1320
|
|
|
current_user=user2, |
1321
|
|
|
session=self.session, |
1322
|
|
|
config=self.app_config, |
1323
|
|
|
) |
1324
|
|
|
workspace2 = WorkspaceApi( |
1325
|
|
|
current_user=user2, |
1326
|
|
|
session=self.session, |
1327
|
|
|
config=self.app_config, |
1328
|
|
|
).create_workspace( |
1329
|
|
|
'test workspace2', |
1330
|
|
|
save_now=True |
1331
|
|
|
) |
1332
|
|
|
folderb = api2.create( |
1333
|
|
|
CONTENT_TYPES.Folder.slug, |
1334
|
|
|
workspace2, |
1335
|
|
|
None, |
1336
|
|
|
'folder b', |
1337
|
|
|
'', |
1338
|
|
|
True |
1339
|
|
|
) |
1340
|
|
|
api2.copy( |
1341
|
|
|
item=text_file, |
1342
|
|
|
new_parent=folderb, |
1343
|
|
|
) |
1344
|
|
|
|
1345
|
|
|
transaction.commit() |
1346
|
|
|
text_file_copy = api2.get_one_by_label_and_parent( |
1347
|
|
|
'test_file', |
1348
|
|
|
folderb, |
1349
|
|
|
) |
1350
|
|
|
|
1351
|
|
|
assert text_file != text_file_copy |
1352
|
|
|
assert text_file_copy.content_id != text_file.content_id |
1353
|
|
|
assert text_file_copy.workspace_id == workspace2.workspace_id |
1354
|
|
|
assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8 |
1355
|
|
|
assert text_file_copy.depot_file.path != text_file.depot_file.path |
1356
|
|
|
assert text_file_copy.label == text_file.label |
1357
|
|
|
assert text_file_copy.type == text_file.type |
1358
|
|
|
assert text_file_copy.parent.content_id == folderb.content_id |
1359
|
|
|
assert text_file_copy.owner.user_id == user.user_id |
1360
|
|
|
assert text_file_copy.description == text_file.description |
1361
|
|
|
assert text_file_copy.file_extension == text_file.file_extension |
1362
|
|
|
assert text_file_copy.file_mimetype == text_file.file_mimetype |
1363
|
|
|
assert text_file_copy.revision_type == ActionDescription.COPY |
1364
|
|
|
assert len(text_file_copy.revisions) == len(text_file.revisions) + 1 |
1365
|
|
|
|
1366
|
|
|
def test_unit_copy_file_different_label_same_parent_ok(self): |
1367
|
|
|
uapi = UserApi( |
1368
|
|
|
session=self.session, |
1369
|
|
|
config=self.app_config, |
1370
|
|
|
current_user=None, |
1371
|
|
|
) |
1372
|
|
|
group_api = GroupApi( |
1373
|
|
|
current_user=None, |
1374
|
|
|
session=self.session, |
1375
|
|
|
config=self.app_config, |
1376
|
|
|
) |
1377
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1378
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1379
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1380
|
|
|
|
1381
|
|
|
user = uapi.create_minimal_user( |
1382
|
|
|
email='user1@user', |
1383
|
|
|
groups=groups, |
1384
|
|
|
save_now=True, |
1385
|
|
|
) |
1386
|
|
|
user2 = uapi.create_minimal_user( |
1387
|
|
|
email='user2@user', |
1388
|
|
|
groups=groups, |
1389
|
|
|
save_now=True |
1390
|
|
|
) |
1391
|
|
|
workspace = WorkspaceApi( |
1392
|
|
|
current_user=user, |
1393
|
|
|
session=self.session, |
1394
|
|
|
config=self.app_config, |
1395
|
|
|
).create_workspace( |
1396
|
|
|
'test workspace', |
1397
|
|
|
save_now=True |
1398
|
|
|
) |
1399
|
|
|
RoleApi( |
1400
|
|
|
current_user=user, |
1401
|
|
|
session=self.session, |
1402
|
|
|
config=self.app_config, |
1403
|
|
|
).create_one( |
1404
|
|
|
user2, workspace, |
1405
|
|
|
UserRoleInWorkspace.WORKSPACE_MANAGER, |
1406
|
|
|
with_notif=False |
1407
|
|
|
) |
1408
|
|
|
api = ContentApi( |
1409
|
|
|
current_user=user, |
1410
|
|
|
session=self.session, |
1411
|
|
|
config=self.app_config, |
1412
|
|
|
) |
1413
|
|
|
foldera = api.create( |
1414
|
|
|
CONTENT_TYPES.Folder.slug, |
1415
|
|
|
workspace, |
1416
|
|
|
None, |
1417
|
|
|
'folder a', |
1418
|
|
|
'', |
1419
|
|
|
True |
1420
|
|
|
) |
1421
|
|
|
with self.session.no_autoflush: |
1422
|
|
|
text_file = api.create( |
1423
|
|
|
content_type_slug=CONTENT_TYPES.File.slug, |
1424
|
|
|
workspace=workspace, |
1425
|
|
|
parent=foldera, |
1426
|
|
|
label='test_file', |
1427
|
|
|
do_save=False, |
1428
|
|
|
) |
1429
|
|
|
api.update_file_data( |
1430
|
|
|
text_file, |
1431
|
|
|
'test_file', |
1432
|
|
|
'text/plain', |
1433
|
|
|
b'test_content' |
1434
|
|
|
) |
1435
|
|
|
|
1436
|
|
|
api.save( |
1437
|
|
|
text_file, |
1438
|
|
|
ActionDescription.CREATION |
1439
|
|
|
) |
1440
|
|
|
api2 = ContentApi( |
1441
|
|
|
current_user=user2, |
1442
|
|
|
session=self.session, |
1443
|
|
|
config=self.app_config, |
1444
|
|
|
) |
1445
|
|
|
|
1446
|
|
|
api2.copy( |
1447
|
|
|
item=text_file, |
1448
|
|
|
new_label='test_file_copy' |
1449
|
|
|
) |
1450
|
|
|
|
1451
|
|
|
transaction.commit() |
1452
|
|
|
text_file_copy = api2.get_one_by_label_and_parent( |
1453
|
|
|
'test_file_copy', |
1454
|
|
|
foldera, |
1455
|
|
|
) |
1456
|
|
|
|
1457
|
|
|
assert text_file != text_file_copy |
1458
|
|
|
assert text_file_copy.content_id != text_file.content_id |
1459
|
|
|
assert text_file_copy.workspace_id == workspace.workspace_id |
1460
|
|
|
assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8 |
1461
|
|
|
assert text_file_copy.depot_file.path != text_file.depot_file.path |
1462
|
|
|
assert text_file_copy.label == 'test_file_copy' |
1463
|
|
|
assert text_file_copy.type == text_file.type |
1464
|
|
|
assert text_file_copy.parent.content_id == foldera.content_id |
1465
|
|
|
assert text_file_copy.owner.user_id == user.user_id |
1466
|
|
|
assert text_file_copy.description == text_file.description |
1467
|
|
|
assert text_file_copy.file_extension == text_file.file_extension |
1468
|
|
|
assert text_file_copy.file_mimetype == text_file.file_mimetype |
1469
|
|
|
assert text_file_copy.revision_type == ActionDescription.COPY |
1470
|
|
|
assert len(text_file_copy.revisions) == len(text_file.revisions) + 1 |
1471
|
|
|
|
1472
|
|
|
def test_unit_copy_file_different_label_same_parent__err__label_already_used(self): |
1473
|
|
|
uapi = UserApi( |
1474
|
|
|
session=self.session, |
1475
|
|
|
config=self.app_config, |
1476
|
|
|
current_user=None, |
1477
|
|
|
) |
1478
|
|
|
group_api = GroupApi( |
1479
|
|
|
current_user=None, |
1480
|
|
|
session=self.session, |
1481
|
|
|
config=self.app_config, |
1482
|
|
|
) |
1483
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1484
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1485
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1486
|
|
|
|
1487
|
|
|
user = uapi.create_minimal_user( |
1488
|
|
|
email='user1@user', |
1489
|
|
|
groups=groups, |
1490
|
|
|
save_now=True, |
1491
|
|
|
) |
1492
|
|
|
user2 = uapi.create_minimal_user( |
1493
|
|
|
email='user2@user', |
1494
|
|
|
groups=groups, |
1495
|
|
|
save_now=True |
1496
|
|
|
) |
1497
|
|
|
workspace = WorkspaceApi( |
1498
|
|
|
current_user=user, |
1499
|
|
|
session=self.session, |
1500
|
|
|
config=self.app_config, |
1501
|
|
|
).create_workspace( |
1502
|
|
|
'test workspace', |
1503
|
|
|
save_now=True |
1504
|
|
|
) |
1505
|
|
|
RoleApi( |
1506
|
|
|
current_user=user, |
1507
|
|
|
session=self.session, |
1508
|
|
|
config=self.app_config, |
1509
|
|
|
).create_one( |
1510
|
|
|
user2, workspace, |
1511
|
|
|
UserRoleInWorkspace.WORKSPACE_MANAGER, |
1512
|
|
|
with_notif=False |
1513
|
|
|
) |
1514
|
|
|
api = ContentApi( |
1515
|
|
|
current_user=user, |
1516
|
|
|
session=self.session, |
1517
|
|
|
config=self.app_config, |
1518
|
|
|
) |
1519
|
|
|
foldera = api.create( |
1520
|
|
|
CONTENT_TYPES.Folder.slug, |
1521
|
|
|
workspace, |
1522
|
|
|
None, |
1523
|
|
|
'folder a', |
1524
|
|
|
'', |
1525
|
|
|
True |
1526
|
|
|
) |
1527
|
|
|
already_exist = api.create( |
1528
|
|
|
CONTENT_TYPES.Folder.slug, |
1529
|
|
|
workspace, |
1530
|
|
|
foldera, |
1531
|
|
|
'already_exist', |
1532
|
|
|
'', |
1533
|
|
|
True |
1534
|
|
|
) |
1535
|
|
|
with self.session.no_autoflush: |
1536
|
|
|
text_file = api.create( |
1537
|
|
|
content_type_slug=CONTENT_TYPES.File.slug, |
1538
|
|
|
workspace=workspace, |
1539
|
|
|
parent=foldera, |
1540
|
|
|
label='test_file', |
1541
|
|
|
do_save=False, |
1542
|
|
|
) |
1543
|
|
|
api.update_file_data( |
1544
|
|
|
text_file, |
1545
|
|
|
'test_file', |
1546
|
|
|
'text/plain', |
1547
|
|
|
b'test_content' |
1548
|
|
|
) |
1549
|
|
|
|
1550
|
|
|
api.save( |
1551
|
|
|
text_file, |
1552
|
|
|
ActionDescription.CREATION |
1553
|
|
|
) |
1554
|
|
|
api2 = ContentApi( |
1555
|
|
|
current_user=user2, |
1556
|
|
|
session=self.session, |
1557
|
|
|
config=self.app_config, |
1558
|
|
|
) |
1559
|
|
|
with pytest.raises(ContentLabelAlreadyUsedHere): |
1560
|
|
|
api2.copy( |
1561
|
|
|
item=text_file, |
1562
|
|
|
new_label='already_exist' |
1563
|
|
|
) |
1564
|
|
|
|
1565
|
|
|
transaction.commit() |
1566
|
|
|
new_already_exist = api2.get_one_by_label_and_parent( |
1567
|
|
|
'already_exist', |
1568
|
|
|
foldera, |
1569
|
|
|
) |
1570
|
|
|
|
1571
|
|
|
# file has no changed |
1572
|
|
|
assert new_already_exist.content_id == already_exist.content_id |
1573
|
|
|
|
1574
|
|
|
def test_mark_read__workspace(self): |
1575
|
|
|
uapi = UserApi( |
1576
|
|
|
session=self.session, |
1577
|
|
|
config=self.app_config, |
1578
|
|
|
current_user=None, |
1579
|
|
|
) |
1580
|
|
|
group_api = GroupApi( |
1581
|
|
|
current_user=None, |
1582
|
|
|
session=self.session, |
1583
|
|
|
config=self.app_config, |
1584
|
|
|
) |
1585
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1586
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1587
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1588
|
|
|
|
1589
|
|
|
user_a = uapi.create_minimal_user(email='this.is@user', |
1590
|
|
|
groups=groups, save_now=True) |
1591
|
|
|
user_b = uapi.create_minimal_user(email='[email protected]', |
1592
|
|
|
groups=groups, save_now=True) |
1593
|
|
|
|
1594
|
|
|
wapi = WorkspaceApi( |
1595
|
|
|
current_user=user_a, |
1596
|
|
|
session=self.session, |
1597
|
|
|
config=self.app_config, |
1598
|
|
|
) |
1599
|
|
|
workspace1 = wapi.create_workspace( |
1600
|
|
|
'test workspace n°1', |
1601
|
|
|
save_now=True) |
1602
|
|
|
workspace2 = wapi.create_workspace( |
1603
|
|
|
'test workspace n°2', |
1604
|
|
|
save_now=True) |
1605
|
|
|
|
1606
|
|
|
role_api1 = RoleApi( |
1607
|
|
|
current_user=user_a, |
1608
|
|
|
session=self.session, |
1609
|
|
|
config=self.app_config, |
1610
|
|
|
) |
1611
|
|
|
role_api1.create_one( |
1612
|
|
|
user_b, |
1613
|
|
|
workspace1, |
1614
|
|
|
UserRoleInWorkspace.READER, |
1615
|
|
|
False |
1616
|
|
|
) |
1617
|
|
|
|
1618
|
|
|
role_api2 = RoleApi( |
1619
|
|
|
current_user=user_b, |
1620
|
|
|
session=self.session, |
1621
|
|
|
config=self.app_config, |
1622
|
|
|
) |
1623
|
|
|
role_api2.create_one(user_b, workspace2, UserRoleInWorkspace.READER, |
1624
|
|
|
False) |
1625
|
|
|
|
1626
|
|
|
cont_api_a = ContentApi( |
1627
|
|
|
current_user=user_a, |
1628
|
|
|
session=self.session, |
1629
|
|
|
config=self.app_config, |
1630
|
|
|
) |
1631
|
|
|
cont_api_b = ContentApi( |
1632
|
|
|
current_user=user_b, |
1633
|
|
|
session=self.session, |
1634
|
|
|
config=self.app_config, |
1635
|
|
|
) |
1636
|
|
|
|
1637
|
|
|
# Creates page_1 & page_2 in workspace 1 |
1638
|
|
|
# and page_3 & page_4 in workspace 2 |
1639
|
|
|
page_1 = cont_api_a.create(CONTENT_TYPES.Page.slug, workspace1, None, |
1640
|
|
|
'this is a page', do_save=True) |
1641
|
|
|
page_2 = cont_api_a.create(CONTENT_TYPES.Page.slug, workspace1, None, |
1642
|
|
|
'this is page1', do_save=True) |
1643
|
|
|
page_3 = cont_api_a.create(CONTENT_TYPES.Thread.slug, workspace2, None, |
1644
|
|
|
'this is page2', do_save=True) |
1645
|
|
|
page_4 = cont_api_a.create(CONTENT_TYPES.File.slug, workspace2, None, |
1646
|
|
|
'this is page3', do_save=True) |
1647
|
|
|
|
1648
|
|
|
for rev in page_1.revisions: |
1649
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1650
|
|
|
for rev in page_2.revisions: |
1651
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1652
|
|
|
for rev in page_3.revisions: |
1653
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1654
|
|
|
for rev in page_4.revisions: |
1655
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1656
|
|
|
|
1657
|
|
|
# Set as read the workspace n°1 |
1658
|
|
|
cont_api_b.mark_read__workspace(workspace=workspace1) |
1659
|
|
|
|
1660
|
|
|
for rev in page_1.revisions: |
1661
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1662
|
|
|
for rev in page_2.revisions: |
1663
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1664
|
|
|
for rev in page_3.revisions: |
1665
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1666
|
|
|
for rev in page_4.revisions: |
1667
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1668
|
|
|
|
1669
|
|
|
# Set as read the workspace n°2 |
1670
|
|
|
cont_api_b.mark_read__workspace(workspace=workspace2) |
1671
|
|
|
|
1672
|
|
|
for rev in page_1.revisions: |
1673
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1674
|
|
|
for rev in page_2.revisions: |
1675
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1676
|
|
|
for rev in page_3.revisions: |
1677
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1678
|
|
|
for rev in page_4.revisions: |
1679
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1680
|
|
|
|
1681
|
|
|
def test_mark_read(self): |
1682
|
|
|
uapi = UserApi( |
1683
|
|
|
session=self.session, |
1684
|
|
|
config=self.app_config, |
1685
|
|
|
current_user=None, |
1686
|
|
|
) |
1687
|
|
|
group_api = GroupApi( |
1688
|
|
|
current_user=None, |
1689
|
|
|
session=self.session, |
1690
|
|
|
config = self.app_config, |
1691
|
|
|
) |
1692
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1693
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1694
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1695
|
|
|
|
1696
|
|
|
user_a = uapi.create_minimal_user( |
1697
|
|
|
email='this.is@user', |
1698
|
|
|
groups=groups, |
1699
|
|
|
save_now=True |
1700
|
|
|
) |
1701
|
|
|
user_b = uapi.create_minimal_user( |
1702
|
|
|
email='[email protected]', |
1703
|
|
|
groups=groups, |
1704
|
|
|
save_now=True |
1705
|
|
|
) |
1706
|
|
|
|
1707
|
|
|
wapi = WorkspaceApi( |
1708
|
|
|
current_user=user_a, |
1709
|
|
|
session=self.session, |
1710
|
|
|
config=self.app_config, |
1711
|
|
|
) |
1712
|
|
|
workspace_api = WorkspaceApi( |
1713
|
|
|
current_user=user_a, |
1714
|
|
|
session=self.session, |
1715
|
|
|
config=self.app_config, |
1716
|
|
|
) |
1717
|
|
|
workspace = wapi.create_workspace( |
1718
|
|
|
'test workspace', |
1719
|
|
|
save_now=True) |
1720
|
|
|
|
1721
|
|
|
role_api = RoleApi( |
1722
|
|
|
current_user=user_a, |
1723
|
|
|
session=self.session, |
1724
|
|
|
config=self.app_config, |
1725
|
|
|
) |
1726
|
|
|
role_api.create_one( |
1727
|
|
|
user_b, |
1728
|
|
|
workspace, |
1729
|
|
|
UserRoleInWorkspace.READER, |
1730
|
|
|
False |
1731
|
|
|
) |
1732
|
|
|
cont_api_a = ContentApi( |
1733
|
|
|
current_user=user_a, |
1734
|
|
|
session=self.session, |
1735
|
|
|
config=self.app_config, |
1736
|
|
|
) |
1737
|
|
|
cont_api_b = ContentApi( |
1738
|
|
|
current_user=user_b, |
1739
|
|
|
session=self.session, |
1740
|
|
|
config=self.app_config, |
1741
|
|
|
) |
1742
|
|
|
|
1743
|
|
|
page_1 = cont_api_a.create(CONTENT_TYPES.Page.slug, workspace, None, |
1744
|
|
|
'this is a page', do_save=True) |
1745
|
|
|
|
1746
|
|
|
for rev in page_1.revisions: |
1747
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1748
|
|
|
|
1749
|
|
|
cont_api_b.mark_read(page_1) |
1750
|
|
|
|
1751
|
|
|
for rev in page_1.revisions: |
1752
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1753
|
|
|
|
1754
|
|
|
def test_mark_read__all(self): |
1755
|
|
|
uapi = UserApi( |
1756
|
|
|
session=self.session, |
1757
|
|
|
config=self.app_config, |
1758
|
|
|
current_user=None, |
1759
|
|
|
) |
1760
|
|
|
group_api = GroupApi( |
1761
|
|
|
current_user=None, |
1762
|
|
|
session=self.session, |
1763
|
|
|
config=self.app_config, |
1764
|
|
|
) |
1765
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1766
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1767
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1768
|
|
|
|
1769
|
|
|
user_a = uapi.create_minimal_user( |
1770
|
|
|
email='this.is@user', |
1771
|
|
|
groups=groups, |
1772
|
|
|
save_now=True |
1773
|
|
|
) |
1774
|
|
|
user_b = uapi.create_minimal_user( |
1775
|
|
|
email='[email protected]', |
1776
|
|
|
groups=groups, |
1777
|
|
|
save_now=True |
1778
|
|
|
) |
1779
|
|
|
|
1780
|
|
|
wapi = WorkspaceApi( |
1781
|
|
|
current_user=user_a, |
1782
|
|
|
session=self.session, |
1783
|
|
|
config=self.app_config, |
1784
|
|
|
) |
1785
|
|
|
workspace = wapi.create_workspace( |
1786
|
|
|
'test workspace', |
1787
|
|
|
save_now=True) |
1788
|
|
|
|
1789
|
|
|
role_api = RoleApi( |
1790
|
|
|
current_user=user_a, |
1791
|
|
|
session=self.session, |
1792
|
|
|
config=self.app_config, |
1793
|
|
|
) |
1794
|
|
|
role_api.create_one( |
1795
|
|
|
user_b, |
1796
|
|
|
workspace, |
1797
|
|
|
UserRoleInWorkspace.READER, |
1798
|
|
|
False |
1799
|
|
|
) |
1800
|
|
|
cont_api_a = ContentApi( |
1801
|
|
|
current_user=user_a, |
1802
|
|
|
session=self.session, |
1803
|
|
|
config=self.app_config, |
1804
|
|
|
) |
1805
|
|
|
cont_api_b = ContentApi( |
1806
|
|
|
current_user=user_b, |
1807
|
|
|
session=self.session, |
1808
|
|
|
config=self.app_config, |
1809
|
|
|
) |
1810
|
|
|
|
1811
|
|
|
page_2 = cont_api_a.create( |
1812
|
|
|
CONTENT_TYPES.Page.slug, |
1813
|
|
|
workspace, |
1814
|
|
|
None, |
1815
|
|
|
'this is page1', |
1816
|
|
|
do_save=True |
1817
|
|
|
) |
1818
|
|
|
page_3 = cont_api_a.create( |
1819
|
|
|
CONTENT_TYPES.Thread.slug, |
1820
|
|
|
workspace, |
1821
|
|
|
None, |
1822
|
|
|
'this is page2', |
1823
|
|
|
do_save=True |
1824
|
|
|
) |
1825
|
|
|
page_4 = cont_api_a.create( |
1826
|
|
|
CONTENT_TYPES.File.slug, |
1827
|
|
|
workspace, |
1828
|
|
|
None, |
1829
|
|
|
'this is page3', |
1830
|
|
|
do_save=True |
1831
|
|
|
) |
1832
|
|
|
|
1833
|
|
|
for rev in page_2.revisions: |
1834
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1835
|
|
|
for rev in page_3.revisions: |
1836
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1837
|
|
|
for rev in page_4.revisions: |
1838
|
|
|
eq_(user_b not in rev.read_by.keys(), True) |
1839
|
|
|
|
1840
|
|
|
self.session.refresh(page_2) |
1841
|
|
|
self.session.refresh(page_3) |
1842
|
|
|
self.session.refresh(page_4) |
1843
|
|
|
|
1844
|
|
|
cont_api_b.mark_read__all() |
1845
|
|
|
|
1846
|
|
|
for rev in page_2.revisions: |
1847
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1848
|
|
|
for rev in page_3.revisions: |
1849
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1850
|
|
|
for rev in page_4.revisions: |
1851
|
|
|
eq_(user_b in rev.read_by.keys(), True) |
1852
|
|
|
|
1853
|
|
|
def test_unit__update__ok__nominal_case(self): |
1854
|
|
|
uapi = UserApi( |
1855
|
|
|
session=self.session, |
1856
|
|
|
config=self.app_config, |
1857
|
|
|
current_user=None, |
1858
|
|
|
) |
1859
|
|
|
group_api = GroupApi( |
1860
|
|
|
current_user=None, |
1861
|
|
|
session=self.session, |
1862
|
|
|
config=self.app_config, |
1863
|
|
|
) |
1864
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1865
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1866
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
1867
|
|
|
|
1868
|
|
|
user1 = uapi.create_minimal_user( |
1869
|
|
|
email='this.is@user', |
1870
|
|
|
groups=groups, |
1871
|
|
|
save_now=True |
1872
|
|
|
) |
1873
|
|
|
|
1874
|
|
|
workspace_api = WorkspaceApi( |
1875
|
|
|
current_user=user1, |
1876
|
|
|
session=self.session, |
1877
|
|
|
config=self.app_config, |
1878
|
|
|
) |
1879
|
|
|
workspace = workspace_api.create_workspace( |
1880
|
|
|
'test workspace', |
1881
|
|
|
save_now=True |
1882
|
|
|
) |
1883
|
|
|
|
1884
|
|
|
wid = workspace.workspace_id |
1885
|
|
|
|
1886
|
|
|
user2 = uapi.create_minimal_user('[email protected]') |
1887
|
|
|
uapi.save(user2) |
1888
|
|
|
|
1889
|
|
|
RoleApi( |
1890
|
|
|
current_user=user1, |
1891
|
|
|
session=self.session, |
1892
|
|
|
config=self.app_config, |
1893
|
|
|
).create_one( |
1894
|
|
|
user2, |
1895
|
|
|
workspace, |
1896
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
1897
|
|
|
with_notif=False, |
1898
|
|
|
flush=True |
1899
|
|
|
) |
1900
|
|
|
|
1901
|
|
|
# Test starts here |
1902
|
|
|
|
1903
|
|
|
api = ContentApi( |
1904
|
|
|
current_user=user1, |
1905
|
|
|
session=self.session, |
1906
|
|
|
config=self.app_config, |
1907
|
|
|
) |
1908
|
|
|
|
1909
|
|
|
p = api.create( |
1910
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
1911
|
|
|
workspace=workspace, |
1912
|
|
|
parent=None, |
1913
|
|
|
label='this_is_a_page', |
1914
|
|
|
do_save=True |
1915
|
|
|
) |
1916
|
|
|
|
1917
|
|
|
u1id = user1.user_id |
1918
|
|
|
u2id = user2.user_id |
1919
|
|
|
pcid = p.content_id |
1920
|
|
|
poid = p.owner_id |
1921
|
|
|
|
1922
|
|
|
transaction.commit() |
1923
|
|
|
|
1924
|
|
|
# Refresh instances after commit |
1925
|
|
|
user1 = uapi.get_one(u1id) |
1926
|
|
|
workspace = WorkspaceApi( |
1927
|
|
|
current_user=user1, |
1928
|
|
|
session=self.session, |
1929
|
|
|
config=self.app_config, |
1930
|
|
|
).get_one(wid) |
1931
|
|
|
api = ContentApi( |
1932
|
|
|
current_user=user1, |
1933
|
|
|
session=self.session, |
1934
|
|
|
config=self.app_config, |
1935
|
|
|
) |
1936
|
|
|
|
1937
|
|
|
content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
1938
|
|
|
eq_(u1id, content.owner_id) |
1939
|
|
|
eq_(poid, content.owner_id) |
1940
|
|
|
|
1941
|
|
|
u2 = UserApi( |
1942
|
|
|
session=self.session, |
1943
|
|
|
config=self.app_config, |
1944
|
|
|
current_user=None, |
1945
|
|
|
).get_one(u2id) |
1946
|
|
|
api2 = ContentApi( |
1947
|
|
|
current_user=u2, |
1948
|
|
|
session=self.session, |
1949
|
|
|
config=self.app_config, |
1950
|
|
|
) |
1951
|
|
|
content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
1952
|
|
|
with new_revision( |
1953
|
|
|
session=self.session, |
1954
|
|
|
tm=transaction.manager, |
1955
|
|
|
content=content2, |
1956
|
|
|
): |
1957
|
|
|
api2.update_content( |
1958
|
|
|
content2, |
1959
|
|
|
'this is an updated page', |
1960
|
|
|
'new content' |
1961
|
|
|
) |
1962
|
|
|
api2.save(content2) |
1963
|
|
|
transaction.commit() |
1964
|
|
|
|
1965
|
|
|
# Refresh instances after commit |
1966
|
|
|
user1 = uapi.get_one(u1id) |
1967
|
|
|
workspace = WorkspaceApi( |
1968
|
|
|
current_user=user1, |
1969
|
|
|
session=self.session, |
1970
|
|
|
config=self.app_config, |
1971
|
|
|
).get_one(wid) |
1972
|
|
|
api = ContentApi( |
1973
|
|
|
current_user=user1, |
1974
|
|
|
session=self.session, |
1975
|
|
|
config=self.app_config, |
1976
|
|
|
) |
1977
|
|
|
|
1978
|
|
|
updated = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
1979
|
|
|
eq_(u2id, updated.owner_id, |
1980
|
|
|
'the owner id should be {} (found {})'.format(u2id, |
1981
|
|
|
updated.owner_id)) |
1982
|
|
|
eq_('this is an updated page', updated.label) |
1983
|
|
|
eq_('new content', updated.description) |
1984
|
|
|
eq_(ActionDescription.EDITION, updated.revision_type) |
1985
|
|
|
|
1986
|
|
View Code Duplication |
def test_unit__update__err__label_already_used(self): |
|
|
|
|
1987
|
|
|
uapi = UserApi( |
1988
|
|
|
session=self.session, |
1989
|
|
|
config=self.app_config, |
1990
|
|
|
current_user=None, |
1991
|
|
|
) |
1992
|
|
|
group_api = GroupApi( |
1993
|
|
|
current_user=None, |
1994
|
|
|
session=self.session, |
1995
|
|
|
config=self.app_config, |
1996
|
|
|
) |
1997
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
1998
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
1999
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
2000
|
|
|
|
2001
|
|
|
user1 = uapi.create_minimal_user( |
2002
|
|
|
email='this.is@user', |
2003
|
|
|
groups=groups, |
2004
|
|
|
save_now=True |
2005
|
|
|
) |
2006
|
|
|
|
2007
|
|
|
workspace_api = WorkspaceApi( |
2008
|
|
|
current_user=user1, |
2009
|
|
|
session=self.session, |
2010
|
|
|
config=self.app_config, |
2011
|
|
|
) |
2012
|
|
|
workspace = workspace_api.create_workspace( |
2013
|
|
|
'test workspace', |
2014
|
|
|
save_now=True |
2015
|
|
|
) |
2016
|
|
|
|
2017
|
|
|
wid = workspace.workspace_id |
2018
|
|
|
|
2019
|
|
|
user2 = uapi.create_minimal_user('[email protected]') |
2020
|
|
|
uapi.save(user2) |
2021
|
|
|
|
2022
|
|
|
RoleApi( |
2023
|
|
|
current_user=user1, |
2024
|
|
|
session=self.session, |
2025
|
|
|
config=self.app_config, |
2026
|
|
|
).create_one( |
2027
|
|
|
user2, |
2028
|
|
|
workspace, |
2029
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
2030
|
|
|
with_notif=False, |
2031
|
|
|
flush=True |
2032
|
|
|
) |
2033
|
|
|
|
2034
|
|
|
# Test starts here |
2035
|
|
|
|
2036
|
|
|
api = ContentApi( |
2037
|
|
|
current_user=user1, |
2038
|
|
|
session=self.session, |
2039
|
|
|
config=self.app_config, |
2040
|
|
|
) |
2041
|
|
|
|
2042
|
|
|
p = api.create( |
2043
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
2044
|
|
|
workspace=workspace, |
2045
|
|
|
parent=None, |
2046
|
|
|
label='this_is_a_page', |
2047
|
|
|
do_save=True |
2048
|
|
|
) |
2049
|
|
|
p2 = api.create( |
2050
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
2051
|
|
|
workspace=workspace, |
2052
|
|
|
parent=None, |
2053
|
|
|
label='this_is_a_page2', |
2054
|
|
|
do_save=True |
2055
|
|
|
) |
2056
|
|
|
u1id = user1.user_id |
2057
|
|
|
u2id = user2.user_id |
2058
|
|
|
pcid = p.content_id |
2059
|
|
|
poid = p.owner_id |
2060
|
|
|
|
2061
|
|
|
transaction.commit() |
2062
|
|
|
|
2063
|
|
|
# Refresh instances after commit |
2064
|
|
|
user1 = uapi.get_one(u1id) |
2065
|
|
|
workspace = WorkspaceApi( |
2066
|
|
|
current_user=user1, |
2067
|
|
|
session=self.session, |
2068
|
|
|
config=self.app_config, |
2069
|
|
|
).get_one(wid) |
2070
|
|
|
api = ContentApi( |
2071
|
|
|
current_user=user1, |
2072
|
|
|
session=self.session, |
2073
|
|
|
config=self.app_config, |
2074
|
|
|
) |
2075
|
|
|
|
2076
|
|
|
content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2077
|
|
|
eq_(u1id, content.owner_id) |
2078
|
|
|
eq_(poid, content.owner_id) |
2079
|
|
|
|
2080
|
|
|
u2 = UserApi( |
2081
|
|
|
session=self.session, |
2082
|
|
|
config=self.app_config, |
2083
|
|
|
current_user=None, |
2084
|
|
|
).get_one(u2id) |
2085
|
|
|
api2 = ContentApi( |
2086
|
|
|
current_user=u2, |
2087
|
|
|
session=self.session, |
2088
|
|
|
config=self.app_config, |
2089
|
|
|
) |
2090
|
|
|
content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2091
|
|
|
with pytest.raises(ContentLabelAlreadyUsedHere): |
2092
|
|
|
with new_revision( |
2093
|
|
|
session=self.session, |
2094
|
|
|
tm=transaction.manager, |
2095
|
|
|
content=content2, |
2096
|
|
|
): |
2097
|
|
|
api2.update_content( |
2098
|
|
|
content2, |
2099
|
|
|
'this_is_a_page2', |
2100
|
|
|
'new content' |
2101
|
|
|
) |
2102
|
|
|
api2.save(content2) |
2103
|
|
|
content3 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2104
|
|
|
assert content3.label == 'this_is_a_page' |
2105
|
|
|
|
2106
|
|
View Code Duplication |
def test_unit__update__err__label_dont_change(self): |
|
|
|
|
2107
|
|
|
uapi = UserApi( |
2108
|
|
|
session=self.session, |
2109
|
|
|
config=self.app_config, |
2110
|
|
|
current_user=None, |
2111
|
|
|
) |
2112
|
|
|
group_api = GroupApi( |
2113
|
|
|
current_user=None, |
2114
|
|
|
session=self.session, |
2115
|
|
|
config=self.app_config, |
2116
|
|
|
) |
2117
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
2118
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
2119
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
2120
|
|
|
|
2121
|
|
|
user1 = uapi.create_minimal_user( |
2122
|
|
|
email='this.is@user', |
2123
|
|
|
groups=groups, |
2124
|
|
|
save_now=True |
2125
|
|
|
) |
2126
|
|
|
|
2127
|
|
|
workspace_api = WorkspaceApi( |
2128
|
|
|
current_user=user1, |
2129
|
|
|
session=self.session, |
2130
|
|
|
config=self.app_config, |
2131
|
|
|
) |
2132
|
|
|
workspace = workspace_api.create_workspace( |
2133
|
|
|
'test workspace', |
2134
|
|
|
save_now=True |
2135
|
|
|
) |
2136
|
|
|
|
2137
|
|
|
wid = workspace.workspace_id |
2138
|
|
|
|
2139
|
|
|
user2 = uapi.create_minimal_user('[email protected]') |
2140
|
|
|
uapi.save(user2) |
2141
|
|
|
|
2142
|
|
|
RoleApi( |
2143
|
|
|
current_user=user1, |
2144
|
|
|
session=self.session, |
2145
|
|
|
config=self.app_config, |
2146
|
|
|
).create_one( |
2147
|
|
|
user2, |
2148
|
|
|
workspace, |
2149
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
2150
|
|
|
with_notif=False, |
2151
|
|
|
flush=True |
2152
|
|
|
) |
2153
|
|
|
|
2154
|
|
|
# Test starts here |
2155
|
|
|
|
2156
|
|
|
api = ContentApi( |
2157
|
|
|
current_user=user1, |
2158
|
|
|
session=self.session, |
2159
|
|
|
config=self.app_config, |
2160
|
|
|
) |
2161
|
|
|
|
2162
|
|
|
p = api.create( |
2163
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
2164
|
|
|
workspace=workspace, |
2165
|
|
|
parent=None, |
2166
|
|
|
label='this_is_a_page', |
2167
|
|
|
do_save=True |
2168
|
|
|
) |
2169
|
|
|
p2 = api.create( |
2170
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
2171
|
|
|
workspace=workspace, |
2172
|
|
|
parent=None, |
2173
|
|
|
label='this_is_a_page2', |
2174
|
|
|
do_save=True |
2175
|
|
|
) |
2176
|
|
|
u1id = user1.user_id |
2177
|
|
|
u2id = user2.user_id |
2178
|
|
|
pcid = p.content_id |
2179
|
|
|
poid = p.owner_id |
2180
|
|
|
|
2181
|
|
|
transaction.commit() |
2182
|
|
|
|
2183
|
|
|
# Refresh instances after commit |
2184
|
|
|
user1 = uapi.get_one(u1id) |
2185
|
|
|
workspace = WorkspaceApi( |
2186
|
|
|
current_user=user1, |
2187
|
|
|
session=self.session, |
2188
|
|
|
config=self.app_config, |
2189
|
|
|
).get_one(wid) |
2190
|
|
|
api = ContentApi( |
2191
|
|
|
current_user=user1, |
2192
|
|
|
session=self.session, |
2193
|
|
|
config=self.app_config, |
2194
|
|
|
) |
2195
|
|
|
|
2196
|
|
|
content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2197
|
|
|
eq_(u1id, content.owner_id) |
2198
|
|
|
eq_(poid, content.owner_id) |
2199
|
|
|
|
2200
|
|
|
u2 = UserApi( |
2201
|
|
|
session=self.session, |
2202
|
|
|
config=self.app_config, |
2203
|
|
|
current_user=None, |
2204
|
|
|
).get_one(u2id) |
2205
|
|
|
api2 = ContentApi( |
2206
|
|
|
current_user=u2, |
2207
|
|
|
session=self.session, |
2208
|
|
|
config=self.app_config, |
2209
|
|
|
) |
2210
|
|
|
content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2211
|
|
|
with new_revision( |
2212
|
|
|
session=self.session, |
2213
|
|
|
tm=transaction.manager, |
2214
|
|
|
content=content2, |
2215
|
|
|
): |
2216
|
|
|
api2.update_content( |
2217
|
|
|
content2, |
2218
|
|
|
'this_is_a_page', |
2219
|
|
|
'new content' |
2220
|
|
|
) |
2221
|
|
|
api2.save(content2) |
2222
|
|
|
content3 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2223
|
|
|
assert content3.label == 'this_is_a_page' |
2224
|
|
|
|
2225
|
|
|
def test_update_no_change(self): |
2226
|
|
|
uapi = UserApi( |
2227
|
|
|
session=self.session, |
2228
|
|
|
config=self.app_config, |
2229
|
|
|
current_user=None, |
2230
|
|
|
) |
2231
|
|
|
group_api = GroupApi( |
2232
|
|
|
current_user=None, |
2233
|
|
|
session=self.session, |
2234
|
|
|
config = self.app_config, |
2235
|
|
|
) |
2236
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
2237
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
2238
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
2239
|
|
|
|
2240
|
|
|
user1 = uapi.create_minimal_user( |
2241
|
|
|
email='this.is@user', |
2242
|
|
|
groups=groups, |
2243
|
|
|
save_now=True, |
2244
|
|
|
) |
2245
|
|
|
|
2246
|
|
|
workspace = WorkspaceApi( |
2247
|
|
|
current_user=user1, |
2248
|
|
|
session=self.session, |
2249
|
|
|
config=self.app_config, |
2250
|
|
|
).create_workspace( |
2251
|
|
|
'test workspace', |
2252
|
|
|
save_now=True |
2253
|
|
|
) |
2254
|
|
|
|
2255
|
|
|
user2 = uapi.create_minimal_user('[email protected]') |
2256
|
|
|
uapi.save(user2) |
2257
|
|
|
|
2258
|
|
|
RoleApi( |
2259
|
|
|
current_user=user1, |
2260
|
|
|
session=self.session, |
2261
|
|
|
config=self.app_config, |
2262
|
|
|
).create_one( |
2263
|
|
|
user2, |
2264
|
|
|
workspace, |
2265
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
2266
|
|
|
with_notif=False, |
2267
|
|
|
flush=True |
2268
|
|
|
) |
2269
|
|
|
api = ContentApi( |
2270
|
|
|
current_user=user1, |
2271
|
|
|
session=self.session, |
2272
|
|
|
config=self.app_config, |
2273
|
|
|
) |
2274
|
|
|
with self.session.no_autoflush: |
2275
|
|
|
page = api.create( |
2276
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
2277
|
|
|
workspace=workspace, |
2278
|
|
|
label="same_content", |
2279
|
|
|
do_save=False |
2280
|
|
|
) |
2281
|
|
|
page.description = "Same_content_here" |
2282
|
|
|
api.save(page, ActionDescription.CREATION, do_notify=True) |
2283
|
|
|
transaction.commit() |
2284
|
|
|
|
2285
|
|
|
api2 = ContentApi( |
2286
|
|
|
current_user=user2, |
2287
|
|
|
session=self.session, |
2288
|
|
|
config=self.app_config, |
2289
|
|
|
) |
2290
|
|
|
content2 = api2.get_one(page.content_id, CONTENT_TYPES.Any_SLUG, workspace) |
2291
|
|
|
with new_revision( |
2292
|
|
|
session=self.session, |
2293
|
|
|
tm=transaction.manager, |
2294
|
|
|
content=content2, |
2295
|
|
|
): |
2296
|
|
|
with pytest.raises(SameValueError): |
2297
|
|
|
api2.update_content( |
2298
|
|
|
item=content2, |
2299
|
|
|
new_label='same_content', |
2300
|
|
|
new_content='Same_content_here' |
2301
|
|
|
) |
2302
|
|
|
api2.save(content2) |
2303
|
|
|
transaction.commit() |
2304
|
|
|
content3 = api2.get_one(page.content_id, CONTENT_TYPES.Any_SLUG, workspace) |
2305
|
|
|
assert content3.label == 'same_content' |
2306
|
|
|
|
2307
|
|
|
def test_update_file_data(self): |
2308
|
|
|
uapi = UserApi( |
2309
|
|
|
session=self.session, |
2310
|
|
|
config=self.app_config, |
2311
|
|
|
current_user=None, |
2312
|
|
|
) |
2313
|
|
|
group_api = GroupApi( |
2314
|
|
|
current_user=None, |
2315
|
|
|
session=self.session, |
2316
|
|
|
config=self.app_config, |
2317
|
|
|
) |
2318
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
2319
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
2320
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
2321
|
|
|
|
2322
|
|
|
user1 = uapi.create_minimal_user( |
2323
|
|
|
email='this.is@user', |
2324
|
|
|
groups=groups, |
2325
|
|
|
save_now=True |
2326
|
|
|
) |
2327
|
|
|
|
2328
|
|
|
workspace_api = WorkspaceApi( |
2329
|
|
|
current_user=user1, |
2330
|
|
|
session=self.session, |
2331
|
|
|
config=self.app_config, |
2332
|
|
|
) |
2333
|
|
|
workspace = workspace_api.create_workspace( |
2334
|
|
|
'test workspace', |
2335
|
|
|
save_now=True |
2336
|
|
|
) |
2337
|
|
|
wid = workspace.workspace_id |
2338
|
|
|
|
2339
|
|
|
user2 = uapi.create_minimal_user('[email protected]') |
2340
|
|
|
uapi.save(user2) |
2341
|
|
|
|
2342
|
|
|
RoleApi( |
2343
|
|
|
current_user=user1, |
2344
|
|
|
session=self.session, |
2345
|
|
|
config=self.app_config, |
2346
|
|
|
).create_one( |
2347
|
|
|
user2, |
2348
|
|
|
workspace, |
2349
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
2350
|
|
|
with_notif=True, |
2351
|
|
|
flush=True |
2352
|
|
|
) |
2353
|
|
|
|
2354
|
|
|
# Test starts here |
2355
|
|
|
api = ContentApi( |
2356
|
|
|
current_user=user1, |
2357
|
|
|
session=self.session, |
2358
|
|
|
config=self.app_config, |
2359
|
|
|
) |
2360
|
|
|
p = api.create( |
2361
|
|
|
content_type_slug=CONTENT_TYPES.File.slug, |
2362
|
|
|
workspace=workspace, |
2363
|
|
|
parent=None, |
2364
|
|
|
label='this_is_a_page', |
2365
|
|
|
do_save=True |
2366
|
|
|
) |
2367
|
|
|
|
2368
|
|
|
u1id = user1.user_id |
2369
|
|
|
u2id = user2.user_id |
2370
|
|
|
pcid = p.content_id |
2371
|
|
|
poid = p.owner_id |
2372
|
|
|
|
2373
|
|
|
api.save(p) |
2374
|
|
|
transaction.commit() |
2375
|
|
|
|
2376
|
|
|
# Refresh instances after commit |
2377
|
|
|
user1 = uapi.get_one(u1id) |
2378
|
|
|
workspace_api2 = WorkspaceApi( |
2379
|
|
|
current_user=user1, |
2380
|
|
|
session=self.session, |
2381
|
|
|
config=self.app_config, |
2382
|
|
|
) |
2383
|
|
|
workspace = workspace_api2.get_one(wid) |
2384
|
|
|
api = ContentApi( |
2385
|
|
|
current_user=user1, |
2386
|
|
|
session=self.session, |
2387
|
|
|
config=self.app_config, |
2388
|
|
|
) |
2389
|
|
|
|
2390
|
|
|
content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2391
|
|
|
eq_(u1id, content.owner_id) |
2392
|
|
|
eq_(poid, content.owner_id) |
2393
|
|
|
|
2394
|
|
|
u2 = UserApi( |
2395
|
|
|
current_user=None, |
2396
|
|
|
session=self.session, |
2397
|
|
|
config=self.app_config, |
2398
|
|
|
).get_one(u2id) |
2399
|
|
|
api2 = ContentApi( |
2400
|
|
|
current_user=u2, |
2401
|
|
|
session=self.session, |
2402
|
|
|
config=self.app_config, |
2403
|
|
|
) |
2404
|
|
|
content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2405
|
|
|
with new_revision( |
2406
|
|
|
session=self.session, |
2407
|
|
|
tm=transaction.manager, |
2408
|
|
|
content=content2, |
2409
|
|
|
): |
2410
|
|
|
api2.update_file_data( |
2411
|
|
|
content2, |
2412
|
|
|
'index.html', |
2413
|
|
|
'text/html', |
2414
|
|
|
b'<html>hello world</html>' |
2415
|
|
|
) |
2416
|
|
|
api2.save(content2) |
2417
|
|
|
transaction.commit() |
2418
|
|
|
|
2419
|
|
|
# Refresh instances after commit |
2420
|
|
|
user1 = uapi.get_one(u1id) |
2421
|
|
|
workspace = WorkspaceApi( |
2422
|
|
|
current_user=user1, |
2423
|
|
|
session=self.session, |
2424
|
|
|
config=self.app_config, |
2425
|
|
|
).get_one(wid) |
2426
|
|
|
|
2427
|
|
|
updated = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2428
|
|
|
eq_(u2id, updated.owner_id, |
2429
|
|
|
'the owner id should be {} (found {})'.format(u2id, |
2430
|
|
|
updated.owner_id)) |
2431
|
|
|
eq_('index.html', updated.file_name) |
2432
|
|
|
eq_('text/html', updated.file_mimetype) |
2433
|
|
|
eq_(b'<html>hello world</html>', updated.depot_file.file.read()) |
2434
|
|
|
eq_(ActionDescription.REVISION, updated.revision_type) |
2435
|
|
|
|
2436
|
|
|
def test_update_no_change(self): |
2437
|
|
|
uapi = UserApi( |
2438
|
|
|
session=self.session, |
2439
|
|
|
config=self.app_config, |
2440
|
|
|
current_user=None, |
2441
|
|
|
) |
2442
|
|
|
group_api = GroupApi( |
2443
|
|
|
current_user=None, |
2444
|
|
|
session=self.session, |
2445
|
|
|
config=self.app_config, |
2446
|
|
|
) |
2447
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
2448
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
2449
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
2450
|
|
|
|
2451
|
|
|
user1 = uapi.create_minimal_user( |
2452
|
|
|
email='this.is@user', |
2453
|
|
|
groups=groups, |
2454
|
|
|
save_now=True, |
2455
|
|
|
) |
2456
|
|
|
|
2457
|
|
|
workspace_api = WorkspaceApi( |
2458
|
|
|
current_user=user1, |
2459
|
|
|
session=self.session, |
2460
|
|
|
config=self.app_config, |
2461
|
|
|
) |
2462
|
|
|
workspace = workspace_api.create_workspace( |
2463
|
|
|
'test workspace', |
2464
|
|
|
save_now=True |
2465
|
|
|
) |
2466
|
|
|
|
2467
|
|
|
user2 = uapi.create_minimal_user('[email protected]') |
2468
|
|
|
uapi.save(user2) |
2469
|
|
|
|
2470
|
|
|
RoleApi( |
2471
|
|
|
current_user=user1, |
2472
|
|
|
session=self.session, |
2473
|
|
|
config=self.app_config, |
2474
|
|
|
).create_one( |
2475
|
|
|
user2, |
2476
|
|
|
workspace, |
2477
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
2478
|
|
|
with_notif=False, |
2479
|
|
|
flush=True |
2480
|
|
|
) |
2481
|
|
|
api = ContentApi( |
2482
|
|
|
current_user=user1, |
2483
|
|
|
session=self.session, |
2484
|
|
|
config=self.app_config, |
2485
|
|
|
) |
2486
|
|
|
with self.session.no_autoflush: |
2487
|
|
|
page = api.create( |
2488
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
2489
|
|
|
workspace=workspace, |
2490
|
|
|
label="same_content", |
2491
|
|
|
do_save=False |
2492
|
|
|
) |
2493
|
|
|
api.update_file_data( |
2494
|
|
|
page, |
2495
|
|
|
'index.html', |
2496
|
|
|
'text/html', |
2497
|
|
|
b'<html>Same Content Here</html>' |
2498
|
|
|
) |
2499
|
|
|
api.save(page, ActionDescription.CREATION, do_notify=True) |
2500
|
|
|
transaction.commit() |
2501
|
|
|
|
2502
|
|
|
api2 = ContentApi( |
2503
|
|
|
current_user=user2, |
2504
|
|
|
session=self.session, |
2505
|
|
|
config=self.app_config, |
2506
|
|
|
) |
2507
|
|
|
content2 = api2.get_one(page.content_id, CONTENT_TYPES.Any_SLUG, workspace) |
2508
|
|
|
with new_revision( |
2509
|
|
|
session=self.session, |
2510
|
|
|
tm=transaction.manager, |
2511
|
|
|
content=content2, |
2512
|
|
|
): |
2513
|
|
|
with pytest.raises(SameValueError): |
2514
|
|
|
api2.update_file_data( |
2515
|
|
|
page, |
2516
|
|
|
'index.html', |
2517
|
|
|
'text/html', |
2518
|
|
|
b'<html>Same Content Here</html>' |
2519
|
|
|
) |
2520
|
|
|
api2.save(content2) |
2521
|
|
|
transaction.commit() |
2522
|
|
|
|
2523
|
|
View Code Duplication |
def test_archive_unarchive(self): |
|
|
|
|
2524
|
|
|
uapi = UserApi( |
2525
|
|
|
session=self.session, |
2526
|
|
|
config=self.app_config, |
2527
|
|
|
current_user=None, |
2528
|
|
|
) |
2529
|
|
|
group_api = GroupApi( |
2530
|
|
|
current_user=None, |
2531
|
|
|
session=self.session, |
2532
|
|
|
config=self.app_config, |
2533
|
|
|
) |
2534
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
2535
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
2536
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
2537
|
|
|
|
2538
|
|
|
user1 = uapi.create_minimal_user( |
2539
|
|
|
email='this.is@user', |
2540
|
|
|
groups=groups, |
2541
|
|
|
save_now=True |
2542
|
|
|
) |
2543
|
|
|
u1id = user1.user_id |
2544
|
|
|
|
2545
|
|
|
workspace_api = WorkspaceApi( |
2546
|
|
|
current_user=user1, |
2547
|
|
|
session=self.session, |
2548
|
|
|
config=self.app_config, |
2549
|
|
|
) |
2550
|
|
|
workspace = workspace_api.create_workspace( |
2551
|
|
|
'test workspace', |
2552
|
|
|
save_now=True |
2553
|
|
|
) |
2554
|
|
|
wid = workspace.workspace_id |
2555
|
|
|
|
2556
|
|
|
user2 = uapi.create_minimal_user('[email protected]') |
2557
|
|
|
uapi.save(user2) |
2558
|
|
|
|
2559
|
|
|
RoleApi( |
2560
|
|
|
current_user=user1, |
2561
|
|
|
session=self.session, |
2562
|
|
|
config=self.app_config, |
2563
|
|
|
).create_one( |
2564
|
|
|
user2, |
2565
|
|
|
workspace, |
2566
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
2567
|
|
|
with_notif=True, |
2568
|
|
|
flush=True |
2569
|
|
|
) |
2570
|
|
|
|
2571
|
|
|
# show archived is used at the top end of the test |
2572
|
|
|
api = ContentApi( |
2573
|
|
|
current_user=user1, |
2574
|
|
|
session=self.session, |
2575
|
|
|
show_archived=True, |
2576
|
|
|
config=self.app_config, |
2577
|
|
|
) |
2578
|
|
|
p = api.create( |
2579
|
|
|
content_type_slug=CONTENT_TYPES.File.slug, |
2580
|
|
|
workspace=workspace, |
2581
|
|
|
parent=None, |
2582
|
|
|
label='this_is_a_page', |
2583
|
|
|
do_save=True |
2584
|
|
|
) |
2585
|
|
|
|
2586
|
|
|
u1id = user1.user_id |
2587
|
|
|
u2id = user2.user_id |
2588
|
|
|
pcid = p.content_id |
2589
|
|
|
poid = p.owner_id |
2590
|
|
|
|
2591
|
|
|
transaction.commit() |
2592
|
|
|
|
2593
|
|
|
#### |
2594
|
|
|
|
2595
|
|
|
# refresh after commit |
2596
|
|
|
user1 = UserApi( |
2597
|
|
|
current_user=None, |
2598
|
|
|
config=self.app_config, |
2599
|
|
|
session=self.session |
2600
|
|
|
).get_one(u1id) |
2601
|
|
|
workspace = WorkspaceApi( |
2602
|
|
|
current_user=user1, |
2603
|
|
|
session=self.session, |
2604
|
|
|
config=self.app_config, |
2605
|
|
|
).get_one(wid) |
2606
|
|
|
|
2607
|
|
|
content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2608
|
|
|
eq_(u1id, content.owner_id) |
2609
|
|
|
eq_(poid, content.owner_id) |
2610
|
|
|
|
2611
|
|
|
u2api = UserApi( |
2612
|
|
|
session=self.session, |
2613
|
|
|
config=self.app_config, |
2614
|
|
|
current_user=None, |
2615
|
|
|
) |
2616
|
|
|
u2 = u2api.get_one(u2id) |
2617
|
|
|
api2 = ContentApi( |
2618
|
|
|
current_user=u2, |
2619
|
|
|
session=self.session, |
2620
|
|
|
config=self.app_config, |
2621
|
|
|
show_archived=True, |
2622
|
|
|
) |
2623
|
|
|
content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2624
|
|
|
with new_revision( |
2625
|
|
|
session=self.session, |
2626
|
|
|
tm=transaction.manager, |
2627
|
|
|
content=content2, |
2628
|
|
|
): |
2629
|
|
|
api2.archive(content2) |
2630
|
|
|
api2.save(content2) |
2631
|
|
|
transaction.commit() |
2632
|
|
|
|
2633
|
|
|
# refresh after commit |
2634
|
|
|
user1 = UserApi( |
2635
|
|
|
current_user=None, |
2636
|
|
|
session=self.session, |
2637
|
|
|
config=self.app_config, |
2638
|
|
|
).get_one(u1id) |
2639
|
|
|
workspace = WorkspaceApi( |
2640
|
|
|
current_user=user1, |
2641
|
|
|
session=self.session, |
2642
|
|
|
config=self.app_config, |
2643
|
|
|
).get_one(wid) |
2644
|
|
|
u2 = UserApi( |
2645
|
|
|
current_user=None, |
2646
|
|
|
session=self.session, |
2647
|
|
|
config=self.app_config, |
2648
|
|
|
).get_one(u2id) |
2649
|
|
|
api = ContentApi( |
2650
|
|
|
current_user=user1, |
2651
|
|
|
session=self.session, |
2652
|
|
|
config=self.app_config, |
2653
|
|
|
show_archived=True, |
2654
|
|
|
) |
2655
|
|
|
api2 = ContentApi( |
2656
|
|
|
current_user=u2, |
2657
|
|
|
session=self.session, |
2658
|
|
|
config=self.app_config, |
2659
|
|
|
show_archived=True, |
2660
|
|
|
) |
2661
|
|
|
|
2662
|
|
|
updated = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2663
|
|
|
eq_(u2id, updated.owner_id, |
2664
|
|
|
'the owner id should be {} (found {})'.format(u2id, |
2665
|
|
|
updated.owner_id)) |
2666
|
|
|
eq_(True, updated.is_archived) |
2667
|
|
|
eq_(ActionDescription.ARCHIVING, updated.revision_type) |
2668
|
|
|
|
2669
|
|
|
#### |
2670
|
|
|
|
2671
|
|
|
updated2 = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2672
|
|
|
with new_revision( |
2673
|
|
|
session=self.session, |
2674
|
|
|
tm=transaction.manager, |
2675
|
|
|
content=updated, |
2676
|
|
|
|
2677
|
|
|
): |
2678
|
|
|
api.unarchive(updated) |
2679
|
|
|
api.save(updated2) |
2680
|
|
|
eq_(False, updated2.is_archived) |
2681
|
|
|
eq_(ActionDescription.UNARCHIVING, updated2.revision_type) |
2682
|
|
|
eq_(u1id, updated2.owner_id) |
2683
|
|
|
|
2684
|
|
View Code Duplication |
def test_delete_undelete(self): |
|
|
|
|
2685
|
|
|
uapi = UserApi( |
2686
|
|
|
session=self.session, |
2687
|
|
|
config=self.app_config, |
2688
|
|
|
current_user=None, |
2689
|
|
|
) |
2690
|
|
|
group_api = GroupApi( |
2691
|
|
|
current_user=None, |
2692
|
|
|
session=self.session, |
2693
|
|
|
config=self.app_config, |
2694
|
|
|
) |
2695
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
2696
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
2697
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
2698
|
|
|
|
2699
|
|
|
user1 = uapi.create_minimal_user( |
2700
|
|
|
email='this.is@user', |
2701
|
|
|
groups=groups, |
2702
|
|
|
save_now=True |
2703
|
|
|
) |
2704
|
|
|
u1id = user1.user_id |
2705
|
|
|
|
2706
|
|
|
workspace_api = WorkspaceApi( |
2707
|
|
|
current_user=user1, |
2708
|
|
|
session=self.session, |
2709
|
|
|
config=self.app_config, |
2710
|
|
|
) |
2711
|
|
|
workspace = workspace_api.create_workspace( |
2712
|
|
|
'test workspace', |
2713
|
|
|
save_now=True |
2714
|
|
|
) |
2715
|
|
|
wid = workspace.workspace_id |
2716
|
|
|
|
2717
|
|
|
user2 = uapi.create_minimal_user('[email protected]') |
2718
|
|
|
uapi.save(user2) |
2719
|
|
|
|
2720
|
|
|
RoleApi( |
2721
|
|
|
current_user=user1, |
2722
|
|
|
session=self.session, |
2723
|
|
|
config=self.app_config, |
2724
|
|
|
).create_one( |
2725
|
|
|
user2, |
2726
|
|
|
workspace, |
2727
|
|
|
UserRoleInWorkspace.CONTENT_MANAGER, |
2728
|
|
|
with_notif=True, |
2729
|
|
|
flush=True |
2730
|
|
|
) |
2731
|
|
|
|
2732
|
|
|
# show archived is used at the top end of the test |
2733
|
|
|
api = ContentApi( |
2734
|
|
|
current_user=user1, |
2735
|
|
|
session=self.session, |
2736
|
|
|
config=self.app_config, |
2737
|
|
|
show_deleted=True, |
2738
|
|
|
) |
2739
|
|
|
p = api.create( |
2740
|
|
|
content_type_slug=CONTENT_TYPES.File.slug, |
2741
|
|
|
workspace=workspace, |
2742
|
|
|
parent=None, |
2743
|
|
|
label='this_is_a_page', |
2744
|
|
|
do_save=True |
2745
|
|
|
) |
2746
|
|
|
|
2747
|
|
|
u1id = user1.user_id |
2748
|
|
|
u2id = user2.user_id |
2749
|
|
|
pcid = p.content_id |
2750
|
|
|
poid = p.owner_id |
2751
|
|
|
|
2752
|
|
|
transaction.commit() |
2753
|
|
|
|
2754
|
|
|
#### |
2755
|
|
|
user1 = UserApi( |
2756
|
|
|
current_user=None, |
2757
|
|
|
session=self.session, |
2758
|
|
|
config=self.app_config, |
2759
|
|
|
).get_one(u1id) |
2760
|
|
|
workspace = WorkspaceApi( |
2761
|
|
|
current_user=user1, |
2762
|
|
|
session=self.session, |
2763
|
|
|
config=self.app_config, |
2764
|
|
|
).get_one(wid) |
2765
|
|
|
|
2766
|
|
|
content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2767
|
|
|
eq_(u1id, content.owner_id) |
2768
|
|
|
eq_(poid, content.owner_id) |
2769
|
|
|
|
2770
|
|
|
u2 = UserApi( |
2771
|
|
|
current_user=None, |
2772
|
|
|
session=self.session, |
2773
|
|
|
config=self.app_config, |
2774
|
|
|
).get_one(u2id) |
2775
|
|
|
api2 = ContentApi( |
2776
|
|
|
current_user=u2, |
2777
|
|
|
session=self.session, |
2778
|
|
|
config=self.app_config, |
2779
|
|
|
show_deleted=True, |
2780
|
|
|
) |
2781
|
|
|
content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2782
|
|
|
with new_revision( |
2783
|
|
|
session=self.session, |
2784
|
|
|
tm=transaction.manager, |
2785
|
|
|
content=content2, |
2786
|
|
|
): |
2787
|
|
|
api2.delete(content2) |
2788
|
|
|
api2.save(content2) |
2789
|
|
|
transaction.commit() |
2790
|
|
|
|
2791
|
|
|
#### |
2792
|
|
|
|
2793
|
|
|
user1 = UserApi( |
2794
|
|
|
current_user=None, |
2795
|
|
|
session=self.session, |
2796
|
|
|
config=self.app_config, |
2797
|
|
|
).get_one(u1id) |
2798
|
|
|
workspace = WorkspaceApi( |
2799
|
|
|
current_user=user1, |
2800
|
|
|
session=self.session, |
2801
|
|
|
config=self.app_config, |
2802
|
|
|
).get_one(wid) |
2803
|
|
|
# show archived is used at the top end of the test |
2804
|
|
|
api = ContentApi( |
2805
|
|
|
current_user=user1, |
2806
|
|
|
session=self.session, |
2807
|
|
|
config=self.app_config, |
2808
|
|
|
show_deleted=True, |
2809
|
|
|
) |
2810
|
|
|
u2 = UserApi( |
2811
|
|
|
current_user=None, |
2812
|
|
|
session=self.session, |
2813
|
|
|
config=self.app_config, |
2814
|
|
|
).get_one(u2id) |
2815
|
|
|
api2 = ContentApi( |
2816
|
|
|
current_user=u2, |
2817
|
|
|
session=self.session, |
2818
|
|
|
config=self.app_config, |
2819
|
|
|
show_deleted=True |
2820
|
|
|
) |
2821
|
|
|
|
2822
|
|
|
updated = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2823
|
|
|
eq_(u2id, updated.owner_id, |
2824
|
|
|
'the owner id should be {} (found {})'.format(u2id, |
2825
|
|
|
updated.owner_id)) |
2826
|
|
|
eq_(True, updated.is_deleted) |
2827
|
|
|
eq_(ActionDescription.DELETION, updated.revision_type) |
2828
|
|
|
|
2829
|
|
|
#### |
2830
|
|
|
|
2831
|
|
|
updated2 = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace) |
2832
|
|
|
with new_revision( |
2833
|
|
|
tm=transaction.manager, |
2834
|
|
|
session=self.session, |
2835
|
|
|
content=updated2, |
2836
|
|
|
): |
2837
|
|
|
api.undelete(updated2) |
2838
|
|
|
api.save(updated2) |
2839
|
|
|
eq_(False, updated2.is_deleted) |
2840
|
|
|
eq_(ActionDescription.UNDELETION, updated2.revision_type) |
2841
|
|
|
eq_(u1id, updated2.owner_id) |
2842
|
|
|
|
2843
|
|
|
def test_unit__get_last_active__ok__nominal_case(self): |
2844
|
|
|
uapi = UserApi( |
2845
|
|
|
session=self.session, |
2846
|
|
|
config=self.app_config, |
2847
|
|
|
current_user=None, |
2848
|
|
|
) |
2849
|
|
|
group_api = GroupApi( |
2850
|
|
|
current_user=None, |
2851
|
|
|
session=self.session, |
2852
|
|
|
config=self.app_config, |
2853
|
|
|
) |
2854
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
2855
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
2856
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
2857
|
|
|
|
2858
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
2859
|
|
|
groups=groups, save_now=True) |
2860
|
|
|
workspace = WorkspaceApi( |
2861
|
|
|
current_user=user, |
2862
|
|
|
session=self.session, |
2863
|
|
|
config=self.app_config, |
2864
|
|
|
).create_workspace( |
2865
|
|
|
'test workspace', |
2866
|
|
|
save_now=True |
2867
|
|
|
) |
2868
|
|
|
workspace2 = WorkspaceApi( |
2869
|
|
|
current_user=user, |
2870
|
|
|
session=self.session, |
2871
|
|
|
config=self.app_config, |
2872
|
|
|
).create_workspace( |
2873
|
|
|
'test workspace2', |
2874
|
|
|
save_now=True |
2875
|
|
|
) |
2876
|
|
|
|
2877
|
|
|
api = ContentApi( |
2878
|
|
|
current_user=user, |
2879
|
|
|
session=self.session, |
2880
|
|
|
config=self.app_config, |
2881
|
|
|
) |
2882
|
|
|
main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True) # nopep8 |
2883
|
|
|
main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
2884
|
|
|
# creation order test |
2885
|
|
|
firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
2886
|
|
|
secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True) # nopep8 |
2887
|
|
|
# update order test |
2888
|
|
|
firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True) # nopep8 |
2889
|
|
|
secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True) # nopep8 |
2890
|
|
|
with new_revision( |
2891
|
|
|
session=self.session, |
2892
|
|
|
tm=transaction.manager, |
2893
|
|
|
content=firstly_created_but_recently_updated, |
2894
|
|
|
): |
2895
|
|
|
firstly_created_but_recently_updated.description = 'Just an update' |
2896
|
|
|
api.save(firstly_created_but_recently_updated) |
2897
|
|
|
# comment change order |
2898
|
|
|
firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True) # nopep8 |
2899
|
|
|
secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8 |
2900
|
|
|
comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8 |
2901
|
|
|
|
2902
|
|
|
content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2 ,main_folder_workspace2, 'content_workspace_2', '',True) # nopep8 |
2903
|
|
|
last_actives = api.get_last_active() |
2904
|
|
|
assert len(last_actives) == 9 |
2905
|
|
|
# workspace_2 content |
2906
|
|
|
assert last_actives[0] == content_workspace_2 |
2907
|
|
|
# comment is newest than page2 |
2908
|
|
|
assert last_actives[1] == firstly_created_but_recently_commented |
2909
|
|
|
assert last_actives[2] == secondly_created_but_not_commented |
2910
|
|
|
# last updated content is newer than other one despite creation |
2911
|
|
|
# of the other is more recent |
2912
|
|
|
assert last_actives[3] == firstly_created_but_recently_updated |
2913
|
|
|
assert last_actives[4] == secondly_created_but_not_updated |
2914
|
|
|
# creation order is inverted here as last created is last active |
2915
|
|
|
assert last_actives[5] == secondly_created |
2916
|
|
|
assert last_actives[6] == firstly_created |
2917
|
|
|
# folder subcontent modification does not change folder order |
2918
|
|
|
assert last_actives[7] == main_folder |
2919
|
|
|
# folder subcontent modification does not change folder order |
2920
|
|
|
# (workspace2) |
2921
|
|
|
assert last_actives[8] == main_folder_workspace2 |
2922
|
|
|
|
2923
|
|
|
def test_unit__get_last_active__ok__do_no_show_deleted_archived(self): |
2924
|
|
|
uapi = UserApi( |
2925
|
|
|
session=self.session, |
2926
|
|
|
config=self.app_config, |
2927
|
|
|
current_user=None, |
2928
|
|
|
) |
2929
|
|
|
group_api = GroupApi( |
2930
|
|
|
current_user=None, |
2931
|
|
|
session=self.session, |
2932
|
|
|
config=self.app_config, |
2933
|
|
|
) |
2934
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
2935
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
2936
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
2937
|
|
|
|
2938
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
2939
|
|
|
groups=groups, save_now=True) |
2940
|
|
|
workspace = WorkspaceApi( |
2941
|
|
|
current_user=user, |
2942
|
|
|
session=self.session, |
2943
|
|
|
config=self.app_config, |
2944
|
|
|
).create_workspace( |
2945
|
|
|
'test workspace', |
2946
|
|
|
save_now=True |
2947
|
|
|
) |
2948
|
|
|
workspace2 = WorkspaceApi( |
2949
|
|
|
current_user=user, |
2950
|
|
|
session=self.session, |
2951
|
|
|
config=self.app_config, |
2952
|
|
|
).create_workspace( |
2953
|
|
|
'test workspace2', |
2954
|
|
|
save_now=True |
2955
|
|
|
) |
2956
|
|
|
|
2957
|
|
|
api = ContentApi( |
2958
|
|
|
current_user=user, |
2959
|
|
|
session=self.session, |
2960
|
|
|
config=self.app_config, |
2961
|
|
|
show_deleted=False, |
2962
|
|
|
show_archived=False, |
2963
|
|
|
) |
2964
|
|
|
main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
2965
|
|
|
archived = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'archived', '', True) # nopep8 |
2966
|
|
|
deleted = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'deleted', '', True) # nopep8 |
2967
|
|
|
comment_archived = api.create_comment(workspace, parent=archived, content='just a comment', do_save=True) # nopep8 |
2968
|
|
|
comment_deleted = api.create_comment(workspace, parent=deleted, content='just a comment', do_save=True) # nopep8 |
2969
|
|
|
with new_revision( |
2970
|
|
|
session=self.session, |
2971
|
|
|
tm=transaction.manager, |
2972
|
|
|
content=archived, |
2973
|
|
|
): |
2974
|
|
|
api.archive(archived) |
2975
|
|
|
api.save(archived) |
2976
|
|
|
|
2977
|
|
|
with new_revision( |
2978
|
|
|
session=self.session, |
2979
|
|
|
tm=transaction.manager, |
2980
|
|
|
content=deleted, |
2981
|
|
|
): |
2982
|
|
|
api.delete(deleted) |
2983
|
|
|
api.save(deleted) |
2984
|
|
|
normal = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'normal', '', True) # nopep8 |
2985
|
|
|
comment_normal = api.create_comment(workspace, parent=normal, content='just a comment', do_save=True) # nopep8 |
2986
|
|
|
|
2987
|
|
|
last_actives = api.get_last_active() |
2988
|
|
|
assert len(last_actives) == 2 |
2989
|
|
|
assert last_actives[0].content_id == normal.content_id |
2990
|
|
|
assert last_actives[1].content_id == main_folder.content_id |
2991
|
|
|
|
2992
|
|
|
|
2993
|
|
|
api._show_deleted = True |
2994
|
|
|
api._show_archived = False |
2995
|
|
|
last_actives = api.get_last_active() |
2996
|
|
|
assert len(last_actives) == 3 |
2997
|
|
|
assert last_actives[0] == normal |
2998
|
|
|
assert last_actives[1] == deleted |
2999
|
|
|
assert last_actives[2] == main_folder |
3000
|
|
|
|
3001
|
|
|
api._show_deleted = False |
3002
|
|
|
api._show_archived = True |
3003
|
|
|
last_actives = api.get_last_active() |
3004
|
|
|
assert len(last_actives) == 3 |
3005
|
|
|
assert last_actives[0]== normal |
3006
|
|
|
assert last_actives[1] == archived |
3007
|
|
|
assert last_actives[2] == main_folder |
3008
|
|
|
|
3009
|
|
|
api._show_deleted = True |
3010
|
|
|
api._show_archived = True |
3011
|
|
|
last_actives = api.get_last_active() |
3012
|
|
|
assert len(last_actives) == 4 |
3013
|
|
|
assert last_actives[0] == normal |
3014
|
|
|
assert last_actives[1] == deleted |
3015
|
|
|
assert last_actives[2] == archived |
3016
|
|
|
assert last_actives[3] == main_folder |
3017
|
|
|
|
3018
|
|
|
def test_unit__get_last_active__ok__workspace_filter_workspace_full(self): |
3019
|
|
|
uapi = UserApi( |
3020
|
|
|
session=self.session, |
3021
|
|
|
config=self.app_config, |
3022
|
|
|
current_user=None, |
3023
|
|
|
) |
3024
|
|
|
group_api = GroupApi( |
3025
|
|
|
current_user=None, |
3026
|
|
|
session=self.session, |
3027
|
|
|
config=self.app_config, |
3028
|
|
|
) |
3029
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
3030
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
3031
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
3032
|
|
|
|
3033
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
3034
|
|
|
groups=groups, save_now=True) |
3035
|
|
|
workspace = WorkspaceApi( |
3036
|
|
|
current_user=user, |
3037
|
|
|
session=self.session, |
3038
|
|
|
config=self.app_config, |
3039
|
|
|
).create_workspace( |
3040
|
|
|
'test workspace', |
3041
|
|
|
save_now=True |
3042
|
|
|
) |
3043
|
|
|
|
3044
|
|
|
api = ContentApi( |
3045
|
|
|
current_user=user, |
3046
|
|
|
session=self.session, |
3047
|
|
|
config=self.app_config, |
3048
|
|
|
) |
3049
|
|
|
main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
3050
|
|
|
# creation order test |
3051
|
|
|
firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
3052
|
|
|
secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True) # nopep8 |
3053
|
|
|
# update order test |
3054
|
|
|
firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True) # nopep8 |
3055
|
|
|
secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True) # nopep8 |
3056
|
|
|
with new_revision( |
3057
|
|
|
session=self.session, |
3058
|
|
|
tm=transaction.manager, |
3059
|
|
|
content=firstly_created_but_recently_updated, |
3060
|
|
|
): |
3061
|
|
|
firstly_created_but_recently_updated.description = 'Just an update' |
3062
|
|
|
api.save(firstly_created_but_recently_updated) |
3063
|
|
|
# comment change order |
3064
|
|
|
firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True) # nopep8 |
3065
|
|
|
secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8 |
3066
|
|
|
comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8 |
3067
|
|
|
|
3068
|
|
|
last_actives = api.get_last_active(workspace=workspace) |
3069
|
|
|
assert len(last_actives) == 7 |
3070
|
|
|
# comment is newest than page2 |
3071
|
|
|
assert last_actives[0] == firstly_created_but_recently_commented |
3072
|
|
|
assert last_actives[1] == secondly_created_but_not_commented |
3073
|
|
|
# last updated content is newer than other one despite creation |
3074
|
|
|
# of the other is more recent |
3075
|
|
|
assert last_actives[2] == firstly_created_but_recently_updated |
3076
|
|
|
assert last_actives[3] == secondly_created_but_not_updated |
3077
|
|
|
# creation order is inverted here as last created is last active |
3078
|
|
|
assert last_actives[4] == secondly_created |
3079
|
|
|
assert last_actives[5] == firstly_created |
3080
|
|
|
# folder subcontent modification does not change folder order |
3081
|
|
|
assert last_actives[6] == main_folder |
3082
|
|
|
|
3083
|
|
|
def test_unit__get_last_active__ok__workspace_filter_workspace_content_ids(self): |
3084
|
|
|
uapi = UserApi( |
3085
|
|
|
session=self.session, |
3086
|
|
|
config=self.app_config, |
3087
|
|
|
current_user=None, |
3088
|
|
|
) |
3089
|
|
|
group_api = GroupApi( |
3090
|
|
|
current_user=None, |
3091
|
|
|
session=self.session, |
3092
|
|
|
config=self.app_config, |
3093
|
|
|
) |
3094
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
3095
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
3096
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
3097
|
|
|
|
3098
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
3099
|
|
|
groups=groups, save_now=True) |
3100
|
|
|
workspace = WorkspaceApi( |
3101
|
|
|
current_user=user, |
3102
|
|
|
session=self.session, |
3103
|
|
|
config=self.app_config, |
3104
|
|
|
).create_workspace( |
3105
|
|
|
'test workspace', |
3106
|
|
|
save_now=True |
3107
|
|
|
) |
3108
|
|
|
|
3109
|
|
|
api = ContentApi( |
3110
|
|
|
current_user=user, |
3111
|
|
|
session=self.session, |
3112
|
|
|
config=self.app_config, |
3113
|
|
|
) |
3114
|
|
|
main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
3115
|
|
|
# creation order test |
3116
|
|
|
firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
3117
|
|
|
secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True) # nopep8 |
3118
|
|
|
# update order test |
3119
|
|
|
firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True) # nopep8 |
3120
|
|
|
secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True) # nopep8 |
3121
|
|
|
with new_revision( |
3122
|
|
|
session=self.session, |
3123
|
|
|
tm=transaction.manager, |
3124
|
|
|
content=firstly_created_but_recently_updated, |
3125
|
|
|
): |
3126
|
|
|
firstly_created_but_recently_updated.description = 'Just an update' |
3127
|
|
|
api.save(firstly_created_but_recently_updated) |
3128
|
|
|
# comment change order |
3129
|
|
|
firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True) # nopep8 |
3130
|
|
|
secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8 |
3131
|
|
|
comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8 |
3132
|
|
|
|
3133
|
|
|
selected_contents = [ |
3134
|
|
|
firstly_created_but_recently_commented, |
3135
|
|
|
firstly_created_but_recently_updated, |
3136
|
|
|
firstly_created, |
3137
|
|
|
main_folder, |
3138
|
|
|
] |
3139
|
|
|
content_ids = [content.content_id for content in selected_contents] |
3140
|
|
|
last_actives = api.get_last_active( |
3141
|
|
|
workspace=workspace, |
3142
|
|
|
content_ids=content_ids, |
3143
|
|
|
) |
3144
|
|
|
assert len(last_actives) == 4 |
3145
|
|
|
# comment is newest than page2 |
3146
|
|
|
assert last_actives[0] == firstly_created_but_recently_commented |
3147
|
|
|
assert secondly_created_but_not_commented not in last_actives |
3148
|
|
|
# last updated content is newer than other one despite creation |
3149
|
|
|
# of the other is more recent |
3150
|
|
|
assert last_actives[1] == firstly_created_but_recently_updated |
3151
|
|
|
assert secondly_created_but_not_updated not in last_actives |
3152
|
|
|
# creation order is inverted here as last created is last active |
3153
|
|
|
assert secondly_created not in last_actives |
3154
|
|
|
assert last_actives[2] == firstly_created |
3155
|
|
|
# folder subcontent modification does not change folder order |
3156
|
|
|
assert last_actives[3] == main_folder |
3157
|
|
|
|
3158
|
|
|
def test_unit__get_last_active__ok__workspace_filter_workspace_limit_2_multiples_times(self): # nopep8 |
3159
|
|
|
uapi = UserApi( |
3160
|
|
|
session=self.session, |
3161
|
|
|
config=self.app_config, |
3162
|
|
|
current_user=None, |
3163
|
|
|
) |
3164
|
|
|
group_api = GroupApi( |
3165
|
|
|
current_user=None, |
3166
|
|
|
session=self.session, |
3167
|
|
|
config=self.app_config, |
3168
|
|
|
) |
3169
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
3170
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
3171
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
3172
|
|
|
|
3173
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
3174
|
|
|
groups=groups, save_now=True) |
3175
|
|
|
workspace = WorkspaceApi( |
3176
|
|
|
current_user=user, |
3177
|
|
|
session=self.session, |
3178
|
|
|
config=self.app_config, |
3179
|
|
|
).create_workspace( |
3180
|
|
|
'test workspace', |
3181
|
|
|
save_now=True |
3182
|
|
|
) |
3183
|
|
|
|
3184
|
|
|
api = ContentApi( |
3185
|
|
|
current_user=user, |
3186
|
|
|
session=self.session, |
3187
|
|
|
config=self.app_config, |
3188
|
|
|
) |
3189
|
|
|
main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
3190
|
|
|
# creation order test |
3191
|
|
|
firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
3192
|
|
|
secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True) # nopep8 |
3193
|
|
|
# update order test |
3194
|
|
|
firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True) # nopep8 |
3195
|
|
|
secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True) # nopep8 |
3196
|
|
|
with new_revision( |
3197
|
|
|
session=self.session, |
3198
|
|
|
tm=transaction.manager, |
3199
|
|
|
content=firstly_created_but_recently_updated, |
3200
|
|
|
): |
3201
|
|
|
firstly_created_but_recently_updated.description = 'Just an update' |
3202
|
|
|
api.save(firstly_created_but_recently_updated) |
3203
|
|
|
# comment change order |
3204
|
|
|
firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True) # nopep8 |
3205
|
|
|
secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8 |
3206
|
|
|
comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8 |
3207
|
|
|
|
3208
|
|
|
last_actives = api.get_last_active(workspace=workspace, limit=2) # nopep8 |
3209
|
|
|
assert len(last_actives) == 2 |
3210
|
|
|
# comment is newest than page2 |
3211
|
|
|
assert last_actives[0] == firstly_created_but_recently_commented |
3212
|
|
|
assert last_actives[1] == secondly_created_but_not_commented |
3213
|
|
|
|
3214
|
|
|
last_actives = api.get_last_active(workspace=workspace, limit=2, before_content=last_actives[1]) # nopep8 |
3215
|
|
|
assert len(last_actives) == 2 |
3216
|
|
|
# last updated content is newer than other one despite creation |
3217
|
|
|
# of the other is more recent |
3218
|
|
|
assert last_actives[0] == firstly_created_but_recently_updated |
3219
|
|
|
assert last_actives[1] == secondly_created_but_not_updated |
3220
|
|
|
|
3221
|
|
|
last_actives = api.get_last_active(workspace=workspace, limit=2, before_content=last_actives[1]) # nopep8 |
3222
|
|
|
assert len(last_actives) == 2 |
3223
|
|
|
# creation order is inverted here as last created is last active |
3224
|
|
|
assert last_actives[0] == secondly_created |
3225
|
|
|
assert last_actives[1] == firstly_created |
3226
|
|
|
|
3227
|
|
|
last_actives = api.get_last_active(workspace=workspace, limit=2, before_content=last_actives[1]) # nopep8 |
3228
|
|
|
assert len(last_actives) == 1 |
3229
|
|
|
# folder subcontent modification does not change folder order |
3230
|
|
|
assert last_actives[0] == main_folder |
3231
|
|
|
|
3232
|
|
|
def test_unit__get_last_active__ok__workspace_filter_workspace_empty(self): |
3233
|
|
|
uapi = UserApi( |
3234
|
|
|
session=self.session, |
3235
|
|
|
config=self.app_config, |
3236
|
|
|
current_user=None, |
3237
|
|
|
) |
3238
|
|
|
group_api = GroupApi( |
3239
|
|
|
current_user=None, |
3240
|
|
|
session=self.session, |
3241
|
|
|
config=self.app_config, |
3242
|
|
|
) |
3243
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
3244
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
3245
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
3246
|
|
|
|
3247
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
3248
|
|
|
groups=groups, save_now=True) |
3249
|
|
|
workspace = WorkspaceApi( |
3250
|
|
|
current_user=user, |
3251
|
|
|
session=self.session, |
3252
|
|
|
config=self.app_config, |
3253
|
|
|
).create_workspace( |
3254
|
|
|
'test workspace', |
3255
|
|
|
save_now=True |
3256
|
|
|
) |
3257
|
|
|
workspace2 = WorkspaceApi( |
3258
|
|
|
current_user=user, |
3259
|
|
|
session=self.session, |
3260
|
|
|
config=self.app_config, |
3261
|
|
|
).create_workspace( |
3262
|
|
|
'test workspace2', |
3263
|
|
|
save_now=True |
3264
|
|
|
) |
3265
|
|
|
api = ContentApi( |
3266
|
|
|
current_user=user, |
3267
|
|
|
session=self.session, |
3268
|
|
|
config=self.app_config, |
3269
|
|
|
) |
3270
|
|
|
main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
3271
|
|
|
# creation order test |
3272
|
|
|
firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
3273
|
|
|
secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True) # nopep8 |
3274
|
|
|
# update order test |
3275
|
|
|
firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True) # nopep8 |
3276
|
|
|
secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True) # nopep8 |
3277
|
|
|
with new_revision( |
3278
|
|
|
session=self.session, |
3279
|
|
|
tm=transaction.manager, |
3280
|
|
|
content=firstly_created_but_recently_updated, |
3281
|
|
|
): |
3282
|
|
|
firstly_created_but_recently_updated.description = 'Just an update' |
3283
|
|
|
api.save(firstly_created_but_recently_updated) |
3284
|
|
|
# comment change order |
3285
|
|
|
firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True) # nopep8 |
3286
|
|
|
secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8 |
3287
|
|
|
comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8 |
3288
|
|
|
|
3289
|
|
|
last_actives = api.get_last_active(workspace=workspace2) |
3290
|
|
|
assert len(last_actives) == 0 |
3291
|
|
|
|
3292
|
|
View Code Duplication |
def test_search_in_label(self): |
|
|
|
|
3293
|
|
|
# HACK - D.A. - 2015-03-09 |
3294
|
|
|
# This test is based on a bug which does NOT return results found |
3295
|
|
|
# at root of a workspace (eg a folder) |
3296
|
|
|
uapi = UserApi( |
3297
|
|
|
session=self.session, |
3298
|
|
|
config=self.app_config, |
3299
|
|
|
current_user=None, |
3300
|
|
|
) |
3301
|
|
|
group_api = GroupApi( |
3302
|
|
|
current_user=None, |
3303
|
|
|
session=self.session, |
3304
|
|
|
config=self.app_config, |
3305
|
|
|
) |
3306
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
3307
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
3308
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
3309
|
|
|
|
3310
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
3311
|
|
|
groups=groups, save_now=True) |
3312
|
|
|
|
3313
|
|
|
workspace = WorkspaceApi( |
3314
|
|
|
current_user=user, |
3315
|
|
|
session=self.session, |
3316
|
|
|
config=self.app_config, |
3317
|
|
|
).create_workspace( |
3318
|
|
|
'test workspace', |
3319
|
|
|
save_now=True |
3320
|
|
|
) |
3321
|
|
|
|
3322
|
|
|
api = ContentApi( |
3323
|
|
|
current_user=user, |
3324
|
|
|
session=self.session, |
3325
|
|
|
config=self.app_config, |
3326
|
|
|
) |
3327
|
|
|
a = api.create(CONTENT_TYPES.Folder.slug, workspace, None, |
3328
|
|
|
'this is randomized folder', '', True) |
3329
|
|
|
p = api.create(CONTENT_TYPES.Page.slug, workspace, a, |
3330
|
|
|
'this is randomized label content', '', True) |
3331
|
|
|
|
3332
|
|
|
with new_revision( |
3333
|
|
|
session=self.session, |
3334
|
|
|
tm=transaction.manager, |
3335
|
|
|
content=p, |
3336
|
|
|
): |
3337
|
|
|
p.description = 'This is some amazing test' |
3338
|
|
|
|
3339
|
|
|
api.save(p) |
3340
|
|
|
original_id = p.content_id |
3341
|
|
|
|
3342
|
|
|
res = api.search(['randomized']) |
3343
|
|
|
eq_(1, len(res.all())) |
3344
|
|
|
item = res.all()[0] |
3345
|
|
|
eq_(original_id, item.content_id) |
3346
|
|
|
|
3347
|
|
View Code Duplication |
def test_search_in_description(self): |
|
|
|
|
3348
|
|
|
# HACK - D.A. - 2015-03-09 |
3349
|
|
|
# This test is based on a bug which does NOT return results found |
3350
|
|
|
# at root of a workspace (eg a folder) |
3351
|
|
|
|
3352
|
|
|
uapi = UserApi( |
3353
|
|
|
session=self.session, |
3354
|
|
|
config=self.app_config, |
3355
|
|
|
current_user=None, |
3356
|
|
|
) |
3357
|
|
|
group_api = GroupApi( |
3358
|
|
|
current_user=None, |
3359
|
|
|
session=self.session, |
3360
|
|
|
config=self.app_config, |
3361
|
|
|
) |
3362
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
3363
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
3364
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
3365
|
|
|
|
3366
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
3367
|
|
|
groups=groups, save_now=True) |
3368
|
|
|
|
3369
|
|
|
workspace = WorkspaceApi( |
3370
|
|
|
current_user=user, |
3371
|
|
|
session=self.session, |
3372
|
|
|
config=self.app_config, |
3373
|
|
|
).create_workspace( |
3374
|
|
|
'test workspace', |
3375
|
|
|
save_now=True, |
3376
|
|
|
) |
3377
|
|
|
|
3378
|
|
|
api = ContentApi( |
3379
|
|
|
current_user=user, |
3380
|
|
|
session=self.session, |
3381
|
|
|
config=self.app_config, |
3382
|
|
|
) |
3383
|
|
|
a = api.create(CONTENT_TYPES.Folder.slug, workspace, None, |
3384
|
|
|
'this is randomized folder', '', True) |
3385
|
|
|
p = api.create(CONTENT_TYPES.Page.slug, workspace, a, |
3386
|
|
|
'this is dummy label content', '', True) |
3387
|
|
|
|
3388
|
|
|
with new_revision( |
3389
|
|
|
tm=transaction.manager, |
3390
|
|
|
session=self.session, |
3391
|
|
|
content=p, |
3392
|
|
|
): |
3393
|
|
|
p.description = 'This is some amazing test' |
3394
|
|
|
|
3395
|
|
|
api.save(p) |
3396
|
|
|
original_id = p.content_id |
3397
|
|
|
|
3398
|
|
|
res = api.search(['dummy']) |
3399
|
|
|
eq_(1, len(res.all())) |
3400
|
|
|
item = res.all()[0] |
3401
|
|
|
eq_(original_id, item.content_id) |
3402
|
|
|
|
3403
|
|
|
def test_search_in_label_or_description(self): |
3404
|
|
|
# HACK - D.A. - 2015-03-09 |
3405
|
|
|
# This test is based on a bug which does NOT return results found |
3406
|
|
|
# at root of a workspace (eg a folder) |
3407
|
|
|
|
3408
|
|
|
uapi = UserApi( |
3409
|
|
|
session=self.session, |
3410
|
|
|
config=self.app_config, |
3411
|
|
|
current_user=None, |
3412
|
|
|
) |
3413
|
|
|
group_api = GroupApi( |
3414
|
|
|
current_user=None, |
3415
|
|
|
session=self.session, |
3416
|
|
|
config=self.app_config, |
3417
|
|
|
) |
3418
|
|
|
groups = [group_api.get_one(Group.TIM_USER), |
3419
|
|
|
group_api.get_one(Group.TIM_MANAGER), |
3420
|
|
|
group_api.get_one(Group.TIM_ADMIN)] |
3421
|
|
|
|
3422
|
|
|
user = uapi.create_minimal_user(email='this.is@user', |
3423
|
|
|
groups=groups, save_now=True) |
3424
|
|
|
|
3425
|
|
|
workspace = WorkspaceApi( |
3426
|
|
|
current_user=user, |
3427
|
|
|
session=self.session, |
3428
|
|
|
config=self.app_config, |
3429
|
|
|
).create_workspace('test workspace', save_now=True) |
3430
|
|
|
|
3431
|
|
|
api = ContentApi( |
3432
|
|
|
current_user=user, |
3433
|
|
|
session=self.session, |
3434
|
|
|
config=self.app_config, |
3435
|
|
|
) |
3436
|
|
|
a = api.create( |
3437
|
|
|
content_type_slug=CONTENT_TYPES.Folder.slug, |
3438
|
|
|
workspace=workspace, |
3439
|
|
|
parent=None, |
3440
|
|
|
label='this is randomized folder', |
3441
|
|
|
do_save=True |
3442
|
|
|
) |
3443
|
|
|
p1 = api.create( |
3444
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
3445
|
|
|
workspace=workspace, |
3446
|
|
|
parent=a, |
3447
|
|
|
label='this is dummy label content', |
3448
|
|
|
do_save=True |
3449
|
|
|
) |
3450
|
|
|
p2 = api.create( |
3451
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
3452
|
|
|
workspace=workspace, |
3453
|
|
|
parent=a, |
3454
|
|
|
label='Hey ! Jon !', |
3455
|
|
|
do_save=True |
3456
|
|
|
) |
3457
|
|
|
|
3458
|
|
|
with new_revision( |
3459
|
|
|
session=self.session, |
3460
|
|
|
tm=transaction.manager, |
3461
|
|
|
content=p1, |
3462
|
|
|
): |
3463
|
|
|
p1.description = 'This is some amazing test' |
3464
|
|
|
|
3465
|
|
|
with new_revision( |
3466
|
|
|
session=self.session, |
3467
|
|
|
tm=transaction.manager, |
3468
|
|
|
content=p2, |
3469
|
|
|
): |
3470
|
|
|
p2.description = 'What\'s up?' |
3471
|
|
|
|
3472
|
|
|
api.save(p1) |
3473
|
|
|
api.save(p2) |
3474
|
|
|
|
3475
|
|
|
id1 = p1.content_id |
3476
|
|
|
id2 = p2.content_id |
3477
|
|
|
|
3478
|
|
|
eq_(1, self.session.query(Workspace).filter(Workspace.label == 'test workspace').count()) |
3479
|
|
|
eq_(1, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'this is randomized folder').count()) |
3480
|
|
|
eq_(2, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'this is dummy label content').count()) |
3481
|
|
|
eq_(1, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.description == 'This is some amazing test').count()) |
3482
|
|
|
eq_(2, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'Hey ! Jon !').count()) |
3483
|
|
|
eq_(1, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.description == 'What\'s up?').count()) |
3484
|
|
|
|
3485
|
|
|
res = api.search(['dummy', 'jon']) |
3486
|
|
|
eq_(2, len(res.all())) |
3487
|
|
|
|
3488
|
|
|
eq_(True, id1 in [o.content_id for o in res.all()]) |
3489
|
|
|
eq_(True, id2 in [o.content_id for o in res.all()]) |
3490
|
|
|
|
3491
|
|
|
def test_unit__search_exclude_content_under_deleted_or_archived_parents__ok(self): # nopep8 |
3492
|
|
|
admin = self.session.query(User)\ |
3493
|
|
|
.filter(User.email == '[email protected]').one() |
3494
|
|
|
workspace = self._create_workspace_and_test( |
3495
|
|
|
'workspace_1', |
3496
|
|
|
admin |
3497
|
|
|
) |
3498
|
|
|
folder_1 = self._create_content_and_test( |
3499
|
|
|
'folder_1', |
3500
|
|
|
workspace=workspace, |
3501
|
|
|
type=CONTENT_TYPES.Folder.slug |
3502
|
|
|
) |
3503
|
|
|
folder_2 = self._create_content_and_test( |
3504
|
|
|
'folder_2', |
3505
|
|
|
workspace=workspace, |
3506
|
|
|
type=CONTENT_TYPES.Folder.slug |
3507
|
|
|
) |
3508
|
|
|
page_1 = self._create_content_and_test( |
3509
|
|
|
'foo', workspace=workspace, |
3510
|
|
|
type=CONTENT_TYPES.Page.slug, |
3511
|
|
|
parent=folder_1 |
3512
|
|
|
) |
3513
|
|
|
page_2 = self._create_content_and_test( |
3514
|
|
|
'bar', |
3515
|
|
|
workspace=workspace, |
3516
|
|
|
type=CONTENT_TYPES.Page.slug, |
3517
|
|
|
parent=folder_2 |
3518
|
|
|
) |
3519
|
|
|
|
3520
|
|
|
api = ContentApi( |
3521
|
|
|
current_user=admin, |
3522
|
|
|
session=self.session, |
3523
|
|
|
config=self.app_config, |
3524
|
|
|
) |
3525
|
|
|
|
3526
|
|
|
foo_result = api.search(['foo']).all() |
3527
|
|
|
eq_(1, len(foo_result)) |
3528
|
|
|
assert page_1 in foo_result |
3529
|
|
|
|
3530
|
|
|
bar_result = api.search(['bar']).all() |
3531
|
|
|
eq_(1, len(bar_result)) |
3532
|
|
|
assert page_2 in bar_result |
3533
|
|
|
|
3534
|
|
|
with new_revision( |
3535
|
|
|
session=self.session, |
3536
|
|
|
tm=transaction.manager, |
3537
|
|
|
content=folder_1, |
3538
|
|
|
): |
3539
|
|
|
api.delete(folder_1) |
3540
|
|
|
with new_revision( |
3541
|
|
|
session=self.session, |
3542
|
|
|
tm=transaction.manager, |
3543
|
|
|
content=folder_2, |
3544
|
|
|
): |
3545
|
|
|
api.archive(folder_2) |
3546
|
|
|
|
3547
|
|
|
# Actually ContentApi.search don't filter it |
3548
|
|
|
foo_result = api.search(['foo']).all() |
3549
|
|
|
eq_(1, len(foo_result)) |
3550
|
|
|
assert page_1 in foo_result |
3551
|
|
|
|
3552
|
|
|
bar_result = api.search(['bar']).all() |
3553
|
|
|
eq_(1, len(bar_result)) |
3554
|
|
|
assert page_2 in bar_result |
3555
|
|
|
|
3556
|
|
|
# ContentApi offer exclude_unavailable method to do it |
3557
|
|
|
foo_result = api.search(['foo']).all() |
3558
|
|
|
api.exclude_unavailable(foo_result) |
3559
|
|
|
eq_(0, len(foo_result)) |
3560
|
|
|
|
3561
|
|
|
bar_result = api.search(['bar']).all() |
3562
|
|
|
api.exclude_unavailable(bar_result) |
3563
|
|
|
eq_(0, len(bar_result)) |
3564
|
|
|
|
3565
|
|
|
|
3566
|
|
|
class TestContentApiSecurity(DefaultTest): |
3567
|
|
|
fixtures = [FixtureTest, ] |
3568
|
|
|
|
3569
|
|
|
def test_unit__cant_get_non_access_content__ok__nominal_case(self): |
3570
|
|
|
admin = self.session.query(User)\ |
3571
|
|
|
.filter(User.email == '[email protected]').one() |
3572
|
|
|
bob = self.session.query(User)\ |
3573
|
|
|
.filter(User.email == '[email protected]').one() |
3574
|
|
|
|
3575
|
|
|
bob_workspace = WorkspaceApi( |
3576
|
|
|
current_user=bob, |
3577
|
|
|
session=self.session, |
3578
|
|
|
config=self.app_config, |
3579
|
|
|
).create_workspace( |
3580
|
|
|
'bob_workspace', |
3581
|
|
|
save_now=True, |
3582
|
|
|
) |
3583
|
|
|
admin_workspace = WorkspaceApi( |
3584
|
|
|
current_user=admin, |
3585
|
|
|
session=self.session, |
3586
|
|
|
config=self.app_config, |
3587
|
|
|
).create_workspace( |
3588
|
|
|
'admin_workspace', |
3589
|
|
|
save_now=True, |
3590
|
|
|
) |
3591
|
|
|
|
3592
|
|
|
bob_page = ContentApi( |
3593
|
|
|
current_user=bob, |
3594
|
|
|
session=self.session, |
3595
|
|
|
config=self.app_config, |
3596
|
|
|
).create( |
3597
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
3598
|
|
|
workspace=bob_workspace, |
3599
|
|
|
label='bob_page', |
3600
|
|
|
do_save=True, |
3601
|
|
|
) |
3602
|
|
|
|
3603
|
|
|
admin_page = ContentApi( |
3604
|
|
|
current_user=admin, |
3605
|
|
|
session=self.session, |
3606
|
|
|
config=self.app_config, |
3607
|
|
|
).create( |
3608
|
|
|
content_type_slug=CONTENT_TYPES.Page.slug, |
3609
|
|
|
workspace=admin_workspace, |
3610
|
|
|
label='admin_page', |
3611
|
|
|
do_save=True, |
3612
|
|
|
) |
3613
|
|
|
|
3614
|
|
|
bob_viewable = ContentApi( |
3615
|
|
|
current_user=bob, |
3616
|
|
|
session=self.session, |
3617
|
|
|
config=self.app_config, |
3618
|
|
|
).get_all() |
3619
|
|
|
eq_(1, len(bob_viewable), 'Bob should view only one content') |
3620
|
|
|
eq_( |
3621
|
|
|
'bob_page', |
3622
|
|
|
bob_viewable[0].label, |
3623
|
|
|
'Bob should not view "{0}" content'.format( |
3624
|
|
|
bob_viewable[0].label, |
3625
|
|
|
) |
3626
|
|
|
) |
3627
|
|
|
|