Browse Source

add exception case for contents

Guénaël Muller 6 years ago
parent
commit
dbea77ac88
2 changed files with 125 additions and 25 deletions
  1. 4 0
      tracim/__init__.py
  2. 121 25
      tracim/tests/functional/test_contents.py

+ 4 - 0
tracim/__init__.py View File

@@ -33,7 +33,9 @@ from tracim.exceptions import InsufficientUserProfile
33 33
 from tracim.exceptions import InsufficientUserRoleInWorkspace
34 34
 from tracim.exceptions import WorkspaceNotFoundInTracimRequest
35 35
 from tracim.exceptions import UserNotFoundInTracimRequest
36
+from tracim.exceptions import ContentNotFoundInTracimRequest
36 37
 from tracim.exceptions import WorkspaceNotFound
38
+from tracim.exceptions import ContentNotFound
37 39
 from tracim.exceptions import UserDoesNotExist
38 40
 from tracim.exceptions import AuthenticationFailed
39 41
 from tracim.exceptions import ContentTypeNotAllowed
@@ -83,8 +85,10 @@ def web(global_config, **local_settings):
83 85
     # Bad request
84 86
     context.handle_exception(WorkspaceNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST)  # nopep8
85 87
     context.handle_exception(UserNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST)  # nopep8
88
+    context.handle_exception(ContentNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST)  # nopep8
86 89
     context.handle_exception(WorkspaceNotFound, HTTPStatus.BAD_REQUEST)
87 90
     context.handle_exception(UserDoesNotExist, HTTPStatus.BAD_REQUEST)
91
+    context.handle_exception(ContentNotFound, HTTPStatus.BAD_REQUEST)
88 92
     context.handle_exception(ContentTypeNotAllowed, HTTPStatus.BAD_REQUEST)
89 93
     # Auth exception
90 94
     context.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)

+ 121 - 25
tracim/tests/functional/test_contents.py View File

@@ -13,22 +13,6 @@ class TestHtmlDocuments(FunctionalTest):
13 13
 
14 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 16
     def test_api__get_html_document__ok_200__legacy_slug(self) -> None:
33 17
         """
34 18
         Get one html document of a content
@@ -44,7 +28,7 @@ class TestHtmlDocuments(FunctionalTest):
44 28
         res = self.testapp.get(
45 29
             '/api/v2/workspaces/2/html-documents/6',
46 30
             status=200
47
-        )   # nopep8
31
+        )
48 32
         content = res.json_body
49 33
         assert content['content_type'] == 'html-documents'
50 34
         assert content['content_id'] == 6
@@ -85,7 +69,7 @@ class TestHtmlDocuments(FunctionalTest):
85 69
         res = self.testapp.get(
86 70
             '/api/v2/workspaces/2/html-documents/6',
87 71
             status=200
88
-        )   # nopep8
72
+        )
89 73
         content = res.json_body
90 74
         assert content['content_type'] == 'html-documents'
91 75
         assert content['content_id'] == 6
@@ -112,6 +96,70 @@ class TestHtmlDocuments(FunctionalTest):
112 96
         assert content['last_modifier']['avatar_url'] is None
113 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 163
     def test_api__update_html_document__ok_200__nominal_case(self) -> None:
116 164
         """
117 165
         Update(put) one html document of a content
@@ -158,7 +206,7 @@ class TestHtmlDocuments(FunctionalTest):
158 206
         res = self.testapp.get(
159 207
             '/api/v2/workspaces/2/html-documents/6',
160 208
             status=200
161
-        )   # nopep8
209
+        )
162 210
         content = res.json_body
163 211
         assert content['content_type'] == 'html-documents'
164 212
         assert content['content_id'] == 6
@@ -284,7 +332,7 @@ class TestHtmlDocuments(FunctionalTest):
284 332
         res = self.testapp.get(
285 333
             '/api/v2/workspaces/2/html-documents/6',
286 334
             status=200
287
-        )   # nopep8
335
+        )
288 336
         content = res.json_body
289 337
         assert content['content_type'] == 'html-documents'
290 338
         assert content['content_id'] == 6
@@ -301,7 +349,7 @@ class TestHtmlDocuments(FunctionalTest):
301 349
         res = self.testapp.get(
302 350
             '/api/v2/workspaces/2/html-documents/6',
303 351
             status=200
304
-        )   # nopep8
352
+        )
305 353
         content = res.json_body
306 354
         assert content['content_type'] == 'html-documents'
307 355
         assert content['content_id'] == 6
@@ -330,7 +378,7 @@ class TestThreads(FunctionalTest):
330 378
         res = self.testapp.get(
331 379
             '/api/v2/workspaces/2/threads/6',
332 380
             status=400
333
-        )   # nopep8
381
+        )
334 382
 
335 383
     def test_api__get_thread__ok_200__nominal_case(self) -> None:
336 384
         """
@@ -373,9 +421,57 @@ class TestThreads(FunctionalTest):
373 421
         assert content['last_modifier']['avatar_url'] is None
374 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 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 476
         self.testapp.authorization = (
381 477
             'Basic',
@@ -447,7 +543,7 @@ class TestThreads(FunctionalTest):
447 543
             self
448 544
     ) -> None:
449 545
         """
450
-        Get one html document of a content
546
+        Get threads revisions
451 547
         """
452 548
         self.testapp.authorization = (
453 549
             'Basic',
@@ -505,7 +601,7 @@ class TestThreads(FunctionalTest):
505 601
 
506 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 606
         self.testapp.authorization = (
511 607
             'Basic',