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