浏览代码

add exception case for contents

Guénaël Muller 6 年前
父节点
当前提交
dbea77ac88
共有 2 个文件被更改,包括 125 次插入25 次删除
  1. 4 0
      tracim/__init__.py
  2. 121 25
      tracim/tests/functional/test_contents.py

+ 4 - 0
tracim/__init__.py 查看文件

33
 from tracim.exceptions import InsufficientUserRoleInWorkspace
33
 from tracim.exceptions import InsufficientUserRoleInWorkspace
34
 from tracim.exceptions import WorkspaceNotFoundInTracimRequest
34
 from tracim.exceptions import WorkspaceNotFoundInTracimRequest
35
 from tracim.exceptions import UserNotFoundInTracimRequest
35
 from tracim.exceptions import UserNotFoundInTracimRequest
36
+from tracim.exceptions import ContentNotFoundInTracimRequest
36
 from tracim.exceptions import WorkspaceNotFound
37
 from tracim.exceptions import WorkspaceNotFound
38
+from tracim.exceptions import ContentNotFound
37
 from tracim.exceptions import UserDoesNotExist
39
 from tracim.exceptions import UserDoesNotExist
38
 from tracim.exceptions import AuthenticationFailed
40
 from tracim.exceptions import AuthenticationFailed
39
 from tracim.exceptions import ContentTypeNotAllowed
41
 from tracim.exceptions import ContentTypeNotAllowed
83
     # Bad request
85
     # Bad request
84
     context.handle_exception(WorkspaceNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST)  # nopep8
86
     context.handle_exception(WorkspaceNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST)  # nopep8
85
     context.handle_exception(UserNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST)  # nopep8
87
     context.handle_exception(UserNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST)  # nopep8
88
+    context.handle_exception(ContentNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST)  # nopep8
86
     context.handle_exception(WorkspaceNotFound, HTTPStatus.BAD_REQUEST)
89
     context.handle_exception(WorkspaceNotFound, HTTPStatus.BAD_REQUEST)
87
     context.handle_exception(UserDoesNotExist, HTTPStatus.BAD_REQUEST)
90
     context.handle_exception(UserDoesNotExist, HTTPStatus.BAD_REQUEST)
91
+    context.handle_exception(ContentNotFound, HTTPStatus.BAD_REQUEST)
88
     context.handle_exception(ContentTypeNotAllowed, HTTPStatus.BAD_REQUEST)
92
     context.handle_exception(ContentTypeNotAllowed, HTTPStatus.BAD_REQUEST)
89
     # Auth exception
93
     # Auth exception
90
     context.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
94
     context.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)

+ 121 - 25
tracim/tests/functional/test_contents.py 查看文件

13
 
13
 
14
     fixtures = [BaseFixture, ContentFixtures]
14
     fixtures = [BaseFixture, ContentFixtures]
15
 
15
 
16
-    def test_api__get_html_document__err_400__wrong_content_type(self) -> None:
17
-        """
18
-        Get one html document of a content
19
-        """
20
-        self.testapp.authorization = (
21
-            'Basic',
22
-            (
23
-                'admin@admin.admin',
24
-                'admin@admin.admin'
25
-            )
26
-        )
27
-        res = self.testapp.get(
28
-            '/api/v2/workspaces/2/html-documents/7',
29
-            status=400
30
-        )   # nopep8
31
-
32
     def test_api__get_html_document__ok_200__legacy_slug(self) -> None:
16
     def test_api__get_html_document__ok_200__legacy_slug(self) -> None:
33
         """
17
         """
34
         Get one html document of a content
18
         Get one html document of a content
44
         res = self.testapp.get(
28
         res = self.testapp.get(
45
             '/api/v2/workspaces/2/html-documents/6',
29
             '/api/v2/workspaces/2/html-documents/6',
46
             status=200
30
             status=200
47
-        )   # nopep8
31
+        )
48
         content = res.json_body
32
         content = res.json_body
49
         assert content['content_type'] == 'html-documents'
33
         assert content['content_type'] == 'html-documents'
