| @@ 3269-3330 (lines=62) @@ | ||
| 3266 | assert res.content_type == 'application/pdf' |
|
| 3267 | assert res.headers['Content-Disposition'] == 'attachment; filename="Test_file_page_1.pdf"' # nopep8 |
|
| 3268 | ||
| 3269 | def test_api__get_pdf_preview__ok__err__400_page_of_preview_not_found(self) -> None: # nopep8 |
|
| 3270 | """ |
|
| 3271 | get full pdf preview of a txt file |
|
| 3272 | """ |
|
| 3273 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 3274 | admin = dbsession.query(models.User) \ |
|
| 3275 | .filter(models.User.email == '[email protected]') \ |
|
| 3276 | .one() |
|
| 3277 | workspace_api = WorkspaceApi( |
|
| 3278 | current_user=admin, |
|
| 3279 | session=dbsession, |
|
| 3280 | config=self.app_config |
|
| 3281 | ) |
|
| 3282 | content_api = ContentApi( |
|
| 3283 | current_user=admin, |
|
| 3284 | session=dbsession, |
|
| 3285 | config=self.app_config |
|
| 3286 | ) |
|
| 3287 | business_workspace = workspace_api.get_one(1) |
|
| 3288 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
| 3289 | test_file = content_api.create( |
|
| 3290 | content_type_slug=CONTENT_TYPES.File.slug, |
|
| 3291 | workspace=business_workspace, |
|
| 3292 | parent=tool_folder, |
|
| 3293 | label='Test file', |
|
| 3294 | do_save=True, |
|
| 3295 | do_notify=False, |
|
| 3296 | ) |
|
| 3297 | with new_revision( |
|
| 3298 | session=dbsession, |
|
| 3299 | tm=transaction.manager, |
|
| 3300 | content=test_file, |
|
| 3301 | ): |
|
| 3302 | test_file.file_extension = '.txt' |
|
| 3303 | test_file.depot_file = FileIntent( |
|
| 3304 | b'Test file', |
|
| 3305 | 'Test_file.txt', |
|
| 3306 | 'text/plain', |
|
| 3307 | ) |
|
| 3308 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
|
| 3309 | dbsession.flush() |
|
| 3310 | transaction.commit() |
|
| 3311 | content_id = int(test_file.content_id) |
|
| 3312 | self.testapp.authorization = ( |
|
| 3313 | 'Basic', |
|
| 3314 | ( |
|
| 3315 | '[email protected]', |
|
| 3316 | '[email protected]' |
|
| 3317 | ) |
|
| 3318 | ) |
|
| 3319 | self.testapp.put( |
|
| 3320 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
| 3321 | upload_files=[ |
|
| 3322 | ('files', test_file.file_name, test_file.depot_file.file.read()) |
|
| 3323 | ], |
|
| 3324 | status=204, |
|
| 3325 | ) |
|
| 3326 | params = {'page': 2} |
|
| 3327 | self.testapp.get( |
|
| 3328 | '/api/v2/workspaces/1/files/{}/preview/pdf'.format(content_id), |
|
| 3329 | status=400, |
|
| 3330 | params=params, |
|
| 3331 | ) |
|
| 3332 | ||
| 3333 | def test_api__get_pdf_revision_preview__ok__200__nominal_case(self) -> None: |
|
| @@ 2856-2917 (lines=62) @@ | ||
| 2853 | new_image = Image.open(io.BytesIO(res.body)) |
|
| 2854 | assert 256, 256 == new_image.size |
|
| 2855 | ||
| 2856 | def test_api__get_full_pdf_preview__ok__200__nominal_case(self) -> None: |
|
| 2857 | """ |
|
| 2858 | get full pdf preview of a txt file |
|
| 2859 | """ |
|
| 2860 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 2861 | admin = dbsession.query(models.User) \ |
|
| 2862 | .filter(models.User.email == '[email protected]') \ |
|
| 2863 | .one() |
|
| 2864 | workspace_api = WorkspaceApi( |
|
| 2865 | current_user=admin, |
|
| 2866 | session=dbsession, |
|
| 2867 | config=self.app_config |
|
| 2868 | ) |
|
| 2869 | content_api = ContentApi( |
|
| 2870 | current_user=admin, |
|
| 2871 | session=dbsession, |
|
| 2872 | config=self.app_config |
|
| 2873 | ) |
|
| 2874 | business_workspace = workspace_api.get_one(1) |
|
| 2875 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
| 2876 | test_file = content_api.create( |
|
| 2877 | content_type_slug=CONTENT_TYPES.File.slug, |
|
| 2878 | workspace=business_workspace, |
|
| 2879 | parent=tool_folder, |
|
| 2880 | label='Test file', |
|
| 2881 | do_save=True, |
|
| 2882 | do_notify=False, |
|
| 2883 | ) |
|
| 2884 | with new_revision( |
|
| 2885 | session=dbsession, |
|
| 2886 | tm=transaction.manager, |
|
| 2887 | content=test_file, |
|
| 2888 | ): |
|
| 2889 | test_file.file_extension = '.txt' |
|
| 2890 | test_file.depot_file = FileIntent( |
|
| 2891 | b'Test file', |
|
| 2892 | 'Test_file.txt', |
|
| 2893 | 'text/plain', |
|
| 2894 | ) |
|
| 2895 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
|
| 2896 | dbsession.flush() |
|
| 2897 | transaction.commit() |
|
| 2898 | content_id = int(test_file.content_id) |
|
| 2899 | self.testapp.authorization = ( |
|
| 2900 | 'Basic', |
|
| 2901 | ( |
|
| 2902 | '[email protected]', |
|
| 2903 | '[email protected]' |
|
| 2904 | ) |
|
| 2905 | ) |
|
| 2906 | self.testapp.put( |
|
| 2907 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
| 2908 | upload_files=[ |
|
| 2909 | ('files', test_file.file_name, test_file.depot_file.file.read()) |
|
| 2910 | ], |
|
| 2911 | status=204, |
|
| 2912 | ) |
|
| 2913 | res = self.testapp.get( |
|
| 2914 | '/api/v2/workspaces/1/files/{}/preview/pdf/full'.format(content_id), # nopep8 |
|
| 2915 | status=200 |
|
| 2916 | ) |
|
| 2917 | assert res.content_type == 'application/pdf' |
|
| 2918 | ||
| 2919 | def test_api__get_full_pdf_preview__ok__200__force_download_case(self) -> None: |
|
| 2920 | """ |
|