Browse Source

Merge branch 'fix/592_fix_schema_and_http_code_in_endpoints' of github.com:tracim/tracim_backend into fix/596_move_endpoint_return_updated_content

Guénaël Muller 6 years ago
parent
commit
377c6ea386

+ 19 - 8
tracim/models/context_models.py View File

@@ -65,10 +65,10 @@ class ContentCreation(object):
65 65
     def __init__(
66 66
             self,
67 67
             label: str,
68
-            content_type_slug: str,
68
+            content_type: str,
69 69
     ):
70 70
         self.label = label
71
-        self.content_type_slug = content_type_slug
71
+        self.content_type = content_type
72 72
 
73 73
 
74 74
 class UserInContext(object):
@@ -92,6 +92,10 @@ class UserInContext(object):
92 92
         return self.user.user_id
93 93
 
94 94
     @property
95
+    def public_name(self) -> str:
96
+        return self.display_name
97
+
98
+    @property
95 99
     def display_name(self) -> str:
96 100
         return self.user.display_name
97 101
 
@@ -109,7 +113,7 @@ class UserInContext(object):
109 113
 
110 114
     @property
111 115
     def profile(self) -> Profile:
112
-        return self.user.profile
116
+        return self.user.profile.name
113 117
 
114 118
     # Context related
115 119
 
@@ -227,12 +231,16 @@ class UserRoleWorkspaceInContext(object):
227 231
         return self.user_role.role
228 232
 
229 233
     @property
234
+    def role(self) -> str:
235
+        return self.role_slug
236
+
237
+    @property
230 238
     def role_slug(self) -> str:
231 239
         """
232 240
         simple name of the role of the user.
233 241
         can be anything from UserRoleInWorkspace SLUG, like
234 242
         'not_applicable', 'reader',
235
-        'contributor', 'content_manager', 'workspace_manager'
243
+        'contributor', 'content-manager', 'workspace-manager'
236 244
         :return: user workspace role as slug.
237 245
         """
238 246
         return UserRoleInWorkspace.SLUG[self.user_role.role]
@@ -273,10 +281,13 @@ class ContentInContext(object):
273 281
         self.config = config
274 282
 
275 283
     # Default
284
+    @property
285
+    def content_id(self) -> int:
286
+        return self.content.content_id
276 287
 
277 288
     @property
278 289
     def id(self) -> int:
279
-        return self.content.content_id
290
+        return self.content_id
280 291
 
281 292
     @property
282 293
     def parent_id(self) -> int:
@@ -291,15 +302,15 @@ class ContentInContext(object):
291 302
         return self.content.label
292 303
 
293 304
     @property
294
-    def content_type_slug(self) -> str:
305
+    def content_type(self) -> str:
295 306
         return self.content.type
296 307
 
297 308
     @property
298
-    def sub_content_type_slug(self) -> typing.List[str]:
309
+    def sub_content_types(self) -> typing.List[str]:
299 310
         return [type.slug for type in self.content.get_allowed_content_types()]
300 311
 
301 312
     @property
302
-    def status_slug(self) -> str:
313
+    def status(self) -> str:
303 314
         return self.content.status
304 315
 
305 316
     @property

+ 10 - 5
tracim/tests/functional/test_session.py View File

@@ -1,4 +1,5 @@
1 1
 # coding=utf-8
2
+import datetime
2 3
 import pytest
3 4
 from sqlalchemy.exc import OperationalError
4 5
 
@@ -45,12 +46,16 @@ class TestLoginEndpoint(FunctionalTest):
45 46
             params=params,
46 47
             status=200,
47 48
         )
48
-        assert res.json_body['display_name'] == 'Global manager'
49
-        assert res.json_body['email'] == 'admin@admin.admin'
50 49
         assert res.json_body['created']
50
+        datetime.datetime.strptime(
51
+            res.json_body['created'],
52
+            '%Y-%m-%dT%H:%M:%SZ'
53
+        )
54
+        assert res.json_body['public_name'] == 'Global manager'
55
+        assert res.json_body['email'] == 'admin@admin.admin'
51 56
         assert res.json_body['is_active']
52 57
         assert res.json_body['profile']
53
-        assert res.json_body['profile']['slug'] == 'administrators'
58
+        assert res.json_body['profile'] == 'administrators'
54 59
         assert res.json_body['caldav_url'] is None
55 60
         assert res.json_body['avatar_url'] is None
56 61
 
@@ -103,12 +108,12 @@ class TestWhoamiEndpoint(FunctionalTest):
103 108
             )
