Browse Source

Merge pull request #9 from tracim/fix/better_app_content_type_list

Bastien Sevajol 6 years ago
parent
commit
6f902b63e4
No account linked to committer's email

+ 14 - 2
backend/tracim_backend/models/applications.py View File

59
 
59
 
60
 )
60
 )
61
 
61
 
62
+folder = Application(
63
+    label='Folder',
64
+    slug='contents/folder',
65
+    fa_icon='folder-open-o',
66
+    hexcolor='#252525',
67
+    is_active=True,
68
+    config={},
69
+    main_route='',
70
+)
71
+
62
 _file = Application(
72
 _file = Application(
63
     label='Files',
73
     label='Files',
64
     slug='contents/file',
74
     slug='contents/file',
92
 # List of applications
102
 # List of applications
93
 applications = [
103
 applications = [
94
     html_documents,
104
     html_documents,
95
-    markdownpluspage,
105
+    # TODO - G.M - 2018-08-02 - Restore markdownpage app
106
+    # markdownpluspage,
96
     _file,
107
     _file,
97
     thread,
108
     thread,
98
-    calendar,
109
+    folder,
110
+    # calendar,
99
 ]
111
 ]

+ 6 - 4
backend/tracim_backend/models/contents.py View File

6
 from tracim_backend.exceptions import ContentStatusNotExist
6
 from tracim_backend.exceptions import ContentStatusNotExist
7
 from tracim_backend.models.applications import html_documents
7
 from tracim_backend.models.applications import html_documents
8
 from tracim_backend.models.applications import _file
8
 from tracim_backend.models.applications import _file
9
+from tracim_backend.models.applications import folder
9
 from tracim_backend.models.applications import thread
10
 from tracim_backend.models.applications import thread
10
 from tracim_backend.models.applications import markdownpluspage
11
 from tracim_backend.models.applications import markdownpluspage
11
 
12
 
171
 # TODO - G.M - 31-05-2018 - Set Better folder params
172
 # TODO - G.M - 31-05-2018 - Set Better folder params
172
 folder_type = ContentType(
173
 folder_type = ContentType(
173
     slug='folder',
174
     slug='folder',
174
-    fa_icon=thread.fa_icon,
175
-    hexcolor=thread.hexcolor,
175
+    fa_icon=folder.fa_icon,
176
+    hexcolor=folder.hexcolor,
176
     label='Folder',
177
     label='Folder',
177
-    creation_label='Create collection of any documents',
178
+    creation_label='Create a folder',
178
     available_statuses=CONTENT_STATUS.get_all(),
179
     available_statuses=CONTENT_STATUS.get_all(),
179
 )
180
 )
180
 
181
 
261
     [
262
     [
262
         thread_type,
263
         thread_type,
263
         file_type,
264
         file_type,
264
-        markdownpluspage_type,
265
+        # TODO - G.M - 2018-08-02 - Restore markdown page content
266
+        #    markdownpluspage_type,
265
         html_documents_type,
267
         html_documents_type,
266
     ]
268
     ]
267
 )
269
 )

+ 24 - 72
backend/tracim_backend/tests/functional/test_system.py View File

1
 # coding=utf-8
1
 # coding=utf-8
2
+from tracim_backend.models.contents import CONTENT_TYPES
2
 from tracim_backend.tests import FunctionalTest
3
 from tracim_backend.tests import FunctionalTest
4
+from tracim_backend.models.applications import applications
3
 
5
 
4
 """
6
 """
5
 Tests for /api/v2/system subpath endpoints.
7
 Tests for /api/v2/system subpath endpoints.
24
         )
26
         )
25
         res = self.testapp.get('/api/v2/system/applications', status=200)
27
         res = self.testapp.get('/api/v2/system/applications', status=200)
26
         res = res.json_body
28
         res = res.json_body