50
         assert content['content_id'] == 6
34
         assert content['content_id'] == 6
85
         res = self.testapp.get(
69
         res = self.testapp.get(
86
             '/api/v2/workspaces/2/html-documents/6',
70
             '/api/v2/workspaces/2/html-documents/6',
87
             status=200
71
             status=200
88
-        )   # nopep8
72
+        )
89
         content = res.json_body
73
         content = res.json_body
90
         assert content['content_type'] == 'html-documents'
74
         assert content['content_type'] == 'html-documents'
91
         assert content['content_id'] == 6
75
         assert content['content_id'] == 6
112
         assert content['last_modifier']['avatar_url'] is None
96
         assert content['last_modifier']['avatar_url'] is None
113
         assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>'  # nopep8
97
         assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>'  # nopep8
114
 
98
 
99
+    def test_api__get_html_document__err_400__wrong_content_type(self) -> None:
100
+        """
101
+        Get one html document of a content content 7 is not html_document
102
+        """
103
+        self.testapp.authorization = (
104
+            'Basic',
105
+            (
106
+                'admin@admin.admin',
107
+                'admin@admin.admin'
108
+            )
109
+        )
110
+        res = self.testapp.get(
111
+            '/api/v2/workspaces/2/html-documents/7',
112
+            status=400
113
+        )
114
+
115
+    def test_api__get_html_document__err_400__content_does_not_exist(self) -> None:  # nopep8
116
+        """
117
+        Get one html document of a content (content 170 does not exist in db
118
+        """
119
+        self.testapp.authorization = (
120
+            'Basic',
121
+            (
122
+                'admin@admin.admin',
123
+                'admin@admin.admin'
124
+            )
125
+        )
126
+        res = self.testapp.get(
127
+            '/api/v2/workspaces/2/html-documents/170',
128
+            status=400
129
+        )
130
+
131
+    def test_api__get_html_document__err_400__content_not_in_workspace(self) -> None:  # nopep8
132
+        """
133
+        Get one html document of a content (content 6 is in workspace 2)
134
+        """
135
+        self.testapp.authorization = (
136
+            'Basic',
137
+            (
138
+                'admin@admin.admin',
139
+                'admin@admin.admin'
140
+            )
141
+        )
142
+        res = self.testapp.get(
143
+            '/api/v2/workspaces/1/html-documents/6',
144
+            status=400
145
+        )
146
+
147
+    def test_api__get_html_document__err_400__workspace_does_not_exist(self) -> None:  # nopep8
148
+        """
149
+        Get one html document of a content (Workspace 40 does not exist)
150
+        """
151
+        self.testapp.authorization = (
152
+            'Basic',
153
+            (
154
+                'admin@admin.admin',
155
+                'admin@admin.admin'
156
+            )
157
+        )
158
+        res = self.testapp.get(
159
+            '/api/v2/workspaces/40/html-documents/6',
160
+            status=400
161
+        )
162
+
115
     def test_api__update_html_document__ok_200__nominal_case(self) -> None:
163
     def test_api__update_html_document__ok_200__nominal_case(self) -> None:
116
         """
164
         """
117
         Update(put) one html document of a content
165
         Update(put) one html document of a content
158
         res = self.testapp.get(
206
         res = self.testapp.get(
159
             '/api/v2/workspaces/2/html-documents/6',
207
             '/api/v2/workspaces/2/html-documents/6',
160
             status=200
208
             status=200
161
-        )   # nopep8
209
+        )
162
         content = res.json_body
210
         content = res.json_body
163
         assert content['content_type'] == 'html-documents'
211
         assert content['content_type'] == 'html-documents'
164
         assert content['content_id'] == 6
212
         assert content['content_id'] == 6
284
         res = self.testapp.get(
332
         res = self.testapp.get(
285
             '/api/v2/workspaces/2/html-documents/6',
333
             '/api/v2/workspaces/2/html-documents/6',
286
             status=200
334
             status=200
287
-        )   # nopep8
335
+        )
288
         content = res.json_body