104 109
         )
105 110
         res = self.testapp.get('/api/v2/sessions/whoami', status=200)
106
-        assert res.json_body['display_name'] == 'Global manager'
111
+        assert res.json_body['public_name'] == 'Global manager'
107 112
         assert res.json_body['email'] == 'admin@admin.admin'
108 113
         assert res.json_body['created']
109 114
         assert res.json_body['is_active']
110 115
         assert res.json_body['profile']
111
-        assert res.json_body['profile']['slug'] == 'administrators'
116
+        assert res.json_body['profile'] == 'administrators'
112 117
         assert res.json_body['caldav_url'] is None
113 118
         assert res.json_body['avatar_url'] is None
114 119
 

+ 2 - 1
tracim/tests/functional/test_user.py View File

@@ -28,8 +28,9 @@ class TestUserWorkspaceEndpoint(FunctionalTest):
28 28
         res = self.testapp.get('/api/v2/users/1/workspaces', status=200)
29 29
         res = res.json_body
30 30
         workspace = res[0]
31
-        assert workspace['id'] == 1
31
+        assert workspace['workspace_id'] == 1
32 32
         assert workspace['label'] == 'Business'
33
+        assert workspace['slug'] == 'business'
33 34
         assert len(workspace['sidebar_entries']) == 7
34 35
 
35 36
         sidebar_entry = workspace['sidebar_entries'][0]

+ 90 - 90
tracim/tests/functional/test_workspaces.py View File

@@ -27,7 +27,7 @@ class TestWorkspaceEndpoint(FunctionalTest):
27 27
         )
28 28
         res = self.testapp.get('/api/v2/workspaces/1', status=200)
29 29
         workspace = res.json_body
30
-        assert workspace['id'] == 1
30
+        assert workspace['workspace_id'] == 1
31 31
         assert workspace['slug'] == 'business'
32 32
         assert workspace['label'] == 'Business'
33 33
         assert workspace['description'] == 'All importants documents'
@@ -155,10 +155,10 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
155 155
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
156 156
         assert len(res) == 1
157 157
         user_role = res[0]
158
-        assert user_role['role_slug'] == 'workspace-manager'
158
+        assert user_role['role'] == 'workspace-manager'
159 159
         assert user_role['user_id'] == 1
160 160
         assert user_role['workspace_id'] == 1
161
-        assert user_role['user']['display_name'] == 'Global manager'
161
+        assert user_role['user']['public_name'] == 'Global manager'
162 162
         # TODO - G.M - 24-05-2018 - [Avatar] Replace
163 163
         # by correct value when avatar feature will be enabled
164 164
         assert user_role['user']['avatar_url'] is None
@@ -239,37 +239,37 @@ class TestWorkspaceContents(FunctionalTest):
239 239
         # TODO - G.M - 30-05-2018 - Check this test
240 240
         assert len(res) == 3
241 241
         content = res[0]
242
-        assert content['id'] == 1
242
+        assert content['content_id'] == 1
243 243
         assert content['is_archived'] is False
244 244
         assert content['is_deleted'] is False
245 245
         assert content['label'] == 'Tools'
246 246
         assert content['parent_id'] is None
247 247
         assert content['show_in_ui'] is True
248 248
         assert content['slug'] == 'tools'
249
-        assert content['status_slug'] == 'open'
250
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
249
+        assert content['status'] == 'open'
250
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
251 251
         assert content['workspace_id'] == 1
252 252
         content = res[1]
253
-        assert content['id'] == 2
253
+        assert content['content_id'] == 2
254 254
         assert content['is_archived'] is False
255 255
         assert content['is_deleted'] is False
256 256
         assert content['label'] == 'Menus'
257 257
         assert content['parent_id'] is None
258 258
         assert content['show_in_ui'] is True
259 259
         assert content['slug'] == 'menus'
260
-        assert content['status_slug'] == 'open'
261
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
260
+        assert content['status'] == 'open'
261
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
262 262
         assert content['workspace_id'] == 1
263 263
         content = res[2]
264
-        assert content['id'] == 11
264
+        assert content['content_id'] == 11
265 265
         assert content['is_archived'] is False
266 266
         assert content['is_deleted'] is False
267 267
         assert content['label'] == 'Current Menu'
268 268
         assert content['parent_id'] == 2
269 269
         assert content['show_in_ui'] is True
270 270
         assert content['slug'] == 'current-menu'