27
-        application = res[0]
28
-        assert application['label'] == "Text Documents"
29
-        assert application['slug'] == 'contents/html-document'
30
-        assert application['fa_icon'] == 'file-text-o'
31
-        assert application['hexcolor'] == '#3f52e3'
32
-        assert application['is_active'] is True
33
-        assert 'config' in application
34
-        application = res[1]
35
-        assert application['label'] == "Markdown Plus Documents"
36
-        assert application['slug'] == 'contents/markdownpluspage'
37
-        assert application['fa_icon'] == 'file-code-o'
38
-        assert application['hexcolor'] == '#f12d2d'
39
-        assert application['is_active'] is True
40
-        assert 'config' in application
41
-        application = res[2]
42
-        assert application['label'] == "Files"
43
-        assert application['slug'] == 'contents/file'
44
-        assert application['fa_icon'] == 'paperclip'
45
-        assert application['hexcolor'] == '#FF9900'
46
-        assert application['is_active'] is True
47
-        assert 'config' in application
48
-        application = res[3]
49
-        assert application['label'] == "Threads"
50
-        assert application['slug'] == 'contents/thread'
51
-        assert application['fa_icon'] == 'comments-o'
52
-        assert application['hexcolor'] == '#ad4cf9'
53
-        assert application['is_active'] is True
54
-        assert 'config' in application
55
-        application = res[4]
56
-        assert application['label'] == "Calendar"
57
-        assert application['slug'] == 'calendar'
58
-        assert application['fa_icon'] == 'calendar'
59
-        assert application['hexcolor'] == '#757575'
60
-        assert application['is_active'] is True
61
-        assert 'config' in application
29
+        assert len(res) == len(applications)
30
+        for counter, application in enumerate(applications):
31
+            assert res[counter]['label'] == application.label
32
+            assert res[counter]['slug'] == application.slug
33
+            assert res[counter]['fa_icon'] == application.fa_icon
34
+            assert res[counter]['hexcolor'] == application.hexcolor
35
+            assert res[counter]['is_active'] == application.is_active
36
+            assert res[counter]['config'] == application.config
62
 
37
 
63
     def test_api__get_applications__err_401__unregistered_user(self):
38
     def test_api__get_applications__err_401__unregistered_user(self):
64
         """
39
         """
96
         )
71
         )
97
         res = self.testapp.get('/api/v2/system/content_types', status=200)
72
         res = self.testapp.get('/api/v2/system/content_types', status=200)
98
         res = res.json_body
73
         res = res.json_body
74
+        assert len(res) == len(CONTENT_TYPES.endpoint_allowed_types_slug())
75
+        content_types = CONTENT_TYPES.endpoint_allowed_types_slug()
99
 
76
 
