Browse Source

fix UnavailablePreviewType test

Guénaël Muller 6 years ago
parent
commit
14ef5c264f

+ 2 - 4
tracim/tests/functional/test_contents.py View File

1226
         )
1226
         )
1227
         assert res.content_type == 'application/pdf'
1227
         assert res.content_type == 'application/pdf'
1228
 
1228
 
1229
-    @pytest.mark.xfail(reason='TODO')
1230
-    def test_api__get_full_pdf_preview__err__400__jpg_UnavailablePreviewType(self) -> None:
1229
+    def test_api__get_full_pdf_preview__err__400__png_UnavailablePreviewType(self) -> None:
1231
         """
1230
         """
1232
         Set one file of a content
1231
         Set one file of a content
1233
         """
1232
         """
1275
         )
1274
         )
1276
         res = self.testapp.get(
1275
         res = self.testapp.get(
1277
             '/api/v2/workspaces/1/files/{}/preview/pdf/full'.format(content_id), # nopep8
1276
             '/api/v2/workspaces/1/files/{}/preview/pdf/full'.format(content_id), # nopep8
1278
-            status=200
1277
+            status=400
1279
         )
1278
         )
1280
-        assert res.content_type == ''
1281
 
1279
 
1282
 
1280
 
1283
 class TestThreads(FunctionalTest):
1281
 class TestThreads(FunctionalTest):

+ 4 - 0
tracim/views/contents_api/file_controller.py View File

4
 import transaction
4
 import transaction
5
 from depot.io.local import LocalStoredFile
5
 from depot.io.local import LocalStoredFile
6
 from depot.manager import DepotManager
6
 from depot.manager import DepotManager
7
+from preview_generator.exception import UnavailablePreviewType
7
 from pyramid.config import Configurator
8
 from pyramid.config import Configurator
8
 from pyramid.response import FileResponse, FileIter
9
 from pyramid.response import FileResponse, FileIter
9
 
10
 
129
     @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
130
     @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
130
     @require_workspace_role(UserRoleInWorkspace.READER)
131
     @require_workspace_role(UserRoleInWorkspace.READER)
131
     @require_content_types([file_type])
132
     @require_content_types([file_type])
133
+    @hapic.handle_exception(UnavailablePreviewType, HTTPStatus.BAD_REQUEST)
132
     @hapic.input_query(PageQuerySchema())
134
     @hapic.input_query(PageQuerySchema())
133
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
135
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
134
     @hapic.output_file([])
136
     @hapic.output_file([])
156
     @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
158
     @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
157
     @require_workspace_role(UserRoleInWorkspace.READER)
159
     @require_workspace_role(UserRoleInWorkspace.READER)
158
     @require_content_types([file_type])
160
     @require_content_types([file_type])
161
+    @hapic.handle_exception(UnavailablePreviewType, HTTPStatus.BAD_REQUEST)
159
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
162
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
160
     @hapic.output_file([])
163
     @hapic.output_file([])
161
     def preview_pdf_full(self, context, request: TracimRequest, hapic_data=None):
164
     def preview_pdf_full(self, context, request: TracimRequest, hapic_data=None):
177
     @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
180
     @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
178
     @require_workspace_role(UserRoleInWorkspace.READER)
181
     @require_workspace_role(UserRoleInWorkspace.READER)
179
     @require_content_types([file_type])
182
     @require_content_types([file_type])
183
+    @hapic.handle_exception(UnavailablePreviewType, HTTPStatus.BAD_REQUEST)
180
     @hapic.input_path(WorkspaceAndContentRevisionIdPathSchema())
184
     @hapic.input_path(WorkspaceAndContentRevisionIdPathSchema())
181
     @hapic.input_query(PageQuerySchema())
185
     @hapic.input_query(PageQuerySchema())
182
     @hapic.output_file([])
186
     @hapic.output_file([])