271
-        assert content['status_slug'] == 'open'
272
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
271
+        assert content['status'] == 'open'
272
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
273 273
         assert content['workspace_id'] == 1
274 274
 
275 275
     # Root related
@@ -299,42 +299,42 @@ class TestWorkspaceContents(FunctionalTest):
299 299
         # TODO - G.M - 30-05-2018 - Check this test
300 300
         assert len(res) == 4
301 301
         content = res[1]
302
-        assert content['content_type_slug'] == 'page'
303
-        assert content['id'] == 15
302
+        assert content['content_type'] == 'page'
303
+        assert content['content_id'] == 15
304 304
         assert content['is_archived'] is False
305 305
         assert content['is_deleted'] is False
306 306
         assert content['label'] == 'New Fruit Salad'
307 307
         assert content['parent_id'] is None
308 308
         assert content['show_in_ui'] is True
309 309
         assert content['slug'] == 'new-fruit-salad'
310
-        assert content['status_slug'] == 'open'
311
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
310
+        assert content['status'] == 'open'
311
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
312 312
         assert content['workspace_id'] == 3
313 313
 
314 314
         content = res[2]
315
-        assert content['content_type_slug'] == 'page'
316
-        assert content['id'] == 16
315
+        assert content['content_type'] == 'page'
316
+        assert content['content_id'] == 16
317 317
         assert content['is_archived'] is True
318 318
         assert content['is_deleted'] is False
319 319
         assert content['label'].startswith('Fruit Salad')
320 320
         assert content['parent_id'] is None
321 321
         assert content['show_in_ui'] is True
322 322
         assert content['slug'].startswith('fruit-salad')
323
-        assert content['status_slug'] == 'open'
324
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
323
+        assert content['status'] == 'open'
324
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
325 325
         assert content['workspace_id'] == 3
326 326
 
327 327
         content = res[3]
328
-        assert content['content_type_slug'] == 'page'
329
-        assert content['id'] == 17
328
+        assert content['content_type'] == 'page'
329
+        assert content['content_id'] == 17
330 330
         assert content['is_archived'] is False
331 331
         assert content['is_deleted'] is True
332 332
         assert content['label'].startswith('Bad Fruit Salad')
333 333
         assert content['parent_id'] is None
334 334
         assert content['show_in_ui'] is True
335 335
         assert content['slug'].startswith('bad-fruit-salad')
336
-        assert content['status_slug'] == 'open'
337
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
336
+        assert content['status'] == 'open'
337
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
338 338
         assert content['workspace_id'] == 3
339 339
 
340 340
     def test_api__get_workspace_content__ok_200__get_only_active_root_content(self):  # nopep8
@@ -362,16 +362,16 @@ class TestWorkspaceContents(FunctionalTest):
362 362
         # TODO - G.M - 30-05-2018 - Check this test
363 363
         assert len(res) == 2
364 364
         content = res[1]
365
-        assert content['content_type_slug'] == 'page'
366
-        assert content['id'] == 15
365
+        assert content['content_type'] == 'page'
366
+        assert content['content_id'] == 15
367 367
         assert content['is_archived'] is False
368 368
         assert content['is_deleted'] is False
369 369
         assert content['label'] == 'New Fruit Salad'
370 370
         assert content['parent_id'] is None
371 371
         assert content['show_in_ui'] is True
372 372
         assert content['slug'] == 'new-fruit-salad'
373
-        assert content['status_slug'] == 'open'
374
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
373
+        assert content['status'] == 'open'
374
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
375 375
         assert content['workspace_id'] == 3
376 376
 
377 377
     def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self):  # nopep8
@@ -398,16 +398,16 @@ class TestWorkspaceContents(FunctionalTest):
398 398
         ).json_body   # nopep8
399 399
         assert len(res) == 1
400 400
         content = res[0]
401
-        assert content['content_type_slug'] == 'page'
402
-        assert content['id'] == 16
401
+        assert content['content_type'] == 'page'
402
+        assert content['content_id'] == 16
403 403
         assert content['is_archived'] is True
404 404
         assert content['is_deleted'] is False
405 405
         assert content['label'].startswith('Fruit Salad')
406 406
         assert content['parent_id'] is None
407 407
         assert content['show_in_ui'] is True
408 408
         assert content['slug'].startswith('fruit-salad')
409
-        assert content['status_slug'] == 'open'
410
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
409
+        assert content['status'] == 'open'
410
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
411 411
         assert content['workspace_id'] == 3
412 412
 
413 413
     def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self):  # nopep8