100
-        content_type = res[1]
101
-        assert content_type['slug'] == 'thread'
102
-        assert content_type['fa_icon'] == 'comments-o'
103
-        assert content_type['hexcolor'] == '#ad4cf9'
104
-        assert content_type['label'] == 'Thread'
105
-        assert content_type['creation_label'] == 'Discuss about a topic'
106
-        assert 'available_statuses' in content_type
107
-        assert len(content_type['available_statuses']) == 4
108
-
109
-        content_type = res[2]
110
-        assert content_type['slug'] == 'file'
111
-        assert content_type['fa_icon'] == 'paperclip'
112
-        assert content_type['hexcolor'] == '#FF9900'
113
-        assert content_type['label'] == 'File'
114
-        assert content_type['creation_label'] == 'Upload a file'
115
-        assert 'available_statuses' in content_type
116
-        assert len(content_type['available_statuses']) == 4
117
-
118
-        content_type = res[3]
119
-        assert content_type['slug'] == 'markdownpage'
120
-        assert content_type['fa_icon'] == 'file-code-o'
121
-        assert content_type['hexcolor'] == '#f12d2d'
122
-        assert content_type['label'] == 'Rich Markdown File'
123
-        assert content_type['creation_label'] == 'Create a Markdown document'
124
-        assert 'available_statuses' in content_type
125
-        assert len(content_type['available_statuses']) == 4
126
-
127
-        content_type = res[4]
128
-        assert content_type['slug'] == 'html-document'
129
-        assert content_type['fa_icon'] == 'file-text-o'
130
-        assert content_type['hexcolor'] == '#3f52e3'
131
-        assert content_type['label'] == 'Text Document'
132
-        assert content_type['creation_label'] == 'Write a document'
133
-        assert 'available_statuses' in content_type
134
-        assert len(content_type['available_statuses']) == 4
135
-        # TODO - G.M - 31-05-2018 - Check Folder type
136
-        # TODO - G.M - 29-05-2018 - Better check for available_statuses
77
+        for counter, content_type_slug in enumerate(content_types):
78
+            content_type = CONTENT_TYPES.get_one_by_slug(content_type_slug)
79
+            assert res[counter]['slug'] == content_type.slug
80
+            assert res[counter]['fa_icon'] == content_type.fa_icon
81
+            assert res[counter]['hexcolor'] == content_type.hexcolor
82
+            assert res[counter]['label'] == content_type.label
83
+            assert res[counter]['creation_label'] == content_type.creation_label
84
+            for status_counter, status in enumerate(content_type.available_statuses):
85
+                assert res[counter]['available_statuses'][status_counter]['fa_icon'] == status.fa_icon  # nopep8
86
+                assert res[counter]['available_statuses'][status_counter]['global_status'] == status.global_status  # nopep8
87
+                assert res[counter]['available_statuses'][status_counter]['slug'] == status.slug  # nopep8
88
+                assert res[counter]['available_statuses'][status_counter]['hexcolor'] == status.hexcolor  # nopep8
137
 
89
 
138
     def test_api__get_content_types__err_401__unregistered_user(self):
90
     def test_api__get_content_types__err_401__unregistered_user(self):
139
         """
91
         """

+ 4 - 15
backend/tracim_backend/tests/functional/test_user.py View File

2382
         assert workspace['workspace_id'] == 1
2382
         assert workspace['workspace_id'] == 1
2383
         assert workspace['label'] == 'Business'
2383
         assert workspace['label'] == 'Business'
2384
         assert workspace['slug'] == 'business'
2384
         assert workspace['slug'] == 'business'
2385
-        assert len(workspace['sidebar_entries']) == 7
2385
+        assert len(workspace['sidebar_entries']) == 5
2386
 
2386
 
2387
+        # TODO - G.M - 2018-08-02 - Better test for sidebar entry, make it
2388
+        # not fixed on active application/content-file
2387
         sidebar_entry = workspace['sidebar_entries'][0]
2389
         sidebar_entry = workspace['sidebar_entries'][0]
2388
         assert sidebar_entry['slug'] == 'dashboard'
2390
         assert sidebar_entry['slug'] == 'dashboard'
2389
         assert sidebar_entry['label'] == 'Dashboard'
2391
         assert sidebar_entry['label'] == 'Dashboard'
2406
         assert sidebar_entry['fa_icon'] == "file-text-o"
2408
         assert sidebar_entry['fa_icon'] == "file-text-o"
2407
 
2409
 
2408
         sidebar_entry = workspace['sidebar_entries'][3]
2410
         sidebar_entry = workspace['sidebar_entries'][3]
2409
-        assert sidebar_entry['slug'] == 'contents/markdownpluspage'
2410
-        assert sidebar_entry['label'] == 'Markdown Plus Documents'
2411
-        assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=markdownpluspage"    # nopep8
2412
-        assert sidebar_entry['hexcolor'] == "#f12d2d"
2413
-        assert sidebar_entry['fa_icon'] == "file-code-o"
2414
-
2415
-        sidebar_entry = workspace['sidebar_entries'][4]
2416
         assert sidebar_entry['slug'] == 'contents/file'
2411
         assert sidebar_entry['slug'] == 'contents/file'
2417
         assert sidebar_entry['label'] == 'Files'