336
         content = res.json_body
289
         assert content['content_type'] == 'html-documents'
337
         assert content['content_type'] == 'html-documents'
290
         assert content['content_id'] == 6
338
         assert content['content_id'] == 6
301
         res = self.testapp.get(
349
         res = self.testapp.get(
302
             '/api/v2/workspaces/2/html-documents/6',
350
             '/api/v2/workspaces/2/html-documents/6',
303
             status=200
351
             status=200
304
-        )   # nopep8
352
+        )
305
         content = res.json_body
353
         content = res.json_body
306
         assert content['content_type'] == 'html-documents'
354
         assert content['content_type'] == 'html-documents'
307
         assert content['content_id'] == 6
355
         assert content['content_id'] == 6
330
         res = self.testapp.get(
378
         res = self.testapp.get(
331
             '/api/v2/workspaces/2/threads/6',
379
             '/api/v2/workspaces/2/threads/6',
332
             status=400
380
             status=400
333
-        )   # nopep8
381
+        )
334
 
382
 
335
     def test_api__get_thread__ok_200__nominal_case(self) -> None:
383
     def test_api__get_thread__ok_200__nominal_case(self) -> None:
336
         """
384
         """
373
         assert content['last_modifier']['avatar_url'] is None
421
         assert content['last_modifier']['avatar_url'] is None
374
         assert content['raw_content'] == 'What is the best cake?'  # nopep8
422
         assert content['raw_content'] == 'What is the best cake?'  # nopep8
375
 
423
 
424
+    def test_api__get_thread__err_400__content_does_not_exist(self) -> None:
425
+        """
426
+        Get one thread (content 170 does not exist)
427
+        """
428
+        self.testapp.authorization = (
429
+            'Basic',
430
+            (
431
+                'admin@admin.admin',
432
+                'admin@admin.admin'
433
+            )
434
+        )
435
+        res = self.testapp.get(
436
+            '/api/v2/workspaces/2/threads/170',
437
+            status=400
438
+        )
439
+
440
+    def test_api__get_thread__err_400__content_not_in_workspace(self) -> None:
441
+        """
442
+        Get one thread(content 7 is in workspace 2)
443
+        """
444
+        self.testapp.authorization = (
445
+            'Basic',
446
+            (
447
+                'admin@admin.admin',
448
+                'admin@admin.admin'
449
+            )
450
+        )
451
+        res = self.testapp.get(
452
+            '/api/v2/workspaces/1/threads/7',
453
+            status=400
454
+        )
455
+
456
+    def test_api__get_thread__err_400__workspace_does_not_exist(self) -> None:  # nopep8
457
+        """
458
+        Get one thread (Workspace 40 does not exist)
459
+        """
460
+        self.testapp.authorization = (
461
+            'Basic',
462
+            (
463
+                'admin@admin.admin',
464
+                'admin@admin.admin'
465
+            )
466
+        )
467
+        res = self.testapp.get(
468
+            '/api/v2/workspaces/40/threads/7',
469
+            status=400
470
+        )
471
+
376
     def test_api__update_thread__ok_200__nominal_case(self) -> None:
472
     def test_api__update_thread__ok_200__nominal_case(self) -> None:
377
         """
473
         """
378
-        Update(put) one html document of a content
474
+        Update(put) thread
379
         """
475
         """
380
         self.testapp.authorization = (
476
         self.testapp.authorization = (
381
             'Basic',
477
             'Basic',
447
             self
543
             self
448
     ) -> None:
544
     ) -> None:
449
         """
545
         """
450
-        Get one html document of a content
546
+        Get threads revisions
451
         """
547
         """
452
         self.testapp.authorization = (
548
         self.testapp.authorization = (
453
             'Basic',
549
             'Basic',
505
 
601
 
506
     def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
602
     def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
507
         """
603
         """
508
-        Get one html document of a content
604
+        Set thread status
509
         """
605
         """
510
         self.testapp.authorization = (
606
         self.testapp.authorization = (
511
             'Basic',
607
             'Basic',