@@ -436,16 +436,16 @@ class TestWorkspaceContents(FunctionalTest):
436 436
 
437 437
         assert len(res) == 1
438 438
         content = res[0]
439
-        assert content['content_type_slug'] == 'page'
440
-        assert content['id'] == 17
439
+        assert content['content_type'] == 'page'
440
+        assert content['content_id'] == 17
441 441
         assert content['is_archived'] is False
442 442
         assert content['is_deleted'] is True
443 443
         assert content['label'].startswith('Bad Fruit Salad')
444 444
         assert content['parent_id'] is None
445 445
         assert content['show_in_ui'] is True
446 446
         assert content['slug'].startswith('bad-fruit-salad')
447
-        assert content['status_slug'] == 'open'
448
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
447
+        assert content['status'] == 'open'
448
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
449 449
         assert content['workspace_id'] == 3
450 450
 
451 451
     def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
@@ -500,42 +500,42 @@ class TestWorkspaceContents(FunctionalTest):
500 500
         ).json_body   # nopep8
501 501
         assert len(res) == 3
502 502
         content = res[0]
503
-        assert content['content_type_slug'] == 'page'
504
-        assert content['id'] == 12
503
+        assert content['content_type'] == 'page'
504
+        assert content['content_id'] == 12
505 505
         assert content['is_archived'] is False
506 506
         assert content['is_deleted'] is False
507 507
         assert content['label'] == 'New Fruit Salad'
508 508
         assert content['parent_id'] == 10
509 509
         assert content['show_in_ui'] is True
510 510
         assert content['slug'] == 'new-fruit-salad'
511
-        assert content['status_slug'] == 'open'
512
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
511
+        assert content['status'] == 'open'
512
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
513 513
         assert content['workspace_id'] == 2
514 514
 
515 515
         content = res[1]
516
-        assert content['content_type_slug'] == 'page'
517
-        assert content['id'] == 13
516
+        assert content['content_type'] == 'page'
517
+        assert content['content_id'] == 13
518 518
         assert content['is_archived'] is True
519 519
         assert content['is_deleted'] is False
520 520
         assert content['label'].startswith('Fruit Salad')
521 521
         assert content['parent_id'] == 10
522 522
         assert content['show_in_ui'] is True
523 523
         assert content['slug'].startswith('fruit-salad')
524
-        assert content['status_slug'] == 'open'
525
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
524
+        assert content['status'] == 'open'
525
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
526 526
         assert content['workspace_id'] == 2
527 527
 
528 528
         content = res[2]
529
-        assert content['content_type_slug'] == 'page'
530
-        assert content['id'] == 14
529
+        assert content['content_type'] == 'page'
530
+        assert content['content_id'] == 14
531 531
         assert content['is_archived'] is False
532 532
         assert content['is_deleted'] is True
533 533
         assert content['label'].startswith('Bad Fruit Salad')
534 534
         assert content['parent_id'] == 10
535 535
         assert content['show_in_ui'] is True
536 536
         assert content['slug'].startswith('bad-fruit-salad')
537
-        assert content['status_slug'] == 'open'
538
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
537
+        assert content['status'] == 'open'
538
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
539 539
         assert content['workspace_id'] == 2
540 540
 
541 541
     def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self):  # nopep8
@@ -562,16 +562,16 @@ class TestWorkspaceContents(FunctionalTest):
562 562
         ).json_body   # nopep8
563 563
         assert len(res) == 1
564 564
         content = res[0]
565
-        assert content['content_type_slug']
566
-        assert content['id'] == 12
565
+        assert content['content_type']
566
+        assert content['content_id'] == 12
567 567
         assert content['is_archived'] is False
568 568
         assert content['is_deleted'] is False
569 569
         assert content['label'] == 'New Fruit Salad'
570 570
         assert content['parent_id'] == 10
571 571
         assert content['show_in_ui'] is True
572 572
         assert content['slug'] == 'new-fruit-salad'
573
-        assert content['status_slug'] == 'open'
574
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
573
+        assert content['status'] == 'open'
574
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
575 575
         assert content['workspace_id'] == 2
576 576
 
577 577
     def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self):  # nopep8
@@ -598,16 +598,16 @@ class TestWorkspaceContents(FunctionalTest):
598 598
         ).json_body   # nopep8
599 599
         assert len(res) == 1
600 600
         content = res[0]