2412
         assert sidebar_entry['label'] == 'Files'
2418
         assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=file"  # nopep8
2413
         assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=file"  # nopep8
2419
         assert sidebar_entry['hexcolor'] == "#FF9900"
2414
         assert sidebar_entry['hexcolor'] == "#FF9900"
2420
         assert sidebar_entry['fa_icon'] == "paperclip"
2415
         assert sidebar_entry['fa_icon'] == "paperclip"
2421
 
2416
 
2422
-        sidebar_entry = workspace['sidebar_entries'][5]
2417
+        sidebar_entry = workspace['sidebar_entries'][4]
2423
         assert sidebar_entry['slug'] == 'contents/thread'
2418
         assert sidebar_entry['slug'] == 'contents/thread'
2424
         assert sidebar_entry['label'] == 'Threads'
2419
         assert sidebar_entry['label'] == 'Threads'
2425
         assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=thread"  # nopep8
2420
         assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=thread"  # nopep8
2426
         assert sidebar_entry['hexcolor'] == "#ad4cf9"
2421
         assert sidebar_entry['hexcolor'] == "#ad4cf9"
2427
         assert sidebar_entry['fa_icon'] == "comments-o"
2422
         assert sidebar_entry['fa_icon'] == "comments-o"
2428
 
2423
 
2429
-        sidebar_entry = workspace['sidebar_entries'][6]
2430
-        assert sidebar_entry['slug'] == 'calendar'
2431
-        assert sidebar_entry['label'] == 'Calendar'
2432
-        assert sidebar_entry['route'] == "/#/workspaces/1/calendar"  # nopep8
2433
-        assert sidebar_entry['hexcolor'] == "#757575"
2434
-        assert sidebar_entry['fa_icon'] == "calendar"
2435
 
2424
 
2436
     def test_api__get_user_workspaces__err_403__unallowed_user(self):
2425
     def test_api__get_user_workspaces__err_403__unallowed_user(self):
2437
         """
2426
         """

+ 14 - 26
backend/tracim_backend/tests/functional/test_workspaces.py View File

41
         assert workspace['slug'] == 'business'
41
         assert workspace['slug'] == 'business'
42
         assert workspace['label'] == 'Business'
42
         assert workspace['label'] == 'Business'
43
         assert workspace['description'] == 'All importants documents'
43
         assert workspace['description'] == 'All importants documents'
44
-        assert len(workspace['sidebar_entries']) == 7
44
+        assert len(workspace['sidebar_entries']) == 5
45
 
45
 
46
+        # TODO - G.M - 2018-08-02 - Better test for sidebar entry, make it
47
+        # not fixed on active application/content-file
46
         sidebar_entry = workspace['sidebar_entries'][0]
48
         sidebar_entry = workspace['sidebar_entries'][0]
47
         assert sidebar_entry['slug'] == 'dashboard'
49
         assert sidebar_entry['slug'] == 'dashboard'
48
         assert sidebar_entry['label'] == 'Dashboard'
50
         assert sidebar_entry['label'] == 'Dashboard'
65
         assert sidebar_entry['fa_icon'] == "file-text-o"
67
         assert sidebar_entry['fa_icon'] == "file-text-o"
66
 
68
 
67
         sidebar_entry = workspace['sidebar_entries'][3]
69
         sidebar_entry = workspace['sidebar_entries'][3]
68
-        assert sidebar_entry['slug'] == 'contents/markdownpluspage'
69
-        assert sidebar_entry['label'] == 'Markdown Plus Documents'
70
-        assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=markdownpluspage"    # nopep8
71
-        assert sidebar_entry['hexcolor'] == "#f12d2d"
72
-        assert sidebar_entry['fa_icon'] == "file-code-o"
73
-
74
-        sidebar_entry = workspace['sidebar_entries'][4]
75
         assert sidebar_entry['slug'] == 'contents/file'
70
         assert sidebar_entry['slug'] == 'contents/file'
