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,8 +1226,7 @@ class TestFiles(FunctionalTest):
1226 1226
         )
1227 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 1231
         Set one file of a content
1233 1232
         """
@@ -1275,9 +1274,8 @@ class TestFiles(FunctionalTest):
1275 1274
         )
1276 1275
         res = self.testapp.get(
1277 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 1281
 class TestThreads(FunctionalTest):

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

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