601
-        assert content['content_type_slug'] == 'page'
602
-        assert content['id'] == 13
601
+        assert content['content_type'] == 'page'
602
+        assert content['content_id'] == 13
603 603
         assert content['is_archived'] is True
604 604
         assert content['is_deleted'] is False
605 605
         assert content['label'].startswith('Fruit Salad')
606 606
         assert content['parent_id'] == 10
607 607
         assert content['show_in_ui'] is True
608 608
         assert content['slug'].startswith('fruit-salad')
609
-        assert content['status_slug'] == 'open'
610
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
609
+        assert content['status'] == 'open'
610
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
611 611
         assert content['workspace_id'] == 2
612 612
 
613 613
     def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self):  # nopep8
@@ -635,16 +635,16 @@ class TestWorkspaceContents(FunctionalTest):
635 635
 
636 636
         assert len(res) == 1
637 637
         content = res[0]
638
-        assert content['content_type_slug'] == 'page'
639
-        assert content['id'] == 14
638
+        assert content['content_type'] == 'page'
639
+        assert content['content_id'] == 14
640 640
         assert content['is_archived'] is False
641 641
         assert content['is_deleted'] is True
642 642
         assert content['label'].startswith('Bad Fruit Salad')
643 643
         assert content['parent_id'] == 10
644 644
         assert content['show_in_ui'] is True
645 645
         assert content['slug'].startswith('bad-fruit-salad')
646
-        assert content['status_slug'] == 'open'
647
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
646
+        assert content['status'] == 'open'
647
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
648 648
         assert content['workspace_id'] == 2
649 649
 
650 650
     def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self):  # nopep8
@@ -741,7 +741,7 @@ class TestWorkspaceContents(FunctionalTest):
741 741
         )
742 742
         params = {
743 743
             'label': 'GenericCreatedContent',
744
-            'content_type_slug': 'markdownpage',
744
+            'content_type': 'markdownpage',
745 745
         }
746 746
         res = self.testapp.post_json(
747 747
             '/api/v2/workspaces/1/contents',
@@ -750,16 +750,16 @@ class TestWorkspaceContents(FunctionalTest):
750 750
         )
751 751
         assert res
752 752
         assert res.json_body
753
-        assert res.json_body['status_slug'] == 'open'
754
-        assert res.json_body['id']
755
-        assert res.json_body['content_type_slug'] == 'markdownpage'
753
+        assert res.json_body['status'] == 'open'
754
+        assert res.json_body['content_id']
755
+        assert res.json_body['content_type'] == 'markdownpage'
756 756
         assert res.json_body['is_archived'] is False
757 757
         assert res.json_body['is_deleted'] is False
758 758
         assert res.json_body['workspace_id'] == 1
759 759
         assert res.json_body['slug'] == 'genericcreatedcontent'
760 760
         assert res.json_body['parent_id'] is None
761 761
         assert res.json_body['show_in_ui'] is True
762
-        assert res.json_body['sub_content_type_slug']
762
+        assert res.json_body['sub_content_types']
763 763
         params_active = {
764 764
             'parent_id': 0,
765 765
             'show_archived': 0,
@@ -801,18 +801,18 @@ class TestWorkspaceContents(FunctionalTest):
801 801
         }
802 802
         folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
803 803
         folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
804
-        assert [content for content in folder1_contents if content['id'] == 8]  # nopep8
805
-        assert not [content for content in folder2_contents if content['id'] == 8]  # nopep8
804
+        assert [content for content in folder1_contents if content['content_id'] == 8]  # nopep8
805
+        assert not [content for content in folder2_contents if content['content_id'] == 8]  # nopep8
806 806
         # TODO - G.M - 2018-06-163 - Check content
807 807
         res = self.testapp.put_json(
808 808
             '/api/v2/workspaces/2/contents/8/move',
809 809
             params=params,
810
-            status=200
810
+            status=204
811 811
         )
812 812
         new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
813 813
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
814
-        assert not [content for content in new_folder1_contents if content['id'] == 8]  # nopep8
815
-        assert [content for content in new_folder2_contents if content['id'] == 8]  # nopep8
814
+        assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
815
+        assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
816 816
 
817 817
     def test_api_put_move_content__ok_200__to_root(self):