76
         assert sidebar_entry['label'] == 'Files'
71
         assert sidebar_entry['label'] == 'Files'
77
         assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=file"  # nopep8
72
         assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=file"  # nopep8
78
         assert sidebar_entry['hexcolor'] == "#FF9900"
73
         assert sidebar_entry['hexcolor'] == "#FF9900"
79
         assert sidebar_entry['fa_icon'] == "paperclip"
74
         assert sidebar_entry['fa_icon'] == "paperclip"
80
 
75
 
81
-        sidebar_entry = workspace['sidebar_entries'][5]
76
+        sidebar_entry = workspace['sidebar_entries'][4]
82
         assert sidebar_entry['slug'] == 'contents/thread'
77
         assert sidebar_entry['slug'] == 'contents/thread'
83
         assert sidebar_entry['label'] == 'Threads'
78
         assert sidebar_entry['label'] == 'Threads'
84
         assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=thread"  # nopep8
79
         assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=thread"  # nopep8
85
         assert sidebar_entry['hexcolor'] == "#ad4cf9"
80
         assert sidebar_entry['hexcolor'] == "#ad4cf9"
86
         assert sidebar_entry['fa_icon'] == "comments-o"
81
         assert sidebar_entry['fa_icon'] == "comments-o"
87
 
82
 
88
-        sidebar_entry = workspace['sidebar_entries'][6]
89
-        assert sidebar_entry['slug'] == 'calendar'
90
-        assert sidebar_entry['label'] == 'Calendar'
91
-        assert sidebar_entry['route'] == "/#/workspaces/1/calendar"  # nopep8
92
-        assert sidebar_entry['hexcolor'] == "#757575"
93
-        assert sidebar_entry['fa_icon'] == "calendar"
94
-
95
     def test_api__update_workspace__ok_200__nominal_case(self) -> None:
83
     def test_api__update_workspace__ok_200__nominal_case(self) -> None:
96
         """
84
         """
97
         Test update workspace
85
         Test update workspace
118
         assert workspace['slug'] == 'business'
106
         assert workspace['slug'] == 'business'
119
         assert workspace['label'] == 'Business'
107
         assert workspace['label'] == 'Business'
120
         assert workspace['description'] == 'All importants documents'
108
         assert workspace['description'] == 'All importants documents'
121
-        assert len(workspace['sidebar_entries']) == 7
109
+        assert len(workspace['sidebar_entries']) == 5
122
 
110
 
123
         # modify workspace
111
         # modify workspace
