Total Complexity | 77 |
Total Lines | 3025 |
Duplicated Lines | 29.16 % |
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 backend.tracim_backend.tests.functional.test_contents 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 transaction |
||
3 | |||
4 | from tracim_backend import models |
||
5 | from tracim_backend.lib.core.content import ContentApi |
||
6 | from tracim_backend.lib.core.workspace import WorkspaceApi |
||
7 | from tracim_backend.models import get_tm_session |
||
8 | from tracim_backend.app_models.contents import CONTENT_TYPES |
||
9 | from tracim_backend.models.revision_protection import new_revision |
||
10 | import io |
||
11 | |||
12 | import transaction |
||
13 | from PIL import Image |
||
14 | from depot.io.utils import FileIntent |
||
15 | |||
16 | from tracim_backend import models |
||
17 | from tracim_backend.lib.core.content import ContentApi |
||
18 | from tracim_backend.lib.core.workspace import WorkspaceApi |
||
19 | from tracim_backend.models import get_tm_session |
||
20 | from tracim_backend.models.revision_protection import new_revision |
||
21 | from tracim_backend.tests import FunctionalTest |
||
22 | from tracim_backend.tests import create_1000px_png_test_image |
||
23 | from tracim_backend.tests import set_html_document_slug_to_legacy |
||
24 | from tracim_backend.fixtures.content import Content as ContentFixtures |
||
25 | from tracim_backend.fixtures.users_and_groups import Base as BaseFixture |
||
26 | |||
27 | |||
28 | class TestFolder(FunctionalTest): |
||
29 | """ |
||
30 | Tests for /api/v2/workspaces/{workspace_id}/folders/{content_id} |
||
31 | endpoint |
||
32 | """ |
||
33 | |||
34 | fixtures = [BaseFixture] |
||
35 | |||
36 | def test_api__get_folder__ok_200__nominal_case(self) -> None: |
||
37 | """ |
||
38 | Get one folder content |
||
39 | """ |
||
40 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
41 | admin = dbsession.query(models.User) \ |
||
42 | .filter(models.User.email == '[email protected]') \ |
||
43 | .one() |
||
44 | workspace_api = WorkspaceApi( |
||
45 | current_user=admin, |
||
46 | session=dbsession, |
||
47 | config=self.app_config |
||
48 | ) |
||
49 | content_api = ContentApi( |
||
50 | current_user=admin, |
||
51 | session=dbsession, |
||
52 | config=self.app_config |
||
53 | ) |
||
54 | test_workspace = workspace_api.create_workspace( |
||
55 | label='test', |
||
56 | save_now=True, |
||
57 | ) |
||
58 | folder = content_api.create( |
||
59 | label='test-folder', |
||
60 | content_type_slug=CONTENT_TYPES.Folder.slug, |
||
61 | workspace=test_workspace, |
||
62 | do_save=True, |
||
63 | do_notify=False |
||
64 | ) |
||
65 | transaction.commit() |
||
66 | |||
67 | self.testapp.authorization = ( |
||
68 | 'Basic', |
||
69 | ( |
||
70 | '[email protected]', |
||
71 | '[email protected]' |
||
72 | ) |
||
73 | ) |
||
74 | res = self.testapp.get( |
||
75 | '/api/v2/workspaces/{workspace_id}/folders/{content_id}'.format( |
||
76 | workspace_id=test_workspace.workspace_id, |
||
77 | content_id=folder.content_id, |
||
78 | ), |
||
79 | status=200 |
||
80 | ) |
||
81 | content = res.json_body |
||
82 | assert content['content_type'] == 'folder' |
||
83 | assert content['content_id'] == folder.content_id |
||
84 | assert content['is_archived'] is False |
||
85 | assert content['is_deleted'] is False |
||
86 | assert content['label'] == 'test-folder' |
||
87 | assert content['parent_id'] is None |
||
88 | assert content['show_in_ui'] is True |
||
89 | assert content['slug'] == 'test-folder' |
||
90 | assert content['status'] == 'open' |
||
91 | assert content['workspace_id'] == test_workspace.workspace_id |
||
92 | assert content['current_revision_id'] == folder.revision_id |
||
93 | # TODO - G.M - 2018-06-173 - check date format |
||
94 | assert content['created'] |
||
95 | assert content['author'] |
||
96 | assert content['author']['user_id'] == 1 |
||
97 | assert content['author']['avatar_url'] is None |
||
98 | assert content['author']['public_name'] == 'Global manager' |
||
99 | # TODO - G.M - 2018-06-173 - check date format |
||
100 | assert content['modified'] |
||
101 | assert content['last_modifier']['user_id'] == 1 |
||
102 | assert content['last_modifier']['public_name'] == 'Global manager' |
||
103 | assert content['last_modifier']['avatar_url'] is None |
||
104 | assert content['raw_content'] == '' |
||
105 | |||
106 | def test_api__get_folder__err_400__wrong_content_type(self) -> None: |
||
107 | """ |
||
108 | Get one folder of a content content 7 is not folder |
||
109 | """ |
||
110 | self.testapp.authorization = ( |
||
111 | 'Basic', |
||
112 | ( |
||
113 | '[email protected]', |
||
114 | '[email protected]' |
||
115 | ) |
||
116 | ) |
||
117 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
118 | admin = dbsession.query(models.User) \ |
||
119 | .filter(models.User.email == '[email protected]') \ |
||
120 | .one() |
||
121 | workspace_api = WorkspaceApi( |
||
122 | current_user=admin, |
||
123 | session=dbsession, |
||
124 | config=self.app_config |
||
125 | ) |
||
126 | content_api = ContentApi( |
||
127 | current_user=admin, |
||
128 | session=dbsession, |
||
129 | config=self.app_config |
||
130 | ) |
||
131 | test_workspace = workspace_api.create_workspace( |
||
132 | label='test', |
||
133 | save_now=True, |
||
134 | ) |
||
135 | thread = content_api.create( |
||
136 | label='thread', |
||
137 | content_type_slug=CONTENT_TYPES.Thread.slug, |
||
138 | workspace=test_workspace, |
||
139 | do_save=True, |
||
140 | do_notify=False |
||
141 | ) |
||
142 | transaction.commit() |
||
143 | self.testapp.get( |
||
144 | '/api/v2/workspaces/2/folders/7', |
||
145 | status=400 |
||
146 | ) |
||
147 | |||
148 | def test_api__get_folder__err_400__content_does_not_exist(self) -> None: # nopep8 |
||
149 | """ |
||
150 | Get one folder content (content 170 does not exist in db) |
||
151 | """ |
||
152 | self.testapp.authorization = ( |
||
153 | 'Basic', |
||
154 | ( |
||
155 | '[email protected]', |
||
156 | '[email protected]' |
||
157 | ) |
||
158 | ) |
||
159 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
160 | admin = dbsession.query(models.User) \ |
||
161 | .filter(models.User.email == '[email protected]') \ |
||
162 | .one() |
||
163 | workspace_api = WorkspaceApi( |
||
164 | current_user=admin, |
||
165 | session=dbsession, |
||
166 | config=self.app_config |
||
167 | ) |
||
168 | content_api = ContentApi( |
||
169 | current_user=admin, |
||
170 | session=dbsession, |
||
171 | config=self.app_config |
||
172 | ) |
||
173 | test_workspace = workspace_api.create_workspace( |
||
174 | label='test', |
||
175 | save_now=True, |
||
176 | ) |
||
177 | transaction.commit() |
||
178 | self.testapp.get( |
||
179 | '/api/v2/workspaces/{workspace_id}/folders/170'.format(workspace_id=test_workspace.workspace_id), # nopep8 |
||
180 | status=400 |
||
181 | ) |
||
182 | |||
183 | def test_api__get_folder__err_400__content_not_in_workspace(self) -> None: # nopep8 |
||
184 | """ |
||
185 | Get one folders of a content (content is in another workspace) |
||
186 | """ |
||
187 | self.testapp.authorization = ( |
||
188 | 'Basic', |
||
189 | ( |
||
190 | '[email protected]', |
||
191 | '[email protected]' |
||
192 | ) |
||
193 | ) |
||
194 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
195 | admin = dbsession.query(models.User) \ |
||
196 | .filter(models.User.email == '[email protected]') \ |
||
197 | .one() |
||
198 | workspace_api = WorkspaceApi( |
||
199 | current_user=admin, |
||
200 | session=dbsession, |
||
201 | config=self.app_config |
||
202 | ) |
||
203 | content_api = ContentApi( |
||
204 | current_user=admin, |
||
205 | session=dbsession, |
||
206 | config=self.app_config |
||
207 | ) |
||
208 | test_workspace = workspace_api.create_workspace( |
||
209 | label='test', |
||
210 | save_now=True, |
||
211 | ) |
||
212 | folder = content_api.create( |
||
213 | label='test_folder', |
||
214 | content_type_slug=CONTENT_TYPES.Folder.slug, |
||
215 | workspace=test_workspace, |
||
216 | do_save=True, |
||
217 | do_notify=False |
||
218 | ) |
||
219 | test_workspace2 = workspace_api.create_workspace( |
||
220 | label='test2', |
||
221 | save_now=True, |
||
222 | ) |
||
223 | transaction.commit() |
||
224 | self.testapp.authorization = ( |
||
225 | 'Basic', |
||
226 | ( |
||
227 | '[email protected]', |
||
228 | '[email protected]' |
||
229 | ) |
||
230 | ) |
||
231 | self.testapp.get( |
||
232 | '/api/v2/workspaces/{workspace_id}/folders/{content_id}'.format( |
||
233 | workspace_id=test_workspace2.workspace_id, |
||
234 | content_id=folder.content_id, |
||
235 | ), |
||
236 | status=400 |
||
237 | ) |
||
238 | |||
239 | def test_api__get_folder__err_400__workspace_does_not_exist(self) -> None: # nopep8 |
||
240 | """ |
||
241 | Get one folder content (Workspace 40 does not exist) |
||
242 | """ |
||
243 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
244 | admin = dbsession.query(models.User) \ |
||
245 | .filter(models.User.email == '[email protected]') \ |
||
246 | .one() |
||
247 | workspace_api = WorkspaceApi( |
||
248 | current_user=admin, |
||
249 | session=dbsession, |
||
250 | config=self.app_config |
||
251 | ) |
||
252 | content_api = ContentApi( |
||
253 | current_user=admin, |
||
254 | session=dbsession, |
||
255 | config=self.app_config |
||
256 | ) |
||
257 | test_workspace = workspace_api.create_workspace( |
||
258 | label='test', |
||
259 | save_now=True, |
||
260 | ) |
||
261 | folder = content_api.create( |
||
262 | label='test_folder', |
||
263 | content_type_slug=CONTENT_TYPES.Folder.slug, |
||
264 | workspace=test_workspace, |
||
265 | do_save=True, |
||
266 | do_notify=False |
||
267 | ) |
||
268 | transaction.commit() |
||
269 | self.testapp.authorization = ( |
||
270 | 'Basic', |
||
271 | ( |
||
272 | '[email protected]', |
||
273 | '[email protected]' |
||
274 | ) |
||
275 | ) |
||
276 | self.testapp.get( |
||
277 | '/api/v2/workspaces/40/folders/{content_id}'.format(content_id=folder.content_id), # nopep8 |
||
278 | status=400 |
||
279 | ) |
||
280 | |||
281 | def test_api__get_folder__err_400__workspace_id_is_not_int(self) -> None: # nopep8 |
||
282 | """ |
||
283 | Get one folder content, workspace id is not int |
||
284 | """ |
||
285 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
286 | admin = dbsession.query(models.User) \ |
||
287 | .filter(models.User.email == '[email protected]') \ |
||
288 | .one() |
||
289 | workspace_api = WorkspaceApi( |
||
290 | current_user=admin, |
||
291 | session=dbsession, |
||
292 | config=self.app_config |
||
293 | ) |
||
294 | content_api = ContentApi( |
||
295 | current_user=admin, |
||
296 | session=dbsession, |
||
297 | config=self.app_config |
||
298 | ) |
||
299 | test_workspace = workspace_api.create_workspace( |
||
300 | label='test', |
||
301 | save_now=True, |
||
302 | ) |
||
303 | folder = content_api.create( |
||
304 | label='test_folder', |
||
305 | content_type_slug=CONTENT_TYPES.Folder.slug, |
||
306 | workspace=test_workspace, |
||
307 | do_save=True, |
||
308 | do_notify=False |
||
309 | ) |
||
310 | transaction.commit() |
||
311 | self.testapp.authorization = ( |
||
312 | 'Basic', |
||
313 | ( |
||
314 | '[email protected]', |
||
315 | '[email protected]' |
||
316 | ) |
||
317 | ) |
||
318 | self.testapp.get( |
||
319 | '/api/v2/workspaces/coucou/folders/{content_id}'.format(content_id=folder.content_id), # nopep8 |
||
320 | status=400 |
||
321 | ) |
||
322 | |||
323 | def test_api__get_folder__err_400__content_id_is_not_int(self) -> None: # nopep8 |
||
324 | """ |
||
325 | Get one folder content, content_id is not int |
||
326 | """ |
||
327 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
328 | admin = dbsession.query(models.User) \ |
||
329 | .filter(models.User.email == '[email protected]') \ |
||
330 | .one() |
||
331 | workspace_api = WorkspaceApi( |
||
332 | current_user=admin, |
||
333 | session=dbsession, |
||
334 | config=self.app_config |
||
335 | ) |
||
336 | content_api = ContentApi( |
||
337 | current_user=admin, |
||
338 | session=dbsession, |
||
339 | config=self.app_config |
||
340 | ) |
||
341 | test_workspace = workspace_api.create_workspace( |
||
342 | label='test', |
||
343 | save_now=True, |
||
344 | ) |
||
345 | folder = content_api.create( |
||
346 | label='test_folder', |
||
347 | content_type_slug=CONTENT_TYPES.Folder.slug, |
||
348 | workspace=test_workspace, |
||
349 | do_save=True, |
||
350 | do_notify=False |
||
351 | ) |
||
352 | transaction.commit() |
||
353 | |||
354 | self.testapp.authorization = ( |
||
355 | 'Basic', |
||
356 | ( |
||
357 | '[email protected]', |
||
358 | '[email protected]' |
||
359 | ) |
||
360 | ) |
||
361 | self.testapp.get( |
||
362 | '/api/v2/workspaces/{workspace_id}/folders/coucou'.format(workspace_id=test_workspace.workspace_id), # nopep8 |
||
363 | status=400 |
||
364 | ) |
||
365 | |||
366 | View Code Duplication | def test_api__update_folder__err_400__empty_label(self) -> None: # nopep8 |
|
|
|||
367 | """ |
||
368 | Update(put) one folder content |
||
369 | """ |
||
370 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
371 | admin = dbsession.query(models.User) \ |
||
372 | .filter(models.User.email == '[email protected]') \ |
||
373 | .one() |
||
374 | workspace_api = WorkspaceApi( |
||
375 | current_user=admin, |
||
376 | session=dbsession, |
||
377 | config=self.app_config |
||
378 | ) |
||
379 | content_api = ContentApi( |
||
380 | current_user=admin, |
||
381 | session=dbsession, |
||
382 | config=self.app_config |
||
383 | ) |
||
384 | test_workspace = workspace_api.create_workspace( |
||
385 | label='test', |
||
386 | save_now=True, |
||
387 | ) |
||
388 | folder = content_api.create( |
||
389 | label='test_folder', |
||
390 | content_type_slug=CONTENT_TYPES.Folder.slug, |
||
391 | workspace=test_workspace, |
||
392 | do_save=True, |
||
393 | do_notify=False |
||
394 | ) |
||
395 | transaction.commit() |
||
396 | self.testapp.authorization = ( |
||
397 | 'Basic', |
||
398 | ( |
||
399 | '[email protected]', |
||
400 | '[email protected]' |
||
401 | ) |
||
402 | ) |
||
403 | params = { |
||
404 | 'label': '', |
||
405 | 'raw_content': '<p> Le nouveau contenu </p>', |
||
406 | 'sub_content_types': [CONTENT_TYPES.Folder.slug] |
||
407 | } |
||
408 | self.testapp.put_json( |
||
409 | '/api/v2/workspaces/{workspace_id}/folders/{content_id}'.format( |
||
410 | workspace_id=test_workspace.workspace_id, |
||
411 | content_id=folder.content_id, |
||
412 | ), |
||
413 | params=params, |
||
414 | status=400 |
||
415 | ) |
||
416 | |||
417 | def test_api__update_folder__ok_200__nominal_case(self) -> None: |
||
418 | """ |
||
419 | Update(put) one html document of a content |
||
420 | """ |
||
421 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
422 | admin = dbsession.query(models.User) \ |
||
423 | .filter(models.User.email == '[email protected]') \ |
||
424 | .one() |
||
425 | workspace_api = WorkspaceApi( |
||
426 | current_user=admin, |
||
427 | session=dbsession, |
||
428 | config=self.app_config |
||
429 | ) |
||
430 | content_api = ContentApi( |
||
431 | current_user=admin, |
||
432 | session=dbsession, |
||
433 | config=self.app_config |
||
434 | ) |
||
435 | test_workspace = workspace_api.create_workspace( |
||
436 | label='test', |
||
437 | save_now=True, |
||
438 | ) |
||
439 | folder = content_api.create( |
||
440 | label='test_folder', |
||
441 | content_type_slug=CONTENT_TYPES.Folder.slug, |
||
442 | workspace=test_workspace, |
||
443 | do_save=True, |
||
444 | do_notify=False |
||
445 | ) |
||
446 | transaction.commit() |
||
447 | self.testapp.authorization = ( |
||
448 | 'Basic', |
||
449 | ( |
||
450 | '[email protected]', |
||
451 | '[email protected]' |
||
452 | ) |
||
453 | ) |
||
454 | params = { |
||
455 | 'label': 'My New label', |
||
456 | 'raw_content': '<p> Le nouveau contenu </p>', |
||
457 | 'sub_content_types': [CONTENT_TYPES.Folder.slug] |
||
458 | } |
||
459 | res = self.testapp.put_json( |
||
460 | '/api/v2/workspaces/{workspace_id}/folders/{content_id}'.format( |
||
461 | workspace_id=test_workspace.workspace_id, |
||
462 | content_id=folder.content_id, |
||
463 | ), |
||
464 | params=params, |
||
465 | status=200 |
||
466 | ) |
||
467 | content = res.json_body |
||
468 | assert content['content_type'] == 'folder' |
||
469 | assert content['content_id'] == folder.content_id |
||
470 | assert content['is_archived'] is False |
||
471 | assert content['is_deleted'] is False |
||
472 | assert content['label'] == 'My New label' |
||
473 | assert content['parent_id'] is None |
||
474 | assert content['show_in_ui'] is True |
||
475 | assert content['slug'] == 'my-new-label' |
||
476 | assert content['status'] == 'open' |
||
477 | assert content['workspace_id'] == test_workspace.workspace_id |
||
478 | assert content['current_revision_id'] |
||
479 | # TODO - G.M - 2018-06-173 - check date format |
||
480 | assert content['created'] |
||
481 | assert content['author'] |
||
482 | assert content['author']['user_id'] == 1 |
||
483 | assert content['author']['avatar_url'] is None |
||
484 | assert content['author']['public_name'] == 'Global manager' |
||
485 | # TODO - G.M - 2018-06-173 - check date format |
||
486 | assert content['modified'] |
||
487 | assert content['last_modifier'] == content['author'] |
||
488 | assert content['raw_content'] == '<p> Le nouveau contenu </p>' |
||
489 | assert content['sub_content_types'] == [CONTENT_TYPES.Folder.slug] |
||
490 | |||
491 | def test_api__get_folder_revisions__ok_200__nominal_case( |
||
492 | self |
||
493 | ) -> None: |
||
494 | """ |
||
495 | Get one html document of a content |
||
496 | """ |
||
497 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
498 | admin = dbsession.query(models.User) \ |
||
499 | .filter(models.User.email == '[email protected]') \ |
||
500 | .one() |
||
501 | workspace_api = WorkspaceApi( |
||
502 | current_user=admin, |
||
503 | session=dbsession, |
||
504 | config=self.app_config |
||
505 | ) |
||
506 | content_api = ContentApi( |
||
507 | current_user=admin, |
||
508 | session=dbsession, |
||
509 | config=self.app_config |
||
510 | ) |
||
511 | test_workspace = workspace_api.create_workspace( |
||
512 | label='test', |
||
513 | save_now=True, |
||
514 | ) |
||
515 | folder = content_api.create( |
||
516 | label='test-folder', |
||
517 | content_type_slug=CONTENT_TYPES.Folder.slug, |
||
518 | workspace=test_workspace, |
||
519 | do_save=True, |
||
520 | do_notify=False |
||
521 | ) |
||
522 | with new_revision( |
||
523 | session=dbsession, |
||
524 | tm=transaction.manager, |
||
525 | content=folder, |
||
526 | ): |
||
527 | content_api.update_content( |
||
528 | folder, |
||
529 | new_label='test-folder-updated', |
||
530 | new_content='Just a test' |
||
531 | ) |
||
532 | content_api.save(folder) |
||
533 | with new_revision( |
||
534 | session=dbsession, |
||
535 | tm=transaction.manager, |
||
536 | content=folder, |
||
537 | ): |
||
538 | content_api.archive( |
||
539 | folder, |
||
540 | ) |
||
541 | content_api.save(folder) |
||
542 | with new_revision( |
||
543 | session=dbsession, |
||
544 | tm=transaction.manager, |
||
545 | content=folder, |
||
546 | ): |
||
547 | content_api.unarchive( |
||
548 | folder, |
||
549 | ) |
||
550 | content_api.save(folder) |
||
551 | transaction.commit() |
||
552 | self.testapp.authorization = ( |
||
553 | 'Basic', |
||
554 | ( |
||
555 | '[email protected]', |
||
556 | '[email protected]' |
||
557 | ) |
||
558 | ) |
||
559 | res = self.testapp.get( |
||
560 | '/api/v2/workspaces/{workspace_id}/folders/{content_id}/revisions'.format( # nopep8 |
||
561 | workspace_id=test_workspace.workspace_id, |
||
562 | content_id=folder.content_id, |
||
563 | ), |
||
564 | status=200 |
||
565 | ) |
||
566 | revisions = res.json_body |
||
567 | assert len(revisions) == 4 |
||
568 | revision = revisions[0] |
||
569 | assert revision['content_type'] == 'folder' |
||
570 | assert revision['content_id'] == folder.content_id |
||
571 | assert revision['is_archived'] is False |
||
572 | assert revision['is_deleted'] is False |
||
573 | assert revision['label'] == 'test-folder' |
||
574 | assert revision['parent_id'] is None |
||
575 | assert revision['show_in_ui'] is True |
||
576 | assert revision['slug'] == 'test-folder' |
||
577 | assert revision['status'] == 'open' |
||
578 | assert revision['workspace_id'] == test_workspace.workspace_id |
||
579 | assert revision['revision_id'] |
||
580 | assert revision['revision_type'] == 'creation' |
||
581 | assert revision['sub_content_types'] |
||
582 | # TODO - G.M - 2018-06-173 - Test with real comments |
||
583 | assert revision['comment_ids'] == [] |
||
584 | # TODO - G.M - 2018-06-173 - check date format |
||
585 | assert revision['created'] |
||
586 | assert revision['author'] |
||
587 | assert revision['author']['user_id'] == 1 |
||
588 | assert revision['author']['avatar_url'] is None |
||
589 | assert revision['author']['public_name'] == 'Global manager' |
||
590 | |||
591 | revision = revisions[1] |
||
592 | assert revision['content_type'] == 'folder' |
||
593 | assert revision['content_id'] == folder.content_id |
||
594 | assert revision['is_archived'] is False |
||
595 | assert revision['is_deleted'] is False |
||
596 | assert revision['label'] == 'test-folder-updated' |
||
597 | assert revision['parent_id'] is None |
||
598 | assert revision['show_in_ui'] is True |
||
599 | assert revision['slug'] == 'test-folder-updated' |
||
600 | assert revision['status'] == 'open' |
||
601 | assert revision['workspace_id'] == test_workspace.workspace_id |
||
602 | assert revision['revision_id'] |
||
603 | assert revision['revision_type'] == 'edition' |
||
604 | assert revision['sub_content_types'] |
||
605 | # TODO - G.M - 2018-06-173 - Test with real comments |
||
606 | assert revision['comment_ids'] == [] |
||
607 | # TODO - G.M - 2018-06-173 - check date format |
||
608 | assert revision['created'] |
||
609 | assert revision['author'] |
||
610 | assert revision['author']['user_id'] == 1 |
||
611 | assert revision['author']['avatar_url'] is None |
||
612 | assert revision['author']['public_name'] == 'Global manager' |
||
613 | |||
614 | revision = revisions[2] |
||
615 | assert revision['content_type'] == 'folder' |
||
616 | assert revision['content_id'] == folder.content_id |
||
617 | assert revision['is_archived'] is True |
||
618 | assert revision['is_deleted'] is False |
||
619 | assert revision['label'] != 'test-folder-updated' |
||
620 | assert revision['label'].startswith('test-folder-updated') |
||
621 | assert revision['parent_id'] is None |
||
622 | assert revision['show_in_ui'] is True |
||
623 | assert revision['slug'] != 'test-folder-updated' |
||
624 | assert revision['slug'].startswith('test-folder-updated') |
||
625 | assert revision['status'] == 'open' |
||
626 | assert revision['workspace_id'] == test_workspace.workspace_id |
||
627 | assert revision['revision_id'] |
||
628 | assert revision['revision_type'] == 'archiving' |
||
629 | assert revision['sub_content_types'] |
||
630 | # TODO - G.M - 2018-06-173 - Test with real comments |
||
631 | assert revision['comment_ids'] == [] |
||
632 | # TODO - G.M - 2018-06-173 - check date format |
||
633 | assert revision['created'] |
||
634 | assert revision['author'] |
||
635 | assert revision['author']['user_id'] == 1 |
||
636 | assert revision['author']['avatar_url'] is None |
||
637 | assert revision['author']['public_name'] == 'Global manager' |
||
638 | |||
639 | revision = revisions[3] |
||
640 | assert revision['content_type'] == 'folder' |
||
641 | assert revision['content_id'] == folder.content_id |
||
642 | assert revision['is_archived'] is False |
||
643 | assert revision['is_deleted'] is False |
||
644 | assert revision['label'].startswith('test-folder-updated') |
||
645 | assert revision['parent_id'] is None |
||
646 | assert revision['show_in_ui'] is True |
||
647 | assert revision['slug'].startswith('test-folder-updated') |
||
648 | assert revision['status'] == 'open' |
||
649 | assert revision['workspace_id'] == test_workspace.workspace_id |
||
650 | assert revision['revision_id'] |
||
651 | assert revision['revision_type'] == 'unarchiving' |
||
652 | assert revision['sub_content_types'] |
||
653 | # TODO - G.M - 2018-06-173 - Test with real comments |
||
654 | assert revision['comment_ids'] == [] |
||
655 | # TODO - G.M - 2018-06-173 - check date format |
||
656 | assert revision['created'] |
||
657 | assert revision['author'] |
||
658 | assert revision['author']['user_id'] == 1 |
||
659 | assert revision['author']['avatar_url'] is None |
||
660 | assert revision['author']['public_name'] == 'Global manager' |
||
661 | |||
662 | def test_api__set_folder_status__ok_200__nominal_case(self) -> None: |
||
663 | """ |
||
664 | Get one folder content |
||
665 | """ |
||
666 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
667 | admin = dbsession.query(models.User) \ |
||
668 | .filter(models.User.email == '[email protected]') \ |
||
669 | .one() |
||
670 | workspace_api = WorkspaceApi( |
||
671 | current_user=admin, |
||
672 | session=dbsession, |
||
673 | config=self.app_config |
||
674 | ) |
||
675 | content_api = ContentApi( |
||
676 | current_user=admin, |
||
677 | session=dbsession, |
||
678 | config=self.app_config |
||
679 | ) |
||
680 | test_workspace = workspace_api.create_workspace( |
||
681 | label='test', |
||
682 | save_now=True, |
||
683 | ) |
||
684 | folder = content_api.create( |
||
685 | label='test_folder', |
||
686 | content_type_slug=CONTENT_TYPES.Folder.slug, |
||
687 | workspace=test_workspace, |
||
688 | do_save=True, |
||
689 | do_notify=False |
||
690 | ) |
||
691 | transaction.commit() |
||
692 | self.testapp.authorization = ( |
||
693 | 'Basic', |
||
694 | ( |
||
695 | '[email protected]', |
||
696 | '[email protected]' |
||
697 | ) |
||
698 | ) |
||
699 | params = { |
||
700 | 'status': 'closed-deprecated', |
||
701 | } |
||
702 | |||
703 | # before |
||
704 | res = self.testapp.get( |
||
705 | '/api/v2/workspaces/{workspace_id}/folders/{content_id}'.format( # nopep8 |
||
706 | # nopep8 |
||
707 | workspace_id=test_workspace.workspace_id, |
||
708 | content_id=folder.content_id, |
||
709 | ), |
||
710 | status=200 |
||
711 | ) |
||
712 | content = res.json_body |
||
713 | assert content['content_type'] == 'folder' |
||
714 | assert content['content_id'] == folder.content_id |
||
715 | assert content['status'] == 'open' |
||
716 | |||
717 | # set status |
||
718 | self.testapp.put_json( |
||
719 | '/api/v2/workspaces/{workspace_id}/folders/{content_id}/status'.format( # nopep8 |
||
720 | workspace_id=test_workspace.workspace_id, |
||
721 | content_id=folder.content_id, |
||
722 | ), |
||
723 | params=params, |
||
724 | status=204 |
||
725 | ) |
||
726 | |||
727 | # after |
||
728 | res = self.testapp.get( |
||
729 | '/api/v2/workspaces/{workspace_id}/folders/{content_id}'.format( |
||
730 | workspace_id=test_workspace.workspace_id, |
||
731 | content_id=folder.content_id, |
||
732 | ), |
||
733 | status=200 |
||
734 | ) |
||
735 | content = res.json_body |
||
736 | assert content['content_type'] == 'folder' |
||
737 | assert content['content_id'] == folder.content_id |
||
738 | assert content['status'] == 'closed-deprecated' |
||
739 | |||
740 | View Code Duplication | def test_api__set_folder_status__err_400__wrong_status(self) -> None: |
|
741 | """ |
||
742 | Get one folder content |
||
743 | """ |
||
744 | self.testapp.authorization = ( |
||
745 | 'Basic', |
||
746 | ( |
||
747 | '[email protected]', |
||
748 | '[email protected]' |
||
749 | ) |
||
750 | ) |
||
751 | params = { |
||
752 | 'status': 'unexistant-status', |
||
753 | } |
||
754 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
755 | admin = dbsession.query(models.User) \ |
||
756 | .filter(models.User.email == '[email protected]') \ |
||
757 | .one() |
||
758 | workspace_api = WorkspaceApi( |
||
759 | current_user=admin, |
||
760 | session=dbsession, |
||
761 | config=self.app_config |
||
762 | ) |
||
763 | content_api = ContentApi( |
||
764 | current_user=admin, |
||
765 | session=dbsession, |
||
766 | config=self.app_config |
||
767 | ) |
||
768 | test_workspace = workspace_api.create_workspace( |
||
769 | label='test', |
||
770 | save_now=True, |
||
771 | ) |
||
772 | folder = content_api.create( |
||
773 | label='test_folder', |
||
774 | content_type_slug=CONTENT_TYPES.Folder.slug, |
||
775 | workspace=test_workspace, |
||
776 | do_save=True, |
||
777 | do_notify=False |
||
778 | ) |
||
779 | transaction.commit() |
||
780 | self.testapp.put_json( |
||
781 | '/api/v2/workspaces/{workspace_id}/folders/{content_id}/status'.format( # nopep8 |
||
782 | workspace_id=test_workspace.workspace_id, |
||
783 | content_id=folder.content_id, |
||
784 | ), |
||
785 | params=params, |
||
786 | status=400 |
||
787 | ) |
||
788 | |||
789 | |||
790 | class TestHtmlDocuments(FunctionalTest): |
||
791 | """ |
||
792 | Tests for /api/v2/workspaces/{workspace_id}/html-documents/{content_id} |
||
793 | endpoint |
||
794 | """ |
||
795 | |||
796 | fixtures = [BaseFixture, ContentFixtures] |
||
797 | |||
798 | def test_api__get_html_document__ok_200__legacy_slug(self) -> None: |
||
799 | """ |
||
800 | Get one html document of a content |
||
801 | """ |
||
802 | self.testapp.authorization = ( |
||
803 | 'Basic', |
||
804 | ( |
||
805 | '[email protected]', |
||
806 | '[email protected]' |
||
807 | ) |
||
808 | ) |
||
809 | set_html_document_slug_to_legacy(self.session_factory) |
||
810 | res = self.testapp.get( |
||
811 | '/api/v2/workspaces/2/html-documents/6', |
||
812 | status=200 |
||
813 | ) |
||
814 | content = res.json_body |
||
815 | assert content['content_type'] == 'html-document' |
||
816 | assert content['content_id'] == 6 |
||
817 | assert content['is_archived'] is False |
||
818 | assert content['is_deleted'] is False |
||
819 | assert content['label'] == 'Tiramisu Recipe' |
||
820 | assert content['parent_id'] == 3 |
||
821 | assert content['show_in_ui'] is True |
||
822 | assert content['slug'] == 'tiramisu-recipe' |
||
823 | assert content['status'] == 'open' |
||
824 | assert content['workspace_id'] == 2 |
||
825 | assert content['current_revision_id'] == 27 |
||
826 | # TODO - G.M - 2018-06-173 - check date format |
||
827 | assert content['created'] |
||
828 | assert content['author'] |
||
829 | assert content['author']['user_id'] == 1 |
||
830 | assert content['author']['avatar_url'] is None |
||
831 | assert content['author']['public_name'] == 'Global manager' |
||
832 | # TODO - G.M - 2018-06-173 - check date format |
||
833 | assert content['modified'] |
||
834 | assert content['last_modifier'] != content['author'] |
||
835 | assert content['last_modifier']['user_id'] == 3 |
||
836 | assert content['last_modifier']['public_name'] == 'Bob i.' |
||
837 | assert content['last_modifier']['avatar_url'] is None |
||
838 | assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>' # nopep8 |
||
839 | |||
840 | View Code Duplication | def test_api__get_html_document__ok_200__nominal_case(self) -> None: |
|
841 | """ |
||
842 | Get one html document of a content |
||
843 | """ |
||
844 | self.testapp.authorization = ( |
||
845 | 'Basic', |
||
846 | ( |
||
847 | '[email protected]', |
||
848 | '[email protected]' |
||
849 | ) |
||
850 | ) |
||
851 | res = self.testapp.get( |
||
852 | '/api/v2/workspaces/2/html-documents/6', |
||
853 | status=200 |
||
854 | ) |
||
855 | content = res.json_body |
||
856 | assert content['content_type'] == 'html-document' |
||
857 | assert content['content_id'] == 6 |
||
858 | assert content['is_archived'] is False |
||
859 | assert content['is_deleted'] is False |
||
860 | assert content['label'] == 'Tiramisu Recipe' |
||
861 | assert content['parent_id'] == 3 |
||
862 | assert content['show_in_ui'] is True |
||
863 | assert content['slug'] == 'tiramisu-recipe' |
||
864 | assert content['status'] == 'open' |
||
865 | assert content['workspace_id'] == 2 |
||
866 | assert content['current_revision_id'] == 27 |
||
867 | # TODO - G.M - 2018-06-173 - check date format |
||
868 | assert content['created'] |
||
869 | assert content['author'] |
||
870 | assert content['author']['user_id'] == 1 |
||
871 | assert content['author']['avatar_url'] is None |
||
872 | assert content['author']['public_name'] == 'Global manager' |
||
873 | # TODO - G.M - 2018-06-173 - check date format |
||
874 | assert content['modified'] |
||
875 | assert content['last_modifier'] != content['author'] |
||
876 | assert content['last_modifier']['user_id'] == 3 |
||
877 | assert content['last_modifier']['public_name'] == 'Bob i.' |
||
878 | assert content['last_modifier']['avatar_url'] is None |
||
879 | assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>' # nopep8 |
||
880 | |||
881 | def test_api__get_html_document__ok_200__archived_content(self) -> None: |
||
882 | """ |
||
883 | Get one html document of a content |
||
884 | """ |
||
885 | self.testapp.authorization = ( |
||
886 | 'Basic', |
||
887 | ( |
||
888 | '[email protected]', |
||
889 | '[email protected]' |
||
890 | ) |
||
891 | ) |
||
892 | res = self.testapp.put_json( |
||
893 | '/api/v2/workspaces/2/contents/6/archive', |
||
894 | status=204 |
||
895 | ) |
||
896 | res = self.testapp.get( |
||
897 | '/api/v2/workspaces/2/html-documents/6', |
||
898 | status=200 |
||
899 | ) |
||
900 | content = res.json_body |
||
901 | assert content['content_type'] == 'html-document' |
||
902 | assert content['content_id'] == 6 |
||
903 | assert content['is_archived'] is True |
||
904 | |||
905 | def test_api__get_html_document__ok_200__deleted_content(self) -> None: |
||
906 | """ |
||
907 | Get one html document of a content |
||
908 | """ |
||
909 | self.testapp.authorization = ( |
||
910 | 'Basic', |
||
911 | ( |
||
912 | '[email protected]', |
||
913 | '[email protected]' |
||
914 | ) |
||
915 | ) |
||
916 | res = self.testapp.put_json( |
||
917 | '/api/v2/workspaces/2/contents/6/delete', |
||
918 | status=204 |
||
919 | ) |
||
920 | res = self.testapp.get( |
||
921 | '/api/v2/workspaces/2/html-documents/6', |
||
922 | status=200 |
||
923 | ) |
||
924 | content = res.json_body |
||
925 | assert content['content_type'] == 'html-document' |
||
926 | assert content['content_id'] == 6 |
||
927 | assert content['is_deleted'] is True |
||
928 | |||
929 | def test_api__get_html_document__err_400__wrong_content_type(self) -> None: |
||
930 | """ |
||
931 | Get one html document of a content content 7 is not html_document |
||
932 | """ |
||
933 | self.testapp.authorization = ( |
||
934 | 'Basic', |
||
935 | ( |
||
936 | '[email protected]', |
||
937 | '[email protected]' |
||
938 | ) |
||
939 | ) |
||
940 | self.testapp.get( |
||
941 | '/api/v2/workspaces/2/html-documents/7', |
||
942 | status=400 |
||
943 | ) |
||
944 | |||
945 | def test_api__get_html_document__err_400__content_does_not_exist(self) -> None: # nopep8 |
||
946 | """ |
||
947 | Get one html document of a content (content 170 does not exist in db |
||
948 | """ |
||
949 | self.testapp.authorization = ( |
||
950 | 'Basic', |
||
951 | ( |
||
952 | '[email protected]', |
||
953 | '[email protected]' |
||
954 | ) |
||
955 | ) |
||
956 | self.testapp.get( |
||
957 | '/api/v2/workspaces/2/html-documents/170', |
||
958 | status=400 |
||
959 | ) |
||
960 | |||
961 | def test_api__get_html_document__err_400__content_not_in_workspace(self) -> None: # nopep8 |
||
962 | """ |
||
963 | Get one html document of a content (content 6 is in workspace 2) |
||
964 | """ |
||
965 | self.testapp.authorization = ( |
||
966 | 'Basic', |
||
967 | ( |
||
968 | '[email protected]', |
||
969 | '[email protected]' |
||
970 | ) |
||
971 | ) |
||
972 | self.testapp.get( |
||
973 | '/api/v2/workspaces/1/html-documents/6', |
||
974 | status=400 |
||
975 | ) |
||
976 | |||
977 | def test_api__get_html_document__err_400__workspace_does_not_exist(self) -> None: # nopep8 |
||
978 | """ |
||
979 | Get one html document of a content (Workspace 40 does not exist) |
||
980 | """ |
||
981 | self.testapp.authorization = ( |
||
982 | 'Basic', |
||
983 | ( |
||
984 | '[email protected]', |
||
985 | '[email protected]' |
||
986 | ) |
||
987 | ) |
||
988 | self.testapp.get( |
||
989 | '/api/v2/workspaces/40/html-documents/6', |
||
990 | status=400 |
||
991 | ) |
||
992 | |||
993 | def test_api__get_html_document__err_400__workspace_id_is_not_int(self) -> None: # nopep8 |
||
994 | """ |
||
995 | Get one html document of a content, workspace id is not int |
||
996 | """ |
||
997 | self.testapp.authorization = ( |
||
998 | 'Basic', |
||
999 | ( |
||
1000 | '[email protected]', |
||
1001 | '[email protected]' |
||
1002 | ) |
||
1003 | ) |
||
1004 | self.testapp.get( |
||
1005 | '/api/v2/workspaces/coucou/html-documents/6', |
||
1006 | status=400 |
||
1007 | ) |
||
1008 | |||
1009 | def test_api__get_html_document__err_400__content_id_is_not_int(self) -> None: # nopep8 |
||
1010 | """ |
||
1011 | Get one html document of a content, content_id is not int |
||
1012 | """ |
||
1013 | self.testapp.authorization = ( |
||
1014 | 'Basic', |
||
1015 | ( |
||
1016 | '[email protected]', |
||
1017 | '[email protected]' |
||
1018 | ) |
||
1019 | ) |
||
1020 | self.testapp.get( |
||
1021 | '/api/v2/workspaces/2/html-documents/coucou', |
||
1022 | status=400 |
||
1023 | ) |
||
1024 | |||
1025 | def test_api__update_html_document__err_400__empty_label(self) -> None: # nopep8 |
||
1026 | """ |
||
1027 | Update(put) one html document of a content |
||
1028 | """ |
||
1029 | self.testapp.authorization = ( |
||
1030 | 'Basic', |
||
1031 | ( |
||
1032 | '[email protected]', |
||
1033 | '[email protected]' |
||
1034 | ) |
||
1035 | ) |
||
1036 | params = { |
||
1037 | 'label': '', |
||
1038 | 'raw_content': '<p> Le nouveau contenu </p>', |
||
1039 | } |
||
1040 | self.testapp.put_json( |
||
1041 | '/api/v2/workspaces/2/html-documents/6', |
||
1042 | params=params, |
||
1043 | status=400 |
||
1044 | ) |
||
1045 | |||
1046 | View Code Duplication | def test_api__update_html_document__ok_200__nominal_case(self) -> None: |
|
1047 | """ |
||
1048 | Update(put) one html document of a content |
||
1049 | """ |
||
1050 | self.testapp.authorization = ( |
||
1051 | 'Basic', |
||
1052 | ( |
||
1053 | '[email protected]', |
||
1054 | '[email protected]' |
||
1055 | ) |
||
1056 | ) |
||
1057 | params = { |
||
1058 | 'label': 'My New label', |
||
1059 | 'raw_content': '<p> Le nouveau contenu </p>', |
||
1060 | } |
||
1061 | res = self.testapp.put_json( |
||
1062 | '/api/v2/workspaces/2/html-documents/6', |
||
1063 | params=params, |
||
1064 | status=200 |
||
1065 | ) |
||
1066 | content = res.json_body |
||
1067 | assert content['content_type'] == 'html-document' |
||
1068 | assert content['content_id'] == 6 |
||
1069 | assert content['is_archived'] is False |
||
1070 | assert content['is_deleted'] is False |
||
1071 | assert content['label'] == 'My New label' |
||
1072 | assert content['parent_id'] == 3 |
||
1073 | assert content['show_in_ui'] is True |
||
1074 | assert content['slug'] == 'my-new-label' |
||
1075 | assert content['status'] == 'open' |
||
1076 | assert content['workspace_id'] == 2 |
||
1077 | assert content['current_revision_id'] == 28 |
||
1078 | # TODO - G.M - 2018-06-173 - check date format |
||
1079 | assert content['created'] |
||
1080 | assert content['author'] |
||
1081 | assert content['author']['user_id'] == 1 |
||
1082 | assert content['author']['avatar_url'] is None |
||
1083 | assert content['author']['public_name'] == 'Global manager' |
||
1084 | # TODO - G.M - 2018-06-173 - check date format |
||
1085 | assert content['modified'] |
||
1086 | assert content['last_modifier'] == content['author'] |
||
1087 | assert content['raw_content'] == '<p> Le nouveau contenu </p>' |
||
1088 | |||
1089 | res = self.testapp.get( |
||
1090 | '/api/v2/workspaces/2/html-documents/6', |
||
1091 | status=200 |
||
1092 | ) |
||
1093 | content = res.json_body |
||
1094 | assert content['content_type'] == 'html-document' |
||
1095 | assert content['content_id'] == 6 |
||
1096 | assert content['is_archived'] is False |
||
1097 | assert content['is_deleted'] is False |
||
1098 | assert content['label'] == 'My New label' |
||
1099 | assert content['parent_id'] == 3 |
||
1100 | assert content['show_in_ui'] is True |
||
1101 | assert content['slug'] == 'my-new-label' |
||
1102 | assert content['status'] == 'open' |
||
1103 | assert content['workspace_id'] == 2 |
||
1104 | assert content['current_revision_id'] == 28 |
||
1105 | # TODO - G.M - 2018-06-173 - check date format |
||
1106 | assert content['created'] |
||
1107 | assert content['author'] |
||
1108 | assert content['author']['user_id'] == 1 |
||
1109 | assert content['author']['avatar_url'] is None |
||
1110 | assert content['author']['public_name'] == 'Global manager' |
||
1111 | # TODO - G.M - 2018-06-173 - check date format |
||
1112 | assert content['modified'] |
||
1113 | assert content['last_modifier'] == content['author'] |
||
1114 | assert content['raw_content'] == '<p> Le nouveau contenu </p>' |
||
1115 | |||
1116 | def test_api__get_html_document_revisions__ok_200__nominal_case( |
||
1117 | self |
||
1118 | ) -> None: |
||
1119 | """ |
||
1120 | Get one html document of a content |
||
1121 | """ |
||
1122 | self.testapp.authorization = ( |
||
1123 | 'Basic', |
||
1124 | ( |
||
1125 | '[email protected]', |
||
1126 | '[email protected]' |
||
1127 | ) |
||
1128 | ) |
||
1129 | res = self.testapp.get( |
||
1130 | '/api/v2/workspaces/2/html-documents/6/revisions', |
||
1131 | status=200 |
||
1132 | ) |
||
1133 | revisions = res.json_body |
||
1134 | assert len(revisions) == 3 |
||
1135 | revision = revisions[0] |
||
1136 | assert revision['content_type'] == 'html-document' |
||
1137 | assert revision['content_id'] == 6 |
||
1138 | assert revision['is_archived'] is False |
||
1139 | assert revision['is_deleted'] is False |
||
1140 | assert revision['label'] == 'Tiramisu Recipes!!!' |
||
1141 | assert revision['parent_id'] == 3 |
||
1142 | assert revision['show_in_ui'] is True |
||
1143 | assert revision['slug'] == 'tiramisu-recipes' |
||
1144 | assert revision['status'] == 'open' |
||
1145 | assert revision['workspace_id'] == 2 |
||
1146 | assert revision['revision_id'] == 6 |
||
1147 | assert revision['revision_type'] == 'creation' |
||
1148 | assert revision['sub_content_types'] |
||
1149 | # TODO - G.M - 2018-06-173 - Test with real comments |
||
1150 | assert revision['comment_ids'] == [] |
||
1151 | # TODO - G.M - 2018-06-173 - check date format |
||
1152 | assert revision['created'] |
||
1153 | assert revision['author'] |
||
1154 | assert revision['author']['user_id'] == 1 |
||
1155 | assert revision['author']['avatar_url'] is None |
||
1156 | assert revision['author']['public_name'] == 'Global manager' |
||
1157 | revision = revisions[1] |
||
1158 | assert revision['content_type'] == 'html-document' |
||
1159 | assert revision['content_id'] == 6 |
||
1160 | assert revision['is_archived'] is False |
||
1161 | assert revision['is_deleted'] is False |
||
1162 | assert revision['label'] == 'Tiramisu Recipes!!!' |
||
1163 | assert revision['parent_id'] == 3 |
||
1164 | assert revision['show_in_ui'] is True |
||
1165 | assert revision['slug'] == 'tiramisu-recipes' |
||
1166 | assert revision['status'] == 'open' |
||
1167 | assert revision['workspace_id'] == 2 |
||
1168 | assert revision['revision_id'] == 7 |
||
1169 | assert revision['revision_type'] == 'edition' |
||
1170 | assert revision['sub_content_types'] |
||
1171 | # TODO - G.M - 2018-06-173 - Test with real comments |
||
1172 | assert revision['comment_ids'] == [] |
||
1173 | # TODO - G.M - 2018-06-173 - check date format |
||
1174 | assert revision['created'] |
||
1175 | assert revision['author'] |
||
1176 | assert revision['author']['user_id'] == 1 |
||
1177 | assert revision['author']['avatar_url'] is None |
||
1178 | assert revision['author']['public_name'] == 'Global manager' |
||
1179 | revision = revisions[2] |
||
1180 | assert revision['content_type'] == 'html-document' |
||
1181 | assert revision['content_id'] == 6 |
||
1182 | assert revision['is_archived'] is False |
||
1183 | assert revision['is_deleted'] is False |
||
1184 | assert revision['label'] == 'Tiramisu Recipe' |
||
1185 | assert revision['parent_id'] == 3 |
||
1186 | assert revision['show_in_ui'] is True |
||
1187 | assert revision['slug'] == 'tiramisu-recipe' |
||
1188 | assert revision['status'] == 'open' |
||
1189 | assert revision['workspace_id'] == 2 |
||
1190 | assert revision['revision_id'] == 27 |
||
1191 | assert revision['revision_type'] == 'edition' |
||
1192 | assert revision['sub_content_types'] |
||
1193 | # TODO - G.M - 2018-06-173 - Test with real comments |
||
1194 | assert revision['comment_ids'] == [] |
||
1195 | # TODO - G.M - 2018-06-173 - check date format |
||
1196 | assert revision['created'] |
||
1197 | assert revision['author'] |
||
1198 | assert revision['author']['user_id'] == 3 |
||
1199 | assert revision['author']['avatar_url'] is None |
||
1200 | assert revision['author']['public_name'] == 'Bob i.' |
||
1201 | |||
1202 | View Code Duplication | def test_api__set_html_document_status__ok_200__nominal_case(self) -> None: |
|
1203 | """ |
||
1204 | Get one html document of a content |
||
1205 | """ |
||
1206 | self.testapp.authorization = ( |
||
1207 | 'Basic', |
||
1208 | ( |
||
1209 | '[email protected]', |
||
1210 | '[email protected]' |
||
1211 | ) |
||
1212 | ) |
||
1213 | params = { |
||
1214 | 'status': 'closed-deprecated', |
||
1215 | } |
||
1216 | |||
1217 | # before |
||
1218 | res = self.testapp.get( |
||
1219 | '/api/v2/workspaces/2/html-documents/6', |
||
1220 | status=200 |
||
1221 | ) |
||
1222 | content = res.json_body |
||
1223 | assert content['content_type'] == 'html-document' |
||
1224 | assert content['content_id'] == 6 |
||
1225 | assert content['status'] == 'open' |
||
1226 | |||
1227 | # set status |
||
1228 | self.testapp.put_json( |
||
1229 | '/api/v2/workspaces/2/html-documents/6/status', |
||
1230 | params=params, |
||
1231 | status=204 |
||
1232 | ) |
||
1233 | |||
1234 | # after |
||
1235 | res = self.testapp.get( |
||
1236 | '/api/v2/workspaces/2/html-documents/6', |
||
1237 | status=200 |
||
1238 | ) |
||
1239 | content = res.json_body |
||
1240 | assert content['content_type'] == 'html-document' |
||
1241 | assert content['content_id'] == 6 |
||
1242 | assert content['status'] == 'closed-deprecated' |
||
1243 | |||
1244 | def test_api__set_html_document_status__err_400__wrong_status(self) -> None: |
||
1245 | """ |
||
1246 | Get one html document of a content |
||
1247 | """ |
||
1248 | self.testapp.authorization = ( |
||
1249 | 'Basic', |
||
1250 | ( |
||
1251 | '[email protected]', |
||
1252 | '[email protected]' |
||
1253 | ) |
||
1254 | ) |
||
1255 | params = { |
||
1256 | 'status': 'unexistant-status', |
||
1257 | } |
||
1258 | self.testapp.put_json( |
||
1259 | '/api/v2/workspaces/2/html-documents/6/status', |
||
1260 | params=params, |
||
1261 | status=400 |
||
1262 | ) |
||
1263 | |||
1264 | |||
1265 | class TestFiles(FunctionalTest): |
||
1266 | """ |
||
1267 | Tests for /api/v2/workspaces/{workspace_id}/files/{content_id} |
||
1268 | endpoint |
||
1269 | """ |
||
1270 | |||
1271 | fixtures = [BaseFixture, ContentFixtures] |
||
1272 | |||
1273 | View Code Duplication | def test_api__get_file__ok_200__nominal_case(self) -> None: |
|
1274 | """ |
||
1275 | Get one file of a content |
||
1276 | """ |
||
1277 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
1278 | admin = dbsession.query(models.User) \ |
||
1279 | .filter(models.User.email == '[email protected]') \ |
||
1280 | .one() |
||
1281 | workspace_api = WorkspaceApi( |
||
1282 | current_user=admin, |
||
1283 | session=dbsession, |
||
1284 | config=self.app_config |
||
1285 | ) |
||
1286 | content_api = ContentApi( |
||
1287 | current_user=admin, |
||
1288 | session=dbsession, |
||
1289 | config=self.app_config |
||
1290 | ) |
||
1291 | business_workspace = workspace_api.get_one(1) |
||
1292 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
1293 | test_file = content_api.create( |
||
1294 | content_type_slug=CONTENT_TYPES.File.slug, |
||
1295 | workspace=business_workspace, |
||
1296 | parent=tool_folder, |
||
1297 | label='Test file', |
||
1298 | do_save=False, |
||
1299 | do_notify=False, |
||
1300 | ) |
||
1301 | content_api.update_file_data( |
||
1302 | test_file, |
||
1303 | 'Test_file.txt', |
||
1304 | new_mimetype='plain/text', |
||
1305 | new_content=b'Test file', |
||
1306 | ) |
||
1307 | test_file.file_mimetype = test_file.depot_file.content_type |
||
1308 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
||
1309 | dbsession.flush() |
||
1310 | transaction.commit() |
||
1311 | |||
1312 | self.testapp.authorization = ( |
||
1313 | 'Basic', |
||
1314 | ( |
||
1315 | '[email protected]', |
||
1316 | '[email protected]' |
||
1317 | ) |
||
1318 | ) |
||
1319 | res = self.testapp.get( |
||
1320 | '/api/v2/workspaces/1/files/{}'.format(test_file.content_id), |
||
1321 | status=200 |
||
1322 | ) |
||
1323 | content = res.json_body |
||
1324 | assert content['content_type'] == 'file' |
||
1325 | assert content['content_id'] == test_file.content_id |
||
1326 | assert content['is_archived'] is False |
||
1327 | assert content['is_deleted'] is False |
||
1328 | assert content['label'] == 'Test_file' |
||
1329 | assert content['parent_id'] == 1 |
||
1330 | assert content['show_in_ui'] is True |
||
1331 | assert content['slug'] == 'test-file' |
||
1332 | assert content['status'] == 'open' |
||
1333 | assert content['workspace_id'] == 1 |
||
1334 | assert content['current_revision_id'] |
||
1335 | # TODO - G.M - 2018-06-173 - check date format |
||
1336 | assert content['created'] |
||
1337 | assert content['author'] |
||
1338 | assert content['author']['user_id'] == 1 |
||
1339 | assert content['author']['avatar_url'] is None |
||
1340 | assert content['author']['public_name'] == 'Global manager' |
||
1341 | # TODO - G.M - 2018-06-173 - check date format |
||
1342 | assert content['modified'] |
||
1343 | assert content['last_modifier'] == content['author'] |
||
1344 | assert content['raw_content'] == '<p>description</p>' # nopep8 |
||
1345 | assert content['mimetype'] == 'plain/text' |
||
1346 | assert content['size'] == len(b'Test file') |
||
1347 | assert content['page_nb'] == 1 |
||
1348 | |||
1349 | def test_api__get_file__ok_200__no_file_add(self) -> None: |
||
1350 | """ |
||
1351 | Get one file of a content |
||
1352 | """ |
||
1353 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
1354 | admin = dbsession.query(models.User) \ |
||
1355 | .filter(models.User.email == '[email protected]') \ |
||
1356 | .one() |
||
1357 | workspace_api = WorkspaceApi( |
||
1358 | current_user=admin, |
||
1359 | session=dbsession, |
||
1360 | config=self.app_config |
||
1361 | ) |
||
1362 | content_api = ContentApi( |
||
1363 | current_user=admin, |
||
1364 | session=dbsession, |
||
1365 | config=self.app_config |
||
1366 | ) |
||
1367 | business_workspace = workspace_api.get_one(1) |
||
1368 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
1369 | test_file = content_api.create( |
||
1370 | content_type_slug=CONTENT_TYPES.File.slug, |
||
1371 | workspace=business_workspace, |
||
1372 | parent=tool_folder, |
||
1373 | label='Test file', |
||
1374 | do_save=True, |
||
1375 | do_notify=False, |
||
1376 | ) |
||
1377 | dbsession.flush() |
||
1378 | transaction.commit() |
||
1379 | |||
1380 | self.testapp.authorization = ( |
||
1381 | 'Basic', |
||
1382 | ( |
||
1383 | '[email protected]', |
||
1384 | '[email protected]' |
||
1385 | ) |
||
1386 | ) |
||
1387 | res = self.testapp.get( |
||
1388 | '/api/v2/workspaces/1/files/{}'.format(test_file.content_id), |
||
1389 | status=200 |
||
1390 | ) |
||
1391 | content = res.json_body |
||
1392 | assert content['content_type'] == 'file' |
||
1393 | assert content['content_id'] == test_file.content_id |
||
1394 | assert content['is_archived'] is False |
||
1395 | assert content['is_deleted'] is False |
||
1396 | assert content['label'] == 'Test file' |
||
1397 | assert content['parent_id'] == 1 |
||
1398 | assert content['show_in_ui'] is True |
||
1399 | assert content['slug'] == 'test-file' |
||
1400 | assert content['status'] == 'open' |
||
1401 | assert content['workspace_id'] == 1 |
||
1402 | assert content['current_revision_id'] |
||
1403 | # TODO - G.M - 2018-06-173 - check date format |
||
1404 | assert content['created'] |
||
1405 | assert content['author'] |
||
1406 | assert content['author']['user_id'] == 1 |
||
1407 | assert content['author']['avatar_url'] is None |
||
1408 | assert content['author']['public_name'] == 'Global manager' |
||
1409 | # TODO - G.M - 2018-06-173 - check date format |
||
1410 | assert content['modified'] |
||
1411 | assert content['last_modifier'] == content['author'] |
||
1412 | assert content['raw_content'] == '' |
||
1413 | assert content['mimetype'] == '' |
||
1414 | assert content['size'] is None |
||
1415 | assert content['page_nb'] is None |
||
1416 | |||
1417 | def test_api__get_files__err_400__wrong_content_type(self) -> None: |
||
1418 | """ |
||
1419 | Get one file of a content content |
||
1420 | """ |
||
1421 | self.testapp.authorization = ( |
||
1422 | 'Basic', |
||
1423 | ( |
||
1424 | '[email protected]', |
||
1425 | '[email protected]' |
||
1426 | ) |
||
1427 | ) |
||
1428 | self.testapp.get( |
||
1429 | '/api/v2/workspaces/2/files/6', |
||
1430 | status=400 |
||
1431 | ) |
||
1432 | |||
1433 | def test_api__get_file__err_400__content_does_not_exist(self) -> None: # nopep8 |
||
1434 | """ |
||
1435 | Get one file (content 170 does not exist in db |
||
1436 | """ |
||
1437 | self.testapp.authorization = ( |
||
1438 | 'Basic', |
||
1439 | ( |
||
1440 | '[email protected]', |
||
1441 | '[email protected]' |
||
1442 | ) |
||
1443 | ) |
||
1444 | self.testapp.get( |
||
1445 | '/api/v2/workspaces/1/files/170', |
||
1446 | status=400 |
||
1447 | ) |
||
1448 | |||
1449 | def test_api__get_file__err_400__content_not_in_workspace(self) -> None: # nopep8 |
||
1450 | """ |
||
1451 | Get one file (content 9 is in workspace 2) |
||
1452 | """ |
||
1453 | self.testapp.authorization = ( |
||
1454 | 'Basic', |
||
1455 | ( |
||
1456 | '[email protected]', |
||
1457 | '[email protected]' |
||
1458 | ) |
||
1459 | ) |
||
1460 | self.testapp.get( |
||
1461 | '/api/v2/workspaces/1/files/9', |
||
1462 | status=400 |
||
1463 | ) |
||
1464 | |||
1465 | def test_api__get_file__err_400__workspace_does_not_exist(self) -> None: # nopep8 |
||
1466 | """ |
||
1467 | Get one file (Workspace 40 does not exist) |
||
1468 | """ |
||
1469 | self.testapp.authorization = ( |
||
1470 | 'Basic', |
||
1471 | ( |
||
1472 | '[email protected]', |
||
1473 | '[email protected]' |
||
1474 | ) |
||
1475 | ) |
||
1476 | self.testapp.get( |
||
1477 | '/api/v2/workspaces/40/files/9', |
||
1478 | status=400 |
||
1479 | ) |
||
1480 | |||
1481 | def test_api__get_file__err_400__workspace_id_is_not_int(self) -> None: # nopep8 |
||
1482 | """ |
||
1483 | Get one file, workspace id is not int |
||
1484 | """ |
||
1485 | self.testapp.authorization = ( |
||
1486 | 'Basic', |
||
1487 | ( |
||
1488 | '[email protected]', |
||
1489 | '[email protected]' |
||
1490 | ) |
||
1491 | ) |
||
1492 | self.testapp.get( |
||
1493 | '/api/v2/workspaces/coucou/files/9', |
||
1494 | status=400 |
||
1495 | ) |
||
1496 | |||
1497 | def test_api__get_file__err_400__content_id_is_not_int(self) -> None: # nopep8 |
||
1498 | """ |
||
1499 | Get one file, content_id is not int |
||
1500 | """ |
||
1501 | self.testapp.authorization = ( |
||
1502 | 'Basic', |
||
1503 | ( |
||
1504 | '[email protected]', |
||
1505 | '[email protected]' |
||
1506 | ) |
||
1507 | ) |
||
1508 | self.testapp.get( |
||
1509 | '/api/v2/workspaces/2/files/coucou', |
||
1510 | status=400 |
||
1511 | ) |
||
1512 | |||
1513 | def test_api__update_file_info_err_400__empty_label(self) -> None: # nopep8 |
||
1514 | """ |
||
1515 | Update(put) one file |
||
1516 | """ |
||
1517 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
1518 | admin = dbsession.query(models.User) \ |
||
1519 | .filter(models.User.email == '[email protected]') \ |
||
1520 | .one() |
||
1521 | workspace_api = WorkspaceApi( |
||
1522 | current_user=admin, |
||
1523 | session=dbsession, |
||
1524 | config=self.app_config |
||
1525 | ) |
||
1526 | content_api = ContentApi( |
||
1527 | current_user=admin, |
||
1528 | session=dbsession, |
||
1529 | config=self.app_config |
||
1530 | ) |
||
1531 | business_workspace = workspace_api.get_one(1) |
||
1532 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
1533 | test_file = content_api.create( |
||
1534 | content_type_slug=CONTENT_TYPES.File.slug, |
||
1535 | workspace=business_workspace, |
||
1536 | parent=tool_folder, |
||
1537 | label='Test file', |
||
1538 | do_save=False, |
||
1539 | do_notify=False, |
||
1540 | ) |
||
1541 | content_api.update_file_data( |
||
1542 | test_file, |
||
1543 | 'Test_file.txt', |
||
1544 | new_mimetype='plain/text', |
||
1545 | new_content=b'Test file', |
||
1546 | ) |
||
1547 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
||
1548 | dbsession.flush() |
||
1549 | transaction.commit() |
||
1550 | |||
1551 | self.testapp.authorization = ( |
||
1552 | 'Basic', |
||
1553 | ( |
||
1554 | '[email protected]', |
||
1555 | '[email protected]' |
||
1556 | ) |
||
1557 | ) |
||
1558 | params = { |
||
1559 | 'label': '', |
||
1560 | 'raw_content': '<p> Le nouveau contenu </p>', |
||
1561 | } |
||
1562 | self.testapp.put_json( |
||
1563 | '/api/v2/workspaces/1/files/{}'.format(test_file.content_id), |
||
1564 | params=params, |
||
1565 | status=400 |
||
1566 | ) |
||
1567 | |||
1568 | def test_api__update_file_info__ok_200__nominal_case(self) -> None: |
||
1569 | """ |
||
1570 | Update(put) one file |
||
1571 | """ |
||
1572 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
1573 | admin = dbsession.query(models.User) \ |
||
1574 | .filter(models.User.email == '[email protected]') \ |
||
1575 | .one() |
||
1576 | workspace_api = WorkspaceApi( |
||
1577 | current_user=admin, |
||
1578 | session=dbsession, |
||
1579 | config=self.app_config |
||
1580 | ) |
||
1581 | content_api = ContentApi( |
||
1582 | current_user=admin, |
||
1583 | session=dbsession, |
||
1584 | config=self.app_config |
||
1585 | ) |
||
1586 | business_workspace = workspace_api.get_one(1) |
||
1587 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
1588 | test_file = content_api.create( |
||
1589 | content_type_slug=CONTENT_TYPES.File.slug, |
||
1590 | workspace=business_workspace, |
||
1591 | parent=tool_folder, |
||
1592 | label='Test file', |
||
1593 | do_save=False, |
||
1594 | do_notify=False, |
||
1595 | ) |
||
1596 | content_api.update_file_data( |
||
1597 | test_file, |
||
1598 | 'Test_file.txt', |
||
1599 | new_mimetype='plain/text', |
||
1600 | new_content=b'Test file', |
||
1601 | ) |
||
1602 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
||
1603 | dbsession.flush() |
||
1604 | transaction.commit() |
||
1605 | |||
1606 | self.testapp.authorization = ( |
||
1607 | 'Basic', |
||
1608 | ( |
||
1609 | '[email protected]', |
||
1610 | '[email protected]' |
||
1611 | ) |
||
1612 | ) |
||
1613 | params = { |
||
1614 | 'label': 'My New label', |
||
1615 | 'raw_content': '<p> Le nouveau contenu </p>', |
||
1616 | } |
||
1617 | res = self.testapp.put_json( |
||
1618 | '/api/v2/workspaces/1/files/{}'.format(test_file.content_id), |
||
1619 | params=params, |
||
1620 | status=200 |
||
1621 | ) |
||
1622 | content = res.json_body |
||
1623 | assert content['content_type'] == 'file' |
||
1624 | assert content['content_id'] == test_file.content_id |
||
1625 | assert content['is_archived'] is False |
||
1626 | assert content['is_deleted'] is False |
||
1627 | assert content['label'] == 'My New label' |
||
1628 | assert content['parent_id'] == 1 |
||
1629 | assert content['show_in_ui'] is True |
||
1630 | assert content['slug'] == 'my-new-label' |
||
1631 | assert content['status'] == 'open' |
||
1632 | assert content['workspace_id'] == 1 |
||
1633 | assert content['current_revision_id'] |
||
1634 | # TODO - G.M - 2018-06-173 - check date format |
||
1635 | assert content['created'] |
||
1636 | assert content['author'] |
||
1637 | assert content['author']['user_id'] == 1 |
||
1638 | assert content['author']['avatar_url'] is None |
||
1639 | assert content['author']['public_name'] == 'Global manager' |
||
1640 | # TODO - G.M - 2018-06-173 - check date format |
||
1641 | assert content['modified'] |
||
1642 | assert content['last_modifier'] == content['author'] |
||
1643 | assert content['raw_content'] == '<p> Le nouveau contenu </p>' |
||
1644 | assert content['mimetype'] == 'plain/text' |
||
1645 | assert content['size'] == len(b'Test file') |
||
1646 | assert content['page_nb'] == 1 |
||
1647 | |||
1648 | res = self.testapp.get( |
||
1649 | '/api/v2/workspaces/1/files/{}'.format(test_file.content_id), |
||
1650 | status=200 |
||
1651 | ) |
||
1652 | content = res.json_body |
||
1653 | assert content['content_type'] == 'file' |
||
1654 | assert content['content_id'] == test_file.content_id |
||
1655 | assert content['is_archived'] is False |
||
1656 | assert content['is_deleted'] is False |
||
1657 | assert content['label'] == 'My New label' |
||
1658 | assert content['parent_id'] == 1 |
||
1659 | assert content['show_in_ui'] is True |
||
1660 | assert content['slug'] == 'my-new-label' |
||
1661 | assert content['status'] == 'open' |
||
1662 | assert content['workspace_id'] == 1 |
||
1663 | assert content['current_revision_id'] |
||
1664 | # TODO - G.M - 2018-06-173 - check date format |
||
1665 | assert content['created'] |
||
1666 | assert content['author'] |
||
1667 | assert content['author']['user_id'] == 1 |
||
1668 | assert content['author']['avatar_url'] is None |
||
1669 | assert content['author']['public_name'] == 'Global manager' |
||
1670 | # TODO - G.M - 2018-06-173 - check date format |
||
1671 | assert content['modified'] |
||
1672 | assert content['last_modifier'] == content['author'] |
||
1673 | assert content['raw_content'] == '<p> Le nouveau contenu </p>' |
||
1674 | assert content['mimetype'] == 'plain/text' |
||
1675 | assert content['size'] == len(b'Test file') |
||
1676 | assert content['page_nb'] == 1 |
||
1677 | |||
1678 | View Code Duplication | def test_api__get_file_revisions__ok_200__nominal_case( |
|
1679 | self |
||
1680 | ) -> None: |
||
1681 | """ |
||
1682 | Get file revisions |
||
1683 | """ |
||
1684 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
1685 | admin = dbsession.query(models.User) \ |
||
1686 | .filter(models.User.email == '[email protected]') \ |
||
1687 | .one() |
||
1688 | workspace_api = WorkspaceApi( |
||
1689 | current_user=admin, |
||
1690 | session=dbsession, |
||
1691 | config=self.app_config |
||
1692 | ) |
||
1693 | content_api = ContentApi( |
||
1694 | current_user=admin, |
||
1695 | session=dbsession, |
||
1696 | config=self.app_config |
||
1697 | ) |
||
1698 | business_workspace = workspace_api.get_one(1) |
||
1699 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
1700 | test_file = content_api.create( |
||
1701 | content_type_slug=CONTENT_TYPES.File.slug, |
||
1702 | workspace=business_workspace, |
||
1703 | parent=tool_folder, |
||
1704 | label='Test file', |
||
1705 | do_save=False, |
||
1706 | do_notify=False, |
||
1707 | ) |
||
1708 | content_api.update_file_data( |
||
1709 | test_file, |
||
1710 | 'Test_file.txt', |
||
1711 | new_mimetype='plain/text', |
||
1712 | new_content=b'Test file', |
||
1713 | ) |
||
1714 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
||
1715 | dbsession.flush() |
||
1716 | transaction.commit() |
||
1717 | |||
1718 | self.testapp.authorization = ( |
||
1719 | 'Basic', |
||
1720 | ( |
||
1721 | '[email protected]', |
||
1722 | '[email protected]' |
||
1723 | ) |
||
1724 | ) |
||
1725 | res = self.testapp.get( |
||
1726 | '/api/v2/workspaces/1/files/{}/revisions'.format(test_file.content_id), # nopep8 |
||
1727 | status=200 |
||
1728 | ) |
||
1729 | revisions = res.json_body |
||
1730 | assert len(revisions) == 1 |
||
1731 | revision = revisions[0] |
||
1732 | assert revision['content_type'] == 'file' |
||
1733 | assert revision['content_id'] == test_file.content_id |
||
1734 | assert revision['is_archived'] is False |
||
1735 | assert revision['is_deleted'] is False |
||
1736 | assert revision['label'] == 'Test_file' |
||
1737 | assert revision['parent_id'] == 1 |
||
1738 | assert revision['show_in_ui'] is True |
||
1739 | assert revision['slug'] == 'test-file' |
||
1740 | assert revision['status'] == 'open' |
||
1741 | assert revision['workspace_id'] == 1 |
||
1742 | assert revision['revision_id'] |
||
1743 | assert revision['sub_content_types'] |
||
1744 | # TODO - G.M - 2018-06-173 - Test with real comments |
||
1745 | assert revision['comment_ids'] == [] |
||
1746 | # TODO - G.M - 2018-06-173 - check date format |
||
1747 | assert revision['created'] |
||
1748 | assert revision['author'] |
||
1749 | assert revision['author']['user_id'] == 1 |
||
1750 | assert revision['author']['avatar_url'] is None |
||
1751 | assert revision['author']['public_name'] == 'Global manager' |
||
1752 | assert revision['mimetype'] == 'plain/text' |
||
1753 | assert revision['size'] == len(b'Test file') |
||
1754 | assert revision['page_nb'] == 1 |
||
1755 | |||
1756 | def test_api__set_file_status__ok_200__nominal_case(self) -> None: |
||
1757 | """ |
||
1758 | set file status |
||
1759 | """ |
||
1760 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
1761 | admin = dbsession.query(models.User) \ |
||
1762 | .filter(models.User.email == '[email protected]') \ |
||
1763 | .one() |
||
1764 | workspace_api = WorkspaceApi( |
||
1765 | current_user=admin, |
||
1766 | session=dbsession, |
||
1767 | config=self.app_config |
||
1768 | ) |
||
1769 | content_api = ContentApi( |
||
1770 | current_user=admin, |
||
1771 | session=dbsession, |
||
1772 | config=self.app_config |
||
1773 | ) |
||
1774 | business_workspace = workspace_api.get_one(1) |
||
1775 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
1776 | test_file = content_api.create( |
||
1777 | content_type_slug=CONTENT_TYPES.File.slug, |
||
1778 | workspace=business_workspace, |
||
1779 | parent=tool_folder, |
||
1780 | label='Test file', |
||
1781 | do_save=False, |
||
1782 | do_notify=False, |
||
1783 | ) |
||
1784 | test_file.file_extension = '.txt' |
||
1785 | test_file.depot_file = FileIntent( |
||
1786 | b'Test file', |
||
1787 | 'Test_file.txt', |
||
1788 | 'text/plain', |
||
1789 | ) |
||
1790 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
||
1791 | dbsession.flush() |
||
1792 | transaction.commit() |
||
1793 | |||
1794 | self.testapp.authorization = ( |
||
1795 | 'Basic', |
||
1796 | ( |
||
1797 | '[email protected]', |
||
1798 | '[email protected]' |
||
1799 | ) |
||
1800 | ) |
||
1801 | params = { |
||
1802 | 'status': 'closed-deprecated', |
||
1803 | } |
||
1804 | |||
1805 | # before |
||
1806 | res = self.testapp.get( |
||
1807 | '/api/v2/workspaces/1/files/{}'.format(test_file.content_id), |
||
1808 | status=200 |
||
1809 | ) |
||
1810 | content = res.json_body |
||
1811 | assert content['content_type'] == 'file' |
||
1812 | assert content['content_id'] == test_file.content_id |
||
1813 | assert content['status'] == 'open' |
||
1814 | |||
1815 | # set status |
||
1816 | self.testapp.put_json( |
||
1817 | '/api/v2/workspaces/1/files/{}/status'.format(test_file.content_id), |
||
1818 | params=params, |
||
1819 | status=204 |
||
1820 | ) |
||
1821 | |||
1822 | # after |
||
1823 | res = self.testapp.get( |
||
1824 | '/api/v2/workspaces/1/files/{}'.format(test_file.content_id), |
||
1825 | status=200 |
||
1826 | ) |
||
1827 | content = res.json_body |
||
1828 | assert content['content_type'] == 'file' |
||
1829 | assert content['content_id'] == test_file.content_id |
||
1830 | assert content['status'] == 'closed-deprecated' |
||
1831 | |||
1832 | def test_api__set_file_status__err_400__wrong_status(self) -> None: |
||
1833 | """ |
||
1834 | set file status |
||
1835 | """ |
||
1836 | self.testapp.authorization = ( |
||
1837 | 'Basic', |
||
1838 | ( |
||
1839 | '[email protected]', |
||
1840 | '[email protected]' |
||
1841 | ) |
||
1842 | ) |
||
1843 | params = { |
||
1844 | 'status': 'unexistant-status', |
||
1845 | } |
||
1846 | self.testapp.put_json( |
||
1847 | '/api/v2/workspaces/2/files/6/status', |
||
1848 | params=params, |
||
1849 | status=400 |
||
1850 | ) |
||
1851 | |||
1852 | def test_api__get_file_raw__ok_200__nominal_case(self) -> None: |
||
1853 | """ |
||
1854 | Get one file of a content |
||
1855 | """ |
||
1856 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
1857 | admin = dbsession.query(models.User) \ |
||
1858 | .filter(models.User.email == '[email protected]') \ |
||
1859 | .one() |
||
1860 | workspace_api = WorkspaceApi( |
||
1861 | current_user=admin, |
||
1862 | session=dbsession, |
||
1863 | config=self.app_config |
||
1864 | ) |
||
1865 | content_api = ContentApi( |
||
1866 | current_user=admin, |
||
1867 | session=dbsession, |
||
1868 | config=self.app_config |
||
1869 | ) |
||
1870 | business_workspace = workspace_api.get_one(1) |
||
1871 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
1872 | test_file = content_api.create( |
||
1873 | content_type_slug=CONTENT_TYPES.File.slug, |
||
1874 | workspace=business_workspace, |
||
1875 | parent=tool_folder, |
||
1876 | label='Test file', |
||
1877 | do_save=False, |
||
1878 | do_notify=False, |
||
1879 | ) |
||
1880 | test_file.file_extension = '.txt' |
||
1881 | test_file.depot_file = FileIntent( |
||
1882 | b'Test file', |
||
1883 | 'Test_file.txt', |
||
1884 | 'text/plain', |
||
1885 | ) |
||
1886 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
||
1887 | dbsession.flush() |
||
1888 | transaction.commit() |
||
1889 | content_id = int(test_file.content_id) |
||
1890 | self.testapp.authorization = ( |
||
1891 | 'Basic', |
||
1892 | ( |
||
1893 | '[email protected]', |
||
1894 | '[email protected]' |
||
1895 | ) |
||
1896 | ) |
||
1897 | res = self.testapp.get( |
||
1898 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
1899 | status=200 |
||
1900 | ) |
||
1901 | assert res.body == b'Test file' |
||
1902 | assert res.content_type == 'text/plain' |
||
1903 | assert res.content_length == len(b'Test file') |
||
1904 | |||
1905 | def test_api__set_file_raw__ok_200__nominal_case(self) -> None: |
||
1906 | """ |
||
1907 | Set one file of a content |
||
1908 | """ |
||
1909 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
1910 | admin = dbsession.query(models.User) \ |
||
1911 | .filter(models.User.email == '[email protected]') \ |
||
1912 | .one() |
||
1913 | workspace_api = WorkspaceApi( |
||
1914 | current_user=admin, |
||
1915 | session=dbsession, |
||
1916 | config=self.app_config |
||
1917 | ) |
||
1918 | content_api = ContentApi( |
||
1919 | current_user=admin, |
||
1920 | session=dbsession, |
||
1921 | config=self.app_config |
||
1922 | ) |
||
1923 | business_workspace = workspace_api.get_one(1) |
||
1924 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
1925 | test_file = content_api.create( |
||
1926 | content_type_slug=CONTENT_TYPES.File.slug, |
||
1927 | workspace=business_workspace, |
||
1928 | parent=tool_folder, |
||
1929 | label='Test file', |
||
1930 | do_save=True, |
||
1931 | do_notify=False, |
||
1932 | ) |
||
1933 | dbsession.flush() |
||
1934 | transaction.commit() |
||
1935 | content_id = int(test_file.content_id) |
||
1936 | image = create_1000px_png_test_image() |
||
1937 | self.testapp.authorization = ( |
||
1938 | 'Basic', |
||
1939 | ( |
||
1940 | '[email protected]', |
||
1941 | '[email protected]' |
||
1942 | ) |
||
1943 | ) |
||
1944 | self.testapp.put( |
||
1945 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
1946 | upload_files=[ |
||
1947 | ('files', image.name, image.getvalue()) |
||
1948 | ], |
||
1949 | status=204, |
||
1950 | ) |
||
1951 | res = self.testapp.get( |
||
1952 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
1953 | status=200 |
||
1954 | ) |
||
1955 | assert res.body == image.getvalue() |
||
1956 | assert res.content_type == 'image/png' |
||
1957 | assert res.content_length == len(image.getvalue()) |
||
1958 | |||
1959 | def test_api__get_allowed_size_dim__ok__nominal_case(self) -> None: |
||
1960 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
1961 | admin = dbsession.query(models.User) \ |
||
1962 | .filter(models.User.email == '[email protected]') \ |
||
1963 | .one() |
||
1964 | workspace_api = WorkspaceApi( |
||
1965 | current_user=admin, |
||
1966 | session=dbsession, |
||
1967 | config=self.app_config |
||
1968 | ) |
||
1969 | content_api = ContentApi( |
||
1970 | current_user=admin, |
||
1971 | session=dbsession, |
||
1972 | config=self.app_config |
||
1973 | ) |
||
1974 | business_workspace = workspace_api.get_one(1) |
||
1975 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
1976 | test_file = content_api.create( |
||
1977 | content_type_slug=CONTENT_TYPES.File.slug, |
||
1978 | workspace=business_workspace, |
||
1979 | parent=tool_folder, |
||
1980 | label='Test file', |
||
1981 | do_save=False, |
||
1982 | do_notify=False, |
||
1983 | ) |
||
1984 | test_file.file_extension = '.txt' |
||
1985 | test_file.depot_file = FileIntent( |
||
1986 | b'Test file', |
||
1987 | 'Test_file.txt', |
||
1988 | 'text/plain', |
||
1989 | ) |
||
1990 | dbsession.flush() |
||
1991 | transaction.commit() |
||
1992 | self.testapp.authorization = ( |
||
1993 | 'Basic', |
||
1994 | ( |
||
1995 | '[email protected]', |
||
1996 | '[email protected]' |
||
1997 | ) |
||
1998 | ) |
||
1999 | content_id = int(test_file.content_id) |
||
2000 | res = self.testapp.get( |
||
2001 | '/api/v2/workspaces/1/files/{}/preview/jpg/allowed_dims'.format(content_id), # nopep8 |
||
2002 | status=200, |
||
2003 | ) |
||
2004 | res = res.json_body |
||
2005 | assert res['restricted'] is True |
||
2006 | assert len(res['dimensions']) == 1 |
||
2007 | dim = res['dimensions'][0] |
||
2008 | assert dim['width'] == 256 |
||
2009 | assert dim['height'] == 256 |
||
2010 | |||
2011 | View Code Duplication | def test_api__get_jpeg_preview__ok__200__nominal_case(self) -> None: |
|
2012 | """ |
||
2013 | Set one file of a content |
||
2014 | """ |
||
2015 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
2016 | admin = dbsession.query(models.User) \ |
||
2017 | .filter(models.User.email == '[email protected]') \ |
||
2018 | .one() |
||
2019 | workspace_api = WorkspaceApi( |
||
2020 | current_user=admin, |
||
2021 | session=dbsession, |
||
2022 | config=self.app_config |
||
2023 | ) |
||
2024 | content_api = ContentApi( |
||
2025 | current_user=admin, |
||
2026 | session=dbsession, |
||
2027 | config=self.app_config |
||
2028 | ) |
||
2029 | business_workspace = workspace_api.get_one(1) |
||
2030 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
2031 | test_file = content_api.create( |
||
2032 | content_type_slug=CONTENT_TYPES.File.slug, |
||
2033 | workspace=business_workspace, |
||
2034 | parent=tool_folder, |
||
2035 | label='Test file', |
||
2036 | do_save=False, |
||
2037 | do_notify=False, |
||
2038 | ) |
||
2039 | test_file.file_extension = '.txt' |
||
2040 | test_file.depot_file = FileIntent( |
||
2041 | b'Test file', |
||
2042 | 'Test_file.txt', |
||
2043 | 'text/plain', |
||
2044 | ) |
||
2045 | dbsession.flush() |
||
2046 | transaction.commit() |
||
2047 | content_id = int(test_file.content_id) |
||
2048 | image = create_1000px_png_test_image() |
||
2049 | self.testapp.authorization = ( |
||
2050 | 'Basic', |
||
2051 | ( |
||
2052 | '[email protected]', |
||
2053 | '[email protected]' |
||
2054 | ) |
||
2055 | ) |
||
2056 | self.testapp.put( |
||
2057 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
2058 | upload_files=[ |
||
2059 | ('files', image.name, image.getvalue()) |
||
2060 | ], |
||
2061 | status=204, |
||
2062 | ) |
||
2063 | res = self.testapp.get( |
||
2064 | '/api/v2/workspaces/1/files/{}/preview/jpg'.format(content_id), |
||
2065 | status=200 |
||
2066 | ) |
||
2067 | assert res.body != image.getvalue() |
||
2068 | assert res.content_type == 'image/jpeg' |
||
2069 | |||
2070 | View Code Duplication | def test_api__get_sized_jpeg_preview__ok__200__nominal_case(self) -> None: |
|
2071 | """ |
||
2072 | get 256x256 preview of a txt file |
||
2073 | """ |
||
2074 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
2075 | admin = dbsession.query(models.User) \ |
||
2076 | .filter(models.User.email == '[email protected]') \ |
||
2077 | .one() |
||
2078 | workspace_api = WorkspaceApi( |
||
2079 | current_user=admin, |
||
2080 | session=dbsession, |
||
2081 | config=self.app_config |
||
2082 | ) |
||
2083 | content_api = ContentApi( |
||
2084 | current_user=admin, |
||
2085 | session=dbsession, |
||
2086 | config=self.app_config |
||
2087 | ) |
||
2088 | business_workspace = workspace_api.get_one(1) |
||
2089 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
2090 | test_file = content_api.create( |
||
2091 | content_type_slug=CONTENT_TYPES.File.slug, |
||
2092 | workspace=business_workspace, |
||
2093 | parent=tool_folder, |
||
2094 | label='Test file', |
||
2095 | do_save=True, |
||
2096 | do_notify=False, |
||
2097 | ) |
||
2098 | dbsession.flush() |
||
2099 | transaction.commit() |
||
2100 | content_id = int(test_file.content_id) |
||
2101 | image = create_1000px_png_test_image() |
||
2102 | self.testapp.authorization = ( |
||
2103 | 'Basic', |
||
2104 | ( |
||
2105 | '[email protected]', |
||
2106 | '[email protected]' |
||
2107 | ) |
||
2108 | ) |
||
2109 | self.testapp.put( |
||
2110 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
2111 | upload_files=[ |
||
2112 | ('files', image.name, image.getvalue()) |
||
2113 | ], |
||
2114 | status=204, |
||
2115 | ) |
||
2116 | res = self.testapp.get( |
||
2117 | '/api/v2/workspaces/1/files/{}/preview/jpg/256x256'.format(content_id), # nopep8 |
||
2118 | status=200 |
||
2119 | ) |
||
2120 | assert res.body != image.getvalue() |
||
2121 | assert res.content_type == 'image/jpeg' |
||
2122 | new_image = Image.open(io.BytesIO(res.body)) |
||
2123 | assert 256, 256 == new_image.size |
||
2124 | |||
2125 | View Code Duplication | def test_api__get_sized_jpeg_preview__err__400__SizeNotAllowed(self) -> None: # nopep8 |
|
2126 | """ |
||
2127 | get 256x256 preview of a txt file |
||
2128 | """ |
||
2129 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
2130 | admin = dbsession.query(models.User) \ |
||
2131 | .filter(models.User.email == '[email protected]') \ |
||
2132 | .one() |
||
2133 | workspace_api = WorkspaceApi( |
||
2134 | current_user=admin, |
||
2135 | session=dbsession, |
||
2136 | config=self.app_config |
||
2137 | ) |
||
2138 | content_api = ContentApi( |
||
2139 | current_user=admin, |
||
2140 | session=dbsession, |
||
2141 | config=self.app_config |
||
2142 | ) |
||
2143 | business_workspace = workspace_api.get_one(1) |
||
2144 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
2145 | test_file = content_api.create( |
||
2146 | content_type_slug=CONTENT_TYPES.File.slug, |
||
2147 | workspace=business_workspace, |
||
2148 | parent=tool_folder, |
||
2149 | label='Test file', |
||
2150 | do_save=True, |
||
2151 | do_notify=False, |
||
2152 | ) |
||
2153 | dbsession.flush() |
||
2154 | transaction.commit() |
||
2155 | content_id = int(test_file.content_id) |
||
2156 | image = create_1000px_png_test_image() |
||
2157 | self.testapp.authorization = ( |
||
2158 | 'Basic', |
||
2159 | ( |
||
2160 | '[email protected]', |
||
2161 | '[email protected]' |
||
2162 | ) |
||
2163 | ) |
||
2164 | self.testapp.put( |
||
2165 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
2166 | upload_files=[ |
||
2167 | ('files', image.name, image.getvalue()) |
||
2168 | ], |
||
2169 | status=204, |
||
2170 | ) |
||
2171 | self.testapp.get( |
||
2172 | '/api/v2/workspaces/1/files/{}/preview/jpg/512x512'.format(content_id), # nopep8 |
||
2173 | status=400 |
||
2174 | ) |
||
2175 | |||
2176 | def test_api__get_sized_jpeg_revision_preview__ok__200__nominal_case(self) -> None: # nopep8 |
||
2177 | """ |
||
2178 | get 256x256 revision preview of a txt file |
||
2179 | """ |
||
2180 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
2181 | admin = dbsession.query(models.User) \ |
||
2182 | .filter(models.User.email == '[email protected]') \ |
||
2183 | .one() |
||
2184 | workspace_api = WorkspaceApi( |
||
2185 | current_user=admin, |
||
2186 | session=dbsession, |
||
2187 | config=self.app_config |
||
2188 | ) |
||
2189 | content_api = ContentApi( |
||
2190 | current_user=admin, |
||
2191 | session=dbsession, |
||
2192 | config=self.app_config |
||
2193 | ) |
||
2194 | business_workspace = workspace_api.get_one(1) |
||
2195 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
2196 | test_file = content_api.create( |
||
2197 | content_type_slug=CONTENT_TYPES.File.slug, |
||
2198 | workspace=business_workspace, |
||
2199 | parent=tool_folder, |
||
2200 | label='Test file', |
||
2201 | do_save=False, |
||
2202 | do_notify=False, |
||
2203 | ) |
||
2204 | test_file.file_extension = '.txt' |
||
2205 | test_file.depot_file = FileIntent( |
||
2206 | b'Test file', |
||
2207 | 'Test_file.txt', |
||
2208 | 'text/plain', |
||
2209 | ) |
||
2210 | dbsession.flush() |
||
2211 | transaction.commit() |
||
2212 | content_id = int(test_file.content_id) |
||
2213 | revision_id = int(test_file.revision_id) |
||
2214 | image = create_1000px_png_test_image() |
||
2215 | self.testapp.authorization = ( |
||
2216 | 'Basic', |
||
2217 | ( |
||
2218 | '[email protected]', |
||
2219 | '[email protected]' |
||
2220 | ) |
||
2221 | ) |
||
2222 | self.testapp.put( |
||
2223 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
2224 | upload_files=[ |
||
2225 | ('files', image.name, image.getvalue()) |
||
2226 | ], |
||
2227 | status=204, |
||
2228 | ) |
||
2229 | res = self.testapp.get( |
||
2230 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/raw'.format( # nopep8 |
||
2231 | content_id=content_id, |
||
2232 | revision_id=revision_id, |
||
2233 | ), |
||
2234 | status=200 |
||
2235 | ) |
||
2236 | assert res.content_type == 'text/plain' |
||
2237 | res = self.testapp.get( |
||
2238 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/preview/jpg/256x256'.format( # nopep8 |
||
2239 | content_id=content_id, |
||
2240 | revision_id=revision_id, |
||
2241 | ), |
||
2242 | status=200 |
||
2243 | ) |
||
2244 | assert res.body != image.getvalue() |
||
2245 | assert res.content_type == 'image/jpeg' |
||
2246 | new_image = Image.open(io.BytesIO(res.body)) |
||
2247 | assert 256, 256 == new_image.size |
||
2248 | |||
2249 | View Code Duplication | def test_api__get_full_pdf_preview__ok__200__nominal_case(self) -> None: |
|
2250 | """ |
||
2251 | get full pdf preview of a txt file |
||
2252 | """ |
||
2253 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
2254 | admin = dbsession.query(models.User) \ |
||
2255 | .filter(models.User.email == '[email protected]') \ |
||
2256 | .one() |
||
2257 | workspace_api = WorkspaceApi( |
||
2258 | current_user=admin, |
||
2259 | session=dbsession, |
||
2260 | config=self.app_config |
||
2261 | ) |
||
2262 | content_api = ContentApi( |
||
2263 | current_user=admin, |
||
2264 | session=dbsession, |
||
2265 | config=self.app_config |
||
2266 | ) |
||
2267 | business_workspace = workspace_api.get_one(1) |
||
2268 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
2269 | test_file = content_api.create( |
||
2270 | content_type_slug=CONTENT_TYPES.File.slug, |
||
2271 | workspace=business_workspace, |
||
2272 | parent=tool_folder, |
||
2273 | label='Test file', |
||
2274 | do_save=True, |
||
2275 | do_notify=False, |
||
2276 | ) |
||
2277 | with new_revision( |
||
2278 | session=dbsession, |
||
2279 | tm=transaction.manager, |
||
2280 | content=test_file, |
||
2281 | ): |
||
2282 | test_file.file_extension = '.txt' |
||
2283 | test_file.depot_file = FileIntent( |
||
2284 | b'Test file', |
||
2285 | 'Test_file.txt', |
||
2286 | 'text/plain', |
||
2287 | ) |
||
2288 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
||
2289 | dbsession.flush() |
||
2290 | transaction.commit() |
||
2291 | content_id = int(test_file.content_id) |
||
2292 | self.testapp.authorization = ( |
||
2293 | 'Basic', |
||
2294 | ( |
||
2295 | '[email protected]', |
||
2296 | '[email protected]' |
||
2297 | ) |
||
2298 | ) |
||
2299 | self.testapp.put( |
||
2300 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
2301 | upload_files=[ |
||
2302 | ('files', test_file.file_name, test_file.depot_file.file.read()) |
||
2303 | ], |
||
2304 | status=204, |
||
2305 | ) |
||
2306 | res = self.testapp.get( |
||
2307 | '/api/v2/workspaces/1/files/{}/preview/pdf/full'.format(content_id), # nopep8 |
||
2308 | status=200 |
||
2309 | ) |
||
2310 | assert res.content_type == 'application/pdf' |
||
2311 | |||
2312 | View Code Duplication | def test_api__get_full_pdf_preview__err__400__png_UnavailablePreviewType(self) -> None: # nopep8 |
|
2313 | """ |
||
2314 | get full pdf preview of a png image -> error UnavailablePreviewType |
||
2315 | """ |
||
2316 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
2317 | admin = dbsession.query(models.User) \ |
||
2318 | .filter(models.User.email == '[email protected]') \ |
||
2319 | .one() |
||
2320 | workspace_api = WorkspaceApi( |
||
2321 | current_user=admin, |
||
2322 | session=dbsession, |
||
2323 | config=self.app_config |
||
2324 | ) |
||
2325 | content_api = ContentApi( |
||
2326 | current_user=admin, |
||
2327 | session=dbsession, |
||
2328 | config=self.app_config |
||
2329 | ) |
||
2330 | business_workspace = workspace_api.get_one(1) |
||
2331 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
2332 | test_file = content_api.create( |
||
2333 | content_type_slug=CONTENT_TYPES.File.slug, |
||
2334 | workspace=business_workspace, |
||
2335 | parent=tool_folder, |
||
2336 | label='Test file', |
||
2337 | do_save=True, |
||
2338 | do_notify=False, |
||
2339 | ) |
||
2340 | dbsession.flush() |
||
2341 | transaction.commit() |
||
2342 | content_id = int(test_file.content_id) |
||
2343 | image = create_1000px_png_test_image() |
||
2344 | self.testapp.authorization = ( |
||
2345 | 'Basic', |
||
2346 | ( |
||
2347 | '[email protected]', |
||
2348 | '[email protected]' |
||
2349 | ) |
||
2350 | ) |
||
2351 | self.testapp.put( |
||
2352 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
2353 | upload_files=[ |
||
2354 | ('files', image.name, image.getvalue()) |
||
2355 | ], |
||
2356 | status=204, |
||
2357 | ) |
||
2358 | self.testapp.get( |
||
2359 | '/api/v2/workspaces/1/files/{}/preview/pdf/full'.format(content_id), # nopep8 |
||
2360 | status=400 |
||
2361 | ) |
||
2362 | |||
2363 | def test_api__get_pdf_preview__ok__200__nominal_case(self) -> None: |
||
2364 | """ |
||
2365 | get full pdf preview of a txt file |
||
2366 | """ |
||
2367 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
2368 | admin = dbsession.query(models.User) \ |
||
2369 | .filter(models.User.email == '[email protected]') \ |
||
2370 | .one() |
||
2371 | workspace_api = WorkspaceApi( |
||
2372 | current_user=admin, |
||
2373 | session=dbsession, |
||
2374 | config=self.app_config |
||
2375 | ) |
||
2376 | content_api = ContentApi( |
||
2377 | current_user=admin, |
||
2378 | session=dbsession, |
||
2379 | config=self.app_config |
||
2380 | ) |
||
2381 | business_workspace = workspace_api.get_one(1) |
||
2382 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
2383 | test_file = content_api.create( |
||
2384 | content_type_slug=CONTENT_TYPES.File.slug, |
||
2385 | workspace=business_workspace, |
||
2386 | parent=tool_folder, |
||
2387 | label='Test file', |
||
2388 | do_save=True, |
||
2389 | do_notify=False, |
||
2390 | ) |
||
2391 | with new_revision( |
||
2392 | session=dbsession, |
||
2393 | tm=transaction.manager, |
||
2394 | content=test_file, |
||
2395 | ): |
||
2396 | test_file.file_extension = '.txt' |
||
2397 | test_file.depot_file = FileIntent( |
||
2398 | b'Test file', |
||
2399 | 'Test_file.txt', |
||
2400 | 'text/plain', |
||
2401 | ) |
||
2402 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
||
2403 | dbsession.flush() |
||
2404 | transaction.commit() |
||
2405 | content_id = int(test_file.content_id) |
||
2406 | self.testapp.authorization = ( |
||
2407 | 'Basic', |
||
2408 | ( |
||
2409 | '[email protected]', |
||
2410 | '[email protected]' |
||
2411 | ) |
||
2412 | ) |
||
2413 | self.testapp.put( |
||
2414 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
2415 | upload_files=[ |
||
2416 | ('files', test_file.file_name, test_file.depot_file.file.read()) |
||
2417 | ], |
||
2418 | status=204, |
||
2419 | ) |
||
2420 | params = {'page': 0} |
||
2421 | res = self.testapp.get( |
||
2422 | '/api/v2/workspaces/1/files/{}/preview/pdf'.format(content_id), |
||
2423 | status=200, |
||
2424 | params=params, |
||
2425 | ) |
||
2426 | assert res.content_type == 'application/pdf' |
||
2427 | |||
2428 | View Code Duplication | def test_api__get_pdf_preview__ok__err__400_page_of_preview_not_found(self) -> None: # nopep8 |
|
2429 | """ |
||
2430 | get full pdf preview of a txt file |
||
2431 | """ |
||
2432 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
2433 | admin = dbsession.query(models.User) \ |
||
2434 | .filter(models.User.email == '[email protected]') \ |
||
2435 | .one() |
||
2436 | workspace_api = WorkspaceApi( |
||
2437 | current_user=admin, |
||
2438 | session=dbsession, |
||
2439 | config=self.app_config |
||
2440 | ) |
||
2441 | content_api = ContentApi( |
||
2442 | current_user=admin, |
||
2443 | session=dbsession, |
||
2444 | config=self.app_config |
||
2445 | ) |
||
2446 | business_workspace = workspace_api.get_one(1) |
||
2447 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
2448 | test_file = content_api.create( |
||
2449 | content_type_slug=CONTENT_TYPES.File.slug, |
||
2450 | workspace=business_workspace, |
||
2451 | parent=tool_folder, |
||
2452 | label='Test file', |
||
2453 | do_save=True, |
||
2454 | do_notify=False, |
||
2455 | ) |
||
2456 | with new_revision( |
||
2457 | session=dbsession, |
||
2458 | tm=transaction.manager, |
||
2459 | content=test_file, |
||
2460 | ): |
||
2461 | test_file.file_extension = '.txt' |
||
2462 | test_file.depot_file = FileIntent( |
||
2463 | b'Test file', |
||
2464 | 'Test_file.txt', |
||
2465 | 'text/plain', |
||
2466 | ) |
||
2467 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
||
2468 | dbsession.flush() |
||
2469 | transaction.commit() |
||
2470 | content_id = int(test_file.content_id) |
||
2471 | self.testapp.authorization = ( |
||
2472 | 'Basic', |
||
2473 | ( |
||
2474 | '[email protected]', |
||
2475 | '[email protected]' |
||
2476 | ) |
||
2477 | ) |
||
2478 | self.testapp.put( |
||
2479 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
2480 | upload_files=[ |
||
2481 | ('files', test_file.file_name, test_file.depot_file.file.read()) |
||
2482 | ], |
||
2483 | status=204, |
||
2484 | ) |
||
2485 | params = {'page': 1} |
||
2486 | self.testapp.get( |
||
2487 | '/api/v2/workspaces/1/files/{}/preview/pdf'.format(content_id), |
||
2488 | status=400, |
||
2489 | params=params, |
||
2490 | ) |
||
2491 | |||
2492 | def test_api__get_pdf_revision_preview__ok__200__nominal_case(self) -> None: |
||
2493 | """ |
||
2494 | get pdf revision preview of content |
||
2495 | """ |
||
2496 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
2497 | admin = dbsession.query(models.User) \ |
||
2498 | .filter(models.User.email == '[email protected]') \ |
||
2499 | .one() |
||
2500 | workspace_api = WorkspaceApi( |
||
2501 | current_user=admin, |
||
2502 | session=dbsession, |
||
2503 | config=self.app_config |
||
2504 | ) |
||
2505 | content_api = ContentApi( |
||
2506 | current_user=admin, |
||
2507 | session=dbsession, |
||
2508 | config=self.app_config |
||
2509 | ) |
||
2510 | business_workspace = workspace_api.get_one(1) |
||
2511 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
2512 | test_file = content_api.create( |
||
2513 | content_type_slug=CONTENT_TYPES.File.slug, |
||
2514 | workspace=business_workspace, |
||
2515 | parent=tool_folder, |
||
2516 | label='Test file', |
||
2517 | do_save=False, |
||
2518 | do_notify=False, |
||
2519 | ) |
||
2520 | test_file.file_extension = '.txt' |
||
2521 | test_file.depot_file = FileIntent( |
||
2522 | b'Test file', |
||
2523 | 'Test_file.txt', |
||
2524 | 'text/plain', |
||
2525 | ) |
||
2526 | dbsession.flush() |
||
2527 | transaction.commit() |
||
2528 | content_id = int(test_file.content_id) |
||
2529 | revision_id = int(test_file.revision_id) |
||
2530 | image = create_1000px_png_test_image() |
||
2531 | self.testapp.authorization = ( |
||
2532 | 'Basic', |
||
2533 | ( |
||
2534 | '[email protected]', |
||
2535 | '[email protected]' |
||
2536 | ) |
||
2537 | ) |
||
2538 | self.testapp.put( |
||
2539 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
||
2540 | upload_files=[ |
||
2541 | ('files', image.name, image.getvalue()) |
||
2542 | ], |
||
2543 | status=204, |
||
2544 | ) |
||
2545 | res = self.testapp.get( |
||
2546 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/raw'.format( # nopep8 |
||
2547 | content_id=content_id, |
||
2548 | revision_id=revision_id, |
||
2549 | ), |
||
2550 | status=200 |
||
2551 | ) |
||
2552 | assert res.content_type == 'text/plain' |
||
2553 | params = {'page': 0} |
||
2554 | res = self.testapp.get( |
||
2555 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/preview/pdf'.format( # nopep8 |
||
2556 | content_id=content_id, |
||
2557 | revision_id=revision_id, |
||
2558 | params=params, |
||
2559 | ), |
||
2560 | status=200 |
||
2561 | ) |
||
2562 | assert res.content_type == 'application/pdf' |
||
2563 | |||
2564 | |||
2565 | class TestThreads(FunctionalTest): |
||
2566 | """ |
||
2567 | Tests for /api/v2/workspaces/{workspace_id}/threads/{content_id} |
||
2568 | endpoint |
||
2569 | """ |
||
2570 | |||
2571 | fixtures = [BaseFixture, ContentFixtures] |
||
2572 | |||
2573 | def test_api__get_thread__err_400__wrong_content_type(self) -> None: |
||
2574 | """ |
||
2575 | Get one html document of a content |
||
2576 | """ |
||
2577 | self.testapp.authorization = ( |
||
2578 | 'Basic', |
||
2579 | ( |
||
2580 | '[email protected]', |
||
2581 | '[email protected]' |
||
2582 | ) |
||
2583 | ) |
||
2584 | self.testapp.get( |
||
2585 | '/api/v2/workspaces/2/threads/6', |
||
2586 | status=400 |
||
2587 | ) |
||
2588 | |||
2589 | View Code Duplication | def test_api__get_thread__ok_200__nominal_case(self) -> None: |
|
2590 | """ |
||
2591 | Get one html document of a content |
||
2592 | """ |
||
2593 | self.testapp.authorization = ( |
||
2594 | 'Basic', |
||
2595 | ( |
||
2596 | '[email protected]', |
||
2597 | '[email protected]' |
||
2598 | ) |
||
2599 | ) |
||
2600 | res = self.testapp.get( |
||
2601 | '/api/v2/workspaces/2/threads/7', |
||
2602 | status=200 |
||
2603 | ) # nopep8 |
||
2604 | content = res.json_body |
||
2605 | assert content['content_type'] == 'thread' |
||
2606 | assert content['content_id'] == 7 |
||
2607 | assert content['is_archived'] is False |
||
2608 | assert content['is_deleted'] is False |
||
2609 | assert content['label'] == 'Best Cakes?' |
||
2610 | assert content['parent_id'] == 3 |
||
2611 | assert content['show_in_ui'] is True |
||
2612 | assert content['slug'] == 'best-cakes' |
||
2613 | assert content['status'] == 'open' |
||
2614 | assert content['workspace_id'] == 2 |
||
2615 | assert content['current_revision_id'] == 26 |
||
2616 | # TODO - G.M - 2018-06-173 - check date format |
||
2617 | assert content['created'] |
||
2618 | assert content['author'] |
||
2619 | assert content['author']['user_id'] == 1 |
||
2620 | assert content['author']['avatar_url'] is None |
||
2621 | assert content['author']['public_name'] == 'Global manager' |
||
2622 | # TODO - G.M - 2018-06-173 - check date format |
||
2623 | assert content['modified'] |
||
2624 | assert content['last_modifier'] != content['author'] |
||
2625 | assert content['last_modifier']['user_id'] == 3 |
||
2626 | assert content['last_modifier']['public_name'] == 'Bob i.' |
||
2627 | assert content['last_modifier']['avatar_url'] is None |
||
2628 | assert content['raw_content'] == 'What is the best cake?' # nopep8 |
||
2629 | |||
2630 | |||
2631 | def test_api__get_thread__err_400__content_does_not_exist(self) -> None: |
||
2632 | """ |
||
2633 | Get one thread (content 170 does not exist) |
||
2634 | """ |
||
2635 | self.testapp.authorization = ( |
||
2636 | 'Basic', |
||
2637 | ( |
||
2638 | '[email protected]', |
||
2639 | '[email protected]' |
||
2640 | ) |
||
2641 | ) |
||
2642 | self.testapp.get( |
||
2643 | '/api/v2/workspaces/2/threads/170', |
||
2644 | status=400 |
||
2645 | ) |
||
2646 | |||
2647 | def test_api__get_thread__err_400__content_not_in_workspace(self) -> None: |
||
2648 | """ |
||
2649 | Get one thread(content 7 is in workspace 2) |
||
2650 | """ |
||
2651 | self.testapp.authorization = ( |
||
2652 | 'Basic', |
||
2653 | ( |
||
2654 | '[email protected]', |
||
2655 | '[email protected]' |
||
2656 | ) |
||
2657 | ) |
||
2658 | self.testapp.get( |
||
2659 | '/api/v2/workspaces/1/threads/7', |
||
2660 | status=400 |
||
2661 | ) |
||
2662 | |||
2663 | def test_api__get_thread__err_400__workspace_does_not_exist(self) -> None: # nopep8 |
||
2664 | """ |
||
2665 | Get one thread (Workspace 40 does not exist) |
||
2666 | """ |
||
2667 | self.testapp.authorization = ( |
||
2668 | 'Basic', |
||
2669 | ( |
||
2670 | '[email protected]', |
||
2671 | '[email protected]' |
||
2672 | ) |
||
2673 | ) |
||
2674 | self.testapp.get( |
||
2675 | '/api/v2/workspaces/40/threads/7', |
||
2676 | status=400 |
||
2677 | ) |
||
2678 | |||
2679 | def test_api__get_thread__err_400__workspace_id_is_not_int(self) -> None: # nopep8 |
||
2680 | """ |
||
2681 | Get one thread, workspace id is not int |
||
2682 | """ |
||
2683 | self.testapp.authorization = ( |
||
2684 | 'Basic', |
||
2685 | ( |
||
2686 | '[email protected]', |
||
2687 | '[email protected]' |
||
2688 | ) |
||
2689 | ) |
||
2690 | self.testapp.get( |
||
2691 | '/api/v2/workspaces/coucou/threads/7', |
||
2692 | status=400 |
||
2693 | ) |
||
2694 | |||
2695 | def test_api__get_thread__err_400_content_id_is_not_int(self) -> None: # nopep8 |
||
2696 | """ |
||
2697 | Get one thread, content id is not int |
||
2698 | """ |
||
2699 | self.testapp.authorization = ( |
||
2700 | 'Basic', |
||
2701 | ( |
||
2702 | '[email protected]', |
||
2703 | '[email protected]' |
||
2704 | ) |
||
2705 | ) |
||
2706 | self.testapp.get( |
||
2707 | '/api/v2/workspaces/2/threads/coucou', |
||
2708 | status=400 |
||
2709 | ) |
||
2710 | |||
2711 | View Code Duplication | def test_api__update_thread__ok_200__nominal_case(self) -> None: |
|
2712 | """ |
||
2713 | Update(put) thread |
||
2714 | """ |
||
2715 | self.testapp.authorization = ( |
||
2716 | 'Basic', |
||
2717 | ( |
||
2718 | '[email protected]', |
||
2719 | '[email protected]' |
||
2720 | ) |
||
2721 | ) |
||
2722 | params = { |
||
2723 | 'label': 'My New label', |
||
2724 | 'raw_content': '<p> Le nouveau contenu </p>', |
||
2725 | } |
||
2726 | res = self.testapp.put_json( |
||
2727 | '/api/v2/workspaces/2/threads/7', |
||
2728 | params=params, |
||
2729 | status=200 |
||
2730 | ) |
||
2731 | content = res.json_body |
||
2732 | assert content['content_type'] == 'thread' |
||
2733 | assert content['content_id'] == 7 |
||
2734 | assert content['is_archived'] is False |
||
2735 | assert content['is_deleted'] is False |
||
2736 | assert content['label'] == 'My New label' |
||
2737 | assert content['parent_id'] == 3 |
||
2738 | assert content['show_in_ui'] is True |
||
2739 | assert content['slug'] == 'my-new-label' |
||
2740 | assert content['status'] == 'open' |
||
2741 | assert content['workspace_id'] == 2 |
||
2742 | assert content['current_revision_id'] == 28 |
||
2743 | # TODO - G.M - 2018-06-173 - check date format |
||
2744 | assert content['created'] |
||
2745 | assert content['author'] |
||
2746 | assert content['author']['user_id'] == 1 |
||
2747 | assert content['author']['avatar_url'] is None |
||
2748 | assert content['author']['public_name'] == 'Global manager' |
||
2749 | # TODO - G.M - 2018-06-173 - check date format |
||
2750 | assert content['modified'] |
||
2751 | assert content['last_modifier'] == content['author'] |
||
2752 | assert content['raw_content'] == '<p> Le nouveau contenu </p>' |
||
2753 | |||
2754 | res = self.testapp.get( |
||
2755 | '/api/v2/workspaces/2/threads/7', |
||
2756 | status=200 |
||
2757 | ) # nopep8 |
||
2758 | content = res.json_body |
||
2759 | assert content['content_type'] == 'thread' |
||
2760 | assert content['content_id'] == 7 |
||
2761 | assert content['is_archived'] is False |
||
2762 | assert content['is_deleted'] is False |
||
2763 | assert content['label'] == 'My New label' |
||
2764 | assert content['parent_id'] == 3 |
||
2765 | assert content['show_in_ui'] is True |
||
2766 | assert content['slug'] == 'my-new-label' |
||
2767 | assert content['status'] == 'open' |
||
2768 | assert content['workspace_id'] == 2 |
||
2769 | assert content['current_revision_id'] == 28 |
||
2770 | # TODO - G.M - 2018-06-173 - check date format |
||
2771 | assert content['created'] |
||
2772 | assert content['author'] |
||
2773 | assert content['author']['user_id'] == 1 |
||
2774 | assert content['author']['avatar_url'] is None |
||
2775 | assert content['author']['public_name'] == 'Global manager' |
||
2776 | # TODO - G.M - 2018-06-173 - check date format |
||
2777 | assert content['modified'] |
||
2778 | assert content['last_modifier'] == content['author'] |
||
2779 | assert content['raw_content'] == '<p> Le nouveau contenu </p>' |
||
2780 | |||
2781 | def test_api__update_thread__err_400__empty_label(self) -> None: |
||
2782 | """ |
||
2783 | Update(put) thread |
||
2784 | """ |
||
2785 | self.testapp.authorization = ( |
||
2786 | 'Basic', |
||
2787 | ( |
||
2788 | '[email protected]', |
||
2789 | '[email protected]' |
||
2790 | ) |
||
2791 | ) |
||
2792 | params = { |
||
2793 | 'label': '', |
||
2794 | 'raw_content': '<p> Le nouveau contenu </p>', |
||
2795 | } |
||
2796 | self.testapp.put_json( |
||
2797 | '/api/v2/workspaces/2/threads/7', |
||
2798 | params=params, |
||
2799 | status=400 |
||
2800 | ) |
||
2801 | |||
2802 | def test_api__get_thread_revisions__ok_200__nominal_case( |
||
2803 | self |
||
2804 | ) -> None: |
||
2805 | """ |
||
2806 | Get threads revisions |
||
2807 | """ |
||
2808 | self.testapp.authorization = ( |
||
2809 | 'Basic', |
||
2810 | ( |
||
2811 | '[email protected]', |
||
2812 | '[email protected]' |
||
2813 | ) |
||
2814 | ) |
||
2815 | res = self.testapp.get( |
||
2816 | '/api/v2/workspaces/2/threads/7/revisions', |
||
2817 | status=200 |
||
2818 | ) |
||
2819 | revisions = res.json_body |
||
2820 | assert len(revisions) == 2 |
||
2821 | revision = revisions[0] |
||
2822 | assert revision['content_type'] == 'thread' |
||
2823 | assert revision['content_id'] == 7 |
||
2824 | assert revision['is_archived'] is False |
||
2825 | assert revision['is_deleted'] is False |
||
2826 | assert revision['label'] == 'Best Cake' |
||
2827 | assert revision['parent_id'] == 3 |
||
2828 | assert revision['show_in_ui'] is True |
||
2829 | assert revision['slug'] == 'best-cake' |
||
2830 | assert revision['status'] == 'open' |
||
2831 | assert revision['workspace_id'] == 2 |
||
2832 | assert revision['revision_id'] == 8 |
||
2833 | assert revision['sub_content_types'] |
||
2834 | assert revision['revision_type'] == 'creation' |
||
2835 | assert revision['comment_ids'] == [18, 19, 20] |
||
2836 | # TODO - G.M - 2018-06-173 - check date format |
||
2837 | assert revision['created'] |
||
2838 | assert revision['author'] |
||
2839 | assert revision['author']['user_id'] == 1 |
||
2840 | assert revision['author']['avatar_url'] is None |
||
2841 | assert revision['author']['public_name'] == 'Global manager' |
||
2842 | revision = revisions[1] |
||
2843 | assert revision['content_type'] == 'thread' |
||
2844 | assert revision['content_id'] == 7 |
||
2845 | assert revision['is_archived'] is False |
||
2846 | assert revision['is_deleted'] is False |
||
2847 | assert revision['label'] == 'Best Cakes?' |
||
2848 | assert revision['parent_id'] == 3 |
||
2849 | assert revision['show_in_ui'] is True |
||
2850 | assert revision['slug'] == 'best-cakes' |
||
2851 | assert revision['status'] == 'open' |
||
2852 | assert revision['workspace_id'] == 2 |
||
2853 | assert revision['revision_id'] == 26 |
||
2854 | assert revision['revision_type'] == 'edition' |
||
2855 | assert revision['sub_content_types'] |
||
2856 | assert revision['comment_ids'] == [] |
||
2857 | # TODO - G.M - 2018-06-173 - check date format |
||
2858 | assert revision['created'] |
||
2859 | assert revision['author'] |
||
2860 | assert revision['author']['user_id'] == 3 |
||
2861 | assert revision['author']['avatar_url'] is None |
||
2862 | assert revision['author']['public_name'] == 'Bob i.' |
||
2863 | |||
2864 | def test_api__get_thread_revisions__ok_200__most_revision_type(self) -> None: |
||
2865 | """ |
||
2866 | get threads revisions |
||
2867 | """ |
||
2868 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
||
2869 | admin = dbsession.query(models.User) \ |
||
2870 | .filter(models.User.email == '[email protected]') \ |
||
2871 | .one() |
||
2872 | workspace_api = WorkspaceApi( |
||
2873 | current_user=admin, |
||
2874 | session=dbsession, |
||
2875 | config=self.app_config |
||
2876 | ) |
||
2877 | business_workspace = workspace_api.get_one(1) |
||
2878 | content_api = ContentApi( |
||
2879 | current_user=admin, |
||
2880 | session=dbsession, |
||
2881 | config=self.app_config |
||
2882 | ) |
||
2883 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
||
2884 | test_thread = content_api.create( |
||
2885 | content_type_slug=CONTENT_TYPES.Thread.slug, |
||
2886 | workspace=business_workspace, |
||
2887 | parent=tool_folder, |
||
2888 | label='Test Thread', |
||
2889 | do_save=True, |
||
2890 | do_notify=False, |
||
2891 | ) |
||
2892 | with new_revision( |
||
2893 | session=dbsession, |
||
2894 | tm=transaction.manager, |
||
2895 | content=test_thread, |
||
2896 | ): |
||
2897 | content_api.update_content( |
||
2898 | test_thread, |
||
2899 | new_label='test_thread_updated', |
||
2900 | new_content='Just a test' |
||
2901 | ) |
||
2902 | content_api.save(test_thread) |
||
2903 | with new_revision( |
||
2904 | session=dbsession, |
||
2905 | tm=transaction.manager, |
||
2906 | content=test_thread, |
||
2907 | ): |
||
2908 | content_api.archive(test_thread) |
||
2909 | content_api.save(test_thread) |
||
2910 | |||
2911 | with new_revision( |
||
2912 | session=dbsession, |
||
2913 | tm=transaction.manager, |
||
2914 | content=test_thread, |
||
2915 | ): |
||
2916 | content_api.unarchive(test_thread) |
||
2917 | content_api.save(test_thread) |
||
2918 | |||
2919 | with new_revision( |
||
2920 | session=dbsession, |
||
2921 | tm=transaction.manager, |
||
2922 | content=test_thread, |
||
2923 | ): |
||
2924 | content_api.delete(test_thread) |
||
2925 | content_api.save(test_thread) |
||
2926 | |||
2927 | with new_revision( |
||
2928 | session=dbsession, |
||
2929 | tm=transaction.manager, |
||
2930 | content=test_thread, |
||
2931 | ): |
||
2932 | content_api.undelete(test_thread) |
||
2933 | content_api.save(test_thread) |
||
2934 | dbsession.flush() |
||
2935 | transaction.commit() |
||
2936 | self.testapp.authorization = ( |
||
2937 | 'Basic', |
||
2938 | ( |
||
2939 | '[email protected]', |
||
2940 | '[email protected]' |
||
2941 | ) |
||
2942 | ) |
||
2943 | res = self.testapp.get( |
||
2944 | '/api/v2/workspaces/1/threads/{}/revisions'.format(test_thread.content_id), # nopep8 |
||
2945 | status=200 |
||
2946 | ) |
||
2947 | revisions = res.json_body |
||
2948 | assert len(revisions) == 6 |
||
2949 | for revision in revisions: |
||
2950 | revision['content_type'] == 'thread' |
||
2951 | revision['workspace_id'] == 1 |
||
2952 | revision['content_id'] == test_thread.content_id |
||
2953 | revision = revisions[0] |
||
2954 | revision['revision_type'] == 'creation' |
||
2955 | revision = revisions[1] |
||
2956 | revision['revision_type'] == 'archiving' |
||
2957 | revision = revisions[2] |
||
2958 | revision['revision_type'] == 'unarchiving' |
||
2959 | revision = revisions[3] |
||
2960 | revision['revision_type'] == 'deletion' |
||
2961 | revision = revisions[4] |
||
2962 | revision['revision_type'] == 'undeletion' |
||
2963 | |||
2964 | View Code Duplication | def test_api__set_thread_status__ok_200__nominal_case(self) -> None: |
|
2965 | """ |
||
2966 | Set thread status |
||
2967 | """ |
||
2968 | self.testapp.authorization = ( |
||
2969 | 'Basic', |
||
2970 | ( |
||
2971 | '[email protected]', |
||
2972 | '[email protected]' |
||
2973 | ) |
||
2974 | ) |
||
2975 | params = { |
||
2976 | 'status': 'closed-deprecated', |
||
2977 | } |
||
2978 | |||
2979 | # before |
||
2980 | res = self.testapp.get( |
||
2981 | '/api/v2/workspaces/2/threads/7', |
||
2982 | status=200 |
||
2983 | ) # nopep8 |
||
2984 | content = res.json_body |
||
2985 | assert content['content_type'] == 'thread' |
||
2986 | assert content['content_id'] == 7 |
||
2987 | assert content['status'] == 'open' |
||
2988 | |||
2989 | # set status |
||
2990 | self.testapp.put_json( |
||
2991 | '/api/v2/workspaces/2/threads/7/status', |
||
2992 | params=params, |
||
2993 | status=204 |
||
2994 | ) |
||
2995 | |||
2996 | # after |
||
2997 | res = self.testapp.get( |
||
2998 | '/api/v2/workspaces/2/threads/7', |
||
2999 | status=200 |
||
3000 | ) # nopep8 |
||
3001 | content = res.json_body |
||
3002 | assert content['content_type'] == 'thread' |
||
3003 | assert content['content_id'] == 7 |
||
3004 | assert content['status'] == 'closed-deprecated' |
||
3005 | |||
3006 | def test_api__set_thread_status__ok_400__wrong_status(self) -> None: |
||
3007 | """ |
||
3008 | Set thread status |
||
3009 | """ |
||
3010 | self.testapp.authorization = ( |
||
3011 | 'Basic', |
||
3012 | ( |
||
3013 | '[email protected]', |
||
3014 | '[email protected]' |
||
3015 | ) |
||
3016 | ) |
||
3017 | params = { |
||
3018 | 'status': 'unexistant-status', |
||
3019 | } |
||
3020 | |||
3021 | self.testapp.put_json( |
||
3022 | '/api/v2/workspaces/2/threads/7/status', |
||
3023 | params=params, |
||
3024 | status=400 |
||
3025 | ) |
||
3026 |