818 818
         """
@@ -1055,18 +1055,18 @@ class TestWorkspaceContents(FunctionalTest):
1055 1055
         }
1056 1056
         active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
1057 1057
         deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8
1058
-        assert [content for content in active_contents if content['id'] == 8]  # nopep8
1059
-        assert not [content for content in deleted_contents if content['id'] == 8]  # nopep8
1058
+        assert [content for content in active_contents if content['content_id'] == 8]  # nopep8
1059
+        assert not [content for content in deleted_contents if content['content_id'] == 8]  # nopep8
1060 1060
         # TODO - G.M - 2018-06-163 - Check content
1061 1061
         res = self.testapp.put_json(
1062 1062
             # INFO - G.M - 2018-06-163 - delete Apple_Pie
1063 1063
             '/api/v2/workspaces/2/contents/8/delete',
1064
-            status=200
1064
+            status=204
1065 1065
         )
1066 1066
         new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
1067 1067
         new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8
1068
-        assert not [content for content in new_active_contents if content['id'] == 8]  # nopep8
1069
-        assert [content for content in new_deleted_contents if content['id'] == 8]  # nopep8
1068
+        assert not [content for content in new_active_contents if content['content_id'] == 8]  # nopep8
1069
+        assert [content for content in new_deleted_contents if content['content_id'] == 8]  # nopep8
1070 1070
 
1071 1071
     def test_api_put_archive_content__ok_200__nominal_case(self):
1072 1072
         """
@@ -1094,16 +1094,16 @@ class TestWorkspaceContents(FunctionalTest):
1094 1094
         }
1095 1095
         active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
1096 1096
         archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8
1097
-        assert [content for content in active_contents if content['id'] == 8]  # nopep8
1098
-        assert not [content for content in archived_contents if content['id'] == 8]  # nopep8
1097
+        assert [content for content in active_contents if content['content_id'] == 8]  # nopep8
1098
+        assert not [content for content in archived_contents if content['content_id'] == 8]  # nopep8
1099 1099
         res = self.testapp.put_json(
1100 1100
             '/api/v2/workspaces/2/contents/8/archive',
1101
-            status=200
1101
+            status=204
1102 1102
         )
1103 1103
         new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
1104 1104
         new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8
1105
-        assert not [content for content in new_active_contents if content['id'] == 8]  # nopep8
1106
-        assert [content for content in new_archived_contents if content['id'] == 8]  # nopep8
1105
+        assert not [content for content in new_active_contents if content['content_id'] == 8]  # nopep8
1106
+        assert [content for content in new_archived_contents if content['content_id'] == 8]  # nopep8
1107 1107
 
1108 1108
     def test_api_put_undelete_content__ok_200__nominal_case(self):
1109 1109
         """
@@ -1131,16 +1131,16 @@ class TestWorkspaceContents(FunctionalTest):
1131 1131
         }
1132 1132
         active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
1133 1133
         deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8
1134
-        assert not [content for content in active_contents if content['id'] == 14]  # nopep8
1135
-        assert [content for content in deleted_contents if content['id'] == 14]  # nopep8
1134
+        assert not [content for content in active_contents if content['content_id'] == 14]  # nopep8
1135
+        assert [content for content in deleted_contents if content['content_id'] == 14]  # nopep8
1136 1136
         res = self.testapp.put_json(
1137 1137
             '/api/v2/workspaces/2/contents/14/undelete',
1138
-            status=200
1138
+            status=204
1139 1139
         )
1140 1140
         new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
1141 1141
         new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8
1142
-        assert [content for content in new_active_contents if content['id'] == 14]  # nopep8
1143
-        assert not [content for content in new_deleted_contents if content['id'] == 14]  # nopep8
1142
+        assert [content for content in new_active_contents if content['content_id'] == 14]  # nopep8
1143
+        assert not [content for content in new_deleted_contents if content['content_id'] == 14]  # nopep8
1144 1144
 
1145 1145
     def test_api_put_unarchive_content__ok_200__nominal_case(self):
1146 1146
         """
@@ -1168,13 +1168,13 @@ class TestWorkspaceContents(FunctionalTest):
1168 1168
         }
1169 1169
         active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
1170 1170
         archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8
1171
-        assert not [content for content in active_contents if content['id'] == 13]  # nopep8
1172
-        assert [content for content in archived_contents if content['id'] == 13]  # nopep8
1171
+        assert not [content for content in active_contents if content['content_id'] == 13]  # nopep8
1172
+        assert [content for content in archived_contents if content['content_id'] == 13]  # nopep8
1173 1173
         res = self.testapp.put_json(
1174 1174
             '/api/v2/workspaces/2/contents/13/unarchive',
1175
-            status=200
1175
+            status=204
1176 1176
         )
1177 1177
         new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
1178 1178
         new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8
1179
-        assert [content for content in new_active_contents if content['id'] == 13]  # nopep8
1180
-        assert not [content for content in new_archived_contents if content['id'] == 13]  # nopep8
1179
+        assert [content for content in new_active_contents if content['content_id'] == 13]  # nopep8
1180
+        assert not [content for content in new_archived_contents if content['content_id'] == 13]  # nopep8

+ 1 - 1
tracim/tests/library/test_user_api.py View File

@@ -131,7 +131,7 @@ class TestUserApi(DefaultTest):
131 131
         new_user = api.get_user_with_context(user)
132 132
         assert isinstance(new_user, UserInContext)
133 133
         assert new_user.user == user
134
-        assert new_user.profile.name == 'nobody'
134
+        assert new_user.profile == 'nobody'
135 135
         assert new_user.user_id == user.user_id
136 136
         assert new_user.email == 'admin@tracim.tracim'
137 137
         assert new_user.display_name == 'Admin'

+ 17 - 27
tracim/views/core_api/schemas.py View File

@@ -16,17 +16,6 @@ from tracim.models.context_models import LoginCredentials
16 16
 from tracim.models.data import UserRoleInWorkspace
17 17
 
18 18
 
19
-class ProfileSchema(marshmallow.Schema):
20
-    slug = marshmallow.fields.String(
21
-        attribute='name',
22
-        validate=OneOf(Profile._NAME),
23
-        example='managers',
24
-    )
25
-
26
-    class Meta:
27
-        description = 'User Profile, give user right on whole Tracim instance.'
28
-
29
-
30 19
 class UserSchema(marshmallow.Schema):
31 20
 
32 21
     user_id = marshmallow.fields.Int(dump_only=True, example=3)
@@ -34,12 +23,12 @@ class UserSchema(marshmallow.Schema):
34 23
         required=True,
35 24
         example='suri.cate@algoo.fr'
36 25
     )