124
         res = self.testapp.put_json(
112
         res = self.testapp.put_json(
132
         assert workspace['slug'] == 'superworkspace'
120
         assert workspace['slug'] == 'superworkspace'
133
         assert workspace['label'] == 'superworkspace'
121
         assert workspace['label'] == 'superworkspace'
134
         assert workspace['description'] == 'mysuperdescription'
122
         assert workspace['description'] == 'mysuperdescription'
135
-        assert len(workspace['sidebar_entries']) == 7
123
+        assert len(workspace['sidebar_entries']) == 5
136
 
124
 
137
         # after
125
         # after
138
         res = self.testapp.get(
126
         res = self.testapp.get(
145
         assert workspace['slug'] == 'superworkspace'
133
         assert workspace['slug'] == 'superworkspace'
146
         assert workspace['label'] == 'superworkspace'
134
         assert workspace['label'] == 'superworkspace'
147
         assert workspace['description'] == 'mysuperdescription'
135
         assert workspace['description'] == 'mysuperdescription'
148
-        assert len(workspace['sidebar_entries']) == 7
136
+        assert len(workspace['sidebar_entries']) == 5
149
 
137
 
150
     def test_api__update_workspace__err_400__empty_label(self) -> None:
138
     def test_api__update_workspace__err_400__empty_label(self) -> None:
151
         """
139
         """
1438
         params = {
1426
         params = {
1439
             'parent_id': None,
1427
             'parent_id': None,
1440
             'label': 'GenericCreatedContent',
1428
             'label': 'GenericCreatedContent',
1441
-            'content_type': 'markdownpage',
1429
+            'content_type': 'html-document',
1442
         }
1430
         }
1443
         res = self.testapp.post_json(
1431
         res = self.testapp.post_json(
1444
             '/api/v2/workspaces/1/contents',
1432
             '/api/v2/workspaces/1/contents',
1449
         assert res.json_body
1437
         assert res.json_body
1450
         assert res.json_body['status'] == 'open'
1438
         assert res.json_body['status'] == 'open'
1451
         assert res.json_body['content_id']
1439
         assert res.json_body['content_id']
1452
-        assert res.json_body['content_type'] == 'markdownpage'
1440
+        assert res.json_body['content_type'] == 'html-document'
1453
         assert res.json_body['is_archived'] is False
1441
         assert res.json_body['is_archived'] is False
1454
         assert res.json_body['is_deleted'] is False
1442
         assert res.json_body['is_deleted'] is False
1455
         assert res.json_body['workspace_id'] == 1
1443
         assert res.json_body['workspace_id'] == 1
1480
         )
1468
         )
1481
         params = {
1469
         params = {
1482
             'label': 'GenericCreatedContent',
1470
             'label': 'GenericCreatedContent',
1483
-            'content_type': 'markdownpage',
1471
+            'content_type': 'html-document',
1484
         }
1472
         }
1485
         res = self.testapp.post_json(
1473
         res = self.testapp.post_json(
1486
             '/api/v2/workspaces/1/contents',
1474
             '/api/v2/workspaces/1/contents',
1491
         assert res.json_body
1479
         assert res.json_body
1492
         assert res.json_body['status'] == 'open'
1480
         assert res.json_body['status'] == 'open'
1493
         assert res.json_body['content_id']
1481
         assert res.json_body['content_id']
1494
-        assert res.json_body['content_type'] == 'markdownpage'
1482
+        assert res.json_body['content_type'] == 'html-document'
1495
         assert res.json_body['is_archived'] is False
1483
         assert res.json_body['is_archived'] is False
1496
         assert res.json_body['is_deleted'] is False
1484
         assert res.json_body['is_deleted'] is False
1497
         assert res.json_body['workspace_id'] == 1
1485
         assert res.json_body['workspace_id'] == 1
1544
         )
1532
         )
1545
         params = {
1533
         params = {
1546
             'label': 'GenericCreatedContent',
1534
             'label': 'GenericCreatedContent',
1547
-            'content_type': 'markdownpage',
1535
+            'content_type': 'html-document',
1548
             'parent_id': 10,
1536
             'parent_id': 10,
1549
         }
1537
         }
1550
         res = self.testapp.post_json(
1538
         res = self.testapp.post_json(
1556
         assert res.json_body
1544
         assert res.json_body
1557
         assert res.json_body['status'] == 'open'
1545
         assert res.json_body['status'] == 'open'
1558
         assert res.json_body['content_id']
1546
         assert res.json_body['content_id']
1559
-        assert res.json_body['content_type'] == 'markdownpage'
1547
+        assert res.json_body['content_type'] == 'html-document'
1560
         assert res.json_body['is_archived'] is False
1548
         assert res.json_body['is_archived'] is False
1561
         assert res.json_body['is_deleted'] is False
1549
         assert res.json_body['is_deleted'] is False
1562
         assert res.json_body['workspace_id'] == 1
1550
         assert res.json_body['workspace_id'] == 1
1587
         )
1575
         )
1588
         params = {
1576
         params = {
1589
             'label': '',
1577
             'label': '',
1590
-            'content_type': 'markdownpage',
1578
+            'content_type': 'html-document',
1591
         }
1579
         }
1592
         res = self.testapp.post_json(
1580
         res = self.testapp.post_json(
1593
             '/api/v2/workspaces/1/contents',
1581
             '/api/v2/workspaces/1/contents',