37
-    display_name = marshmallow.fields.String(
26
+    public_name = marshmallow.fields.String(
38 27
         example='Suri Cate',
39 28
     )
40 29
     created = marshmallow.fields.DateTime(
41
-        format='iso8601',
42
-        description='User account creation date (iso8601 format).',
30
+        format='%Y-%m-%dT%H:%M:%SZ',
31
+        description='User account creation date',
43 32
     )
44 33
     is_active = marshmallow.fields.Bool(
45 34
         example=True,
@@ -64,9 +53,10 @@ class UserSchema(marshmallow.Schema):
64 53
                     "If no avatar, then set it to null "
65 54
                     "(and frontend will interpret this with a default avatar)",
66 55
     )
67
-    profile = marshmallow.fields.Nested(
68
-        ProfileSchema,
69
-        many=False,
56
+    profile = marshmallow.fields.String(
57
+        attribute='profile',
58
+        validate=OneOf(Profile._NAME),
59
+        example='managers',
70 60
     )
71 61
 
72 62
     class Meta:
@@ -187,7 +177,8 @@ class WorkspaceMenuEntrySchema(marshmallow.Schema):
187 177
 
188 178
 
189 179
 class WorkspaceDigestSchema(marshmallow.Schema):
190
-    id = marshmallow.fields.Int(example=4)
180
+    workspace_id = marshmallow.fields.Int(example=4)
181
+    slug = marshmallow.fields.String(example='intranet')
191 182
     label = marshmallow.fields.String(example='Intranet')
192 183
     sidebar_entries = marshmallow.fields.Nested(
193 184
         WorkspaceMenuEntrySchema,
@@ -199,7 +190,6 @@ class WorkspaceDigestSchema(marshmallow.Schema):
199 190
 
200 191
 
201 192
 class WorkspaceSchema(WorkspaceDigestSchema):
202
-    slug = marshmallow.fields.String(example='intranet')
203 193
     description = marshmallow.fields.String(example='All intranet data.')
204 194
 
205 195
     class Meta:
@@ -207,14 +197,14 @@ class WorkspaceSchema(WorkspaceDigestSchema):
207 197
 
208 198
 
209 199
 class WorkspaceMemberSchema(marshmallow.Schema):
210
-    role_slug = marshmallow.fields.String(
200
+    role = marshmallow.fields.String(
211 201
         example='contributor',
212 202
         validate=OneOf(UserRoleInWorkspace.get_all_role_slug())
213 203
     )
214 204
     user_id = marshmallow.fields.Int(example=3)
215 205
     workspace_id = marshmallow.fields.Int(example=4)
216 206
     user = marshmallow.fields.Nested(
217
-        UserSchema(only=('display_name', 'avatar_url'))
207
+        UserSchema(only=('public_name', 'avatar_url'))
218 208
     )
219 209
 
220 210
     class Meta:
@@ -256,7 +246,7 @@ class StatusSchema(marshmallow.Schema):
256 246
                     'Statuses are open, closed-validated, closed-invalidated, closed-deprecated'  # nopep8
257 247
     )
258 248
     global_status = marshmallow.fields.String(
259
-        example='Open',
249
+        example='open',
260 250
         description='global_status: open, closed',
261 251
         validate=OneOf([status.value for status in GlobalStatus]),
262 252
     )
@@ -317,7 +307,7 @@ class ContentCreationSchema(marshmallow.Schema):
317 307
         example='contract for client XXX',
318 308
         description='Title of the content to create'
319 309
     )
320
-    content_type_slug = marshmallow.fields.String(
310
+    content_type = marshmallow.fields.String(
321 311
         example='htmlpage',
322 312
         validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
323 313
     )
@@ -328,7 +318,7 @@ class ContentCreationSchema(marshmallow.Schema):
328 318
 
329 319
 
330 320
 class ContentDigestSchema(marshmallow.Schema):
331
-    id = marshmallow.fields.Int(example=6)
321
+    content_id = marshmallow.fields.Int(example=6)
332 322
     slug = marshmallow.fields.Str(example='intervention-report-12')
333 323
     parent_id = marshmallow.fields.Int(
334 324
         example=34,
@@ -339,17 +329,17 @@ class ContentDigestSchema(marshmallow.Schema):
339 329
         example=19,
340 330
     )
341 331
     label = marshmallow.fields.Str(example='Intervention Report 12')
342
-    content_type_slug = marshmallow.fields.Str(
332
+    content_type = marshmallow.fields.Str(
343 333
         example='htmlpage',
344 334
         validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
345 335
     )
346
-    sub_content_type_slug = marshmallow.fields.List(
336
+    sub_content_types = marshmallow.fields.List(
347 337
         marshmallow.fields.Str,
348 338
         description='list of content types allowed as sub contents. '
349 339
                     'This field is required for folder contents, '
350 340
                     'set it to empty list in other cases'
351 341
     )
352
-    status_slug = marshmallow.fields.Str(
342
+    status = marshmallow.fields.Str(
353 343
         example='closed-deprecated',
354 344
         validate=OneOf([status.slug for status in CONTENT_DEFAULT_STATUS]),
355 345
         description='this slug is found in content_type available statuses',

+ 6 - 6
tracim/views/core_api/workspace_controller.py View File

@@ -149,7 +149,7 @@ class WorkspaceController(Controller):
149 149
         )
150 150
         content = api.create(
151 151
             label=creation_data.label,
152
-            content_type=creation_data.content_type_slug,
152
+            content_type=creation_data.content_type,
153 153
             workspace=request.current_workspace,
154 154
         )
155 155
         api.save(content, ActionDescription.CREATION)
@@ -166,7 +166,7 @@ class WorkspaceController(Controller):
166 166
     @require_candidate_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
167 167
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
168 168
     @hapic.input_body(ContentMoveSchema())
169
-    @hapic.output_body(NoContentSchema())
169
+    @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
170 170
     def move_content(
171 171
             self,
172 172
             context,
@@ -217,7 +217,7 @@ class WorkspaceController(Controller):
217 217
     @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
218 218
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
219 219
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
220
-    @hapic.output_body(NoContentSchema())
220
+    @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
221 221
     def delete_content(
222 222
             self,
223 223
             context,
@@ -252,7 +252,7 @@ class WorkspaceController(Controller):
252 252
     @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
253 253
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
254 254
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
255
-    @hapic.output_body(NoContentSchema())
255
+    @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
256 256
     def undelete_content(
257 257
             self,
258 258
             context,
@@ -288,7 +288,7 @@ class WorkspaceController(Controller):
288 288
     @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
289 289
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
290 290
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
291
-    @hapic.output_body(NoContentSchema())
291
+    @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
292 292
     def archive_content(
293 293
             self,
294 294
             context,
@@ -320,7 +320,7 @@ class WorkspaceController(Controller):
320 320
     @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
321 321
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
322 322
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
323
-    @hapic.output_body(NoContentSchema())
323
+    @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
324 324
     def unarchive_content(
325 325
             self,
326 326
             context,