| @@ 4527-4591 (lines=65) @@ | ||
| 4524 | assert 'code' in res.json.keys() |
|
| 4525 | assert res.json_body['code'] == error.UNAIVALABLE_PREVIEW |
|
| 4526 | ||
| 4527 | def test_api__get_pdf_preview__ok__200__nominal_case(self) -> None: |
|
| 4528 | """ |
|
| 4529 | get full pdf preview of a txt file |
|
| 4530 | """ |
|
| 4531 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4532 | admin = dbsession.query(models.User) \ |
|
| 4533 | .filter(models.User.email == '[email protected]') \ |
|
| 4534 | .one() |
|
| 4535 | workspace_api = WorkspaceApi( |
|
| 4536 | current_user=admin, |
|
| 4537 | session=dbsession, |
|
| 4538 | config=self.app_config |
|
| 4539 | ) |
|
| 4540 | content_api = ContentApi( |
|
| 4541 | current_user=admin, |
|
| 4542 | session=dbsession, |
|
| 4543 | config=self.app_config |
|
| 4544 | ) |
|
| 4545 | business_workspace = workspace_api.get_one(1) |
|
| 4546 | tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG) |
|
| 4547 | test_file = content_api.create( |
|
| 4548 | content_type_slug=content_type_list.File.slug, |
|
| 4549 | workspace=business_workspace, |
|
| 4550 | parent=tool_folder, |
|
| 4551 | label='Test file', |
|
| 4552 | do_save=True, |
|
| 4553 | do_notify=False, |
|
| 4554 | ) |
|
| 4555 | with new_revision( |
|
| 4556 | session=dbsession, |
|
| 4557 | tm=transaction.manager, |
|
| 4558 | content=test_file, |
|
| 4559 | ): |
|
| 4560 | test_file.file_extension = '.txt' |
|
| 4561 | test_file.depot_file = FileIntent( |
|
| 4562 | b'Test file', |
|
| 4563 | 'Test_file.txt', |
|
| 4564 | 'text/plain', |
|
| 4565 | ) |
|
| 4566 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
|
| 4567 | dbsession.flush() |
|
| 4568 | transaction.commit() |
|
| 4569 | content_id = int(test_file.content_id) |
|
| 4570 | self.testapp.authorization = ( |
|
| 4571 | 'Basic', |
|
| 4572 | ( |
|
| 4573 | '[email protected]', |
|
| 4574 | '[email protected]' |
|
| 4575 | ) |
|
| 4576 | ) |
|
| 4577 | self.testapp.put( |
|
| 4578 | '/api/v2/workspaces/1/files/{}/raw/{}'.format(content_id, test_file.file_name), |
|
| 4579 | upload_files=[ |
|
| 4580 | ('files', test_file.file_name, test_file.depot_file.file.read()) |
|
| 4581 | ], |
|
| 4582 | status=204, |
|
| 4583 | ) |
|
| 4584 | params = {'page': 1} |
|
| 4585 | filename = 'test_file.pdf' |
|
| 4586 | res = self.testapp.get( |
|
| 4587 | '/api/v2/workspaces/1/files/{}/preview/pdf/{}'.format(content_id, filename), |
|
| 4588 | status=200, |
|
| 4589 | params=params, |
|
| 4590 | ) |
|
| 4591 | assert res.content_type == 'application/pdf' |
|
| 4592 | ||
| 4593 | def test_api__get_pdf_preview_err__400__UnavailablePreview(self) -> None: |
|
| 4594 | """ |
|
| @@ 4273-4335 (lines=63) @@ | ||
| 4270 | new_image = Image.open(io.BytesIO(res.body)) |
|
| 4271 | assert 256, 256 == new_image.size |
|
| 4272 | ||
| 4273 | def test_api__get_full_pdf_preview__ok__200__nominal_case(self) -> None: |
|
| 4274 | """ |
|
| 4275 | get full pdf preview of a txt file |
|
| 4276 | """ |
|
| 4277 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4278 | admin = dbsession.query(models.User) \ |
|
| 4279 | .filter(models.User.email == '[email protected]') \ |
|
| 4280 | .one() |
|
| 4281 | workspace_api = WorkspaceApi( |
|
| 4282 | current_user=admin, |
|
| 4283 | session=dbsession, |
|
| 4284 | config=self.app_config |
|
| 4285 | ) |
|
| 4286 | content_api = ContentApi( |
|
| 4287 | current_user=admin, |
|
| 4288 | session=dbsession, |
|
| 4289 | config=self.app_config |
|
| 4290 | ) |
|
| 4291 | business_workspace = workspace_api.get_one(1) |
|
| 4292 | tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG) |
|
| 4293 | test_file = content_api.create( |
|
| 4294 | content_type_slug=content_type_list.File.slug, |
|
| 4295 | workspace=business_workspace, |
|
| 4296 | parent=tool_folder, |
|
| 4297 | label='Test file', |
|
| 4298 | do_save=True, |
|
| 4299 | do_notify=False, |
|
| 4300 | ) |
|
| 4301 | with new_revision( |
|
| 4302 | session=dbsession, |
|
| 4303 | tm=transaction.manager, |
|
| 4304 | content=test_file, |
|
| 4305 | ): |
|
| 4306 | test_file.file_extension = '.txt' |
|
| 4307 | test_file.depot_file = FileIntent( |
|
| 4308 | b'Test file', |
|
| 4309 | 'Test_file.txt', |
|
| 4310 | 'text/plain', |
|
| 4311 | ) |
|
| 4312 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
|
| 4313 | dbsession.flush() |
|
| 4314 | transaction.commit() |
|
| 4315 | content_id = int(test_file.content_id) |
|
| 4316 | self.testapp.authorization = ( |
|
| 4317 | 'Basic', |
|
| 4318 | ( |
|
| 4319 | '[email protected]', |
|
| 4320 | '[email protected]' |
|
| 4321 | ) |
|
| 4322 | ) |
|
| 4323 | self.testapp.put( |
|
| 4324 | '/api/v2/workspaces/1/files/{}/raw/{}'.format(content_id, test_file.file_name), |
|
| 4325 | upload_files=[ |
|
| 4326 | ('files', test_file.file_name, test_file.depot_file.file.read()) |
|
| 4327 | ], |
|
| 4328 | status=204, |
|
| 4329 | ) |
|
| 4330 | filename = 'test_image.pdf' |
|
| 4331 | res = self.testapp.get( |
|
| 4332 | '/api/v2/workspaces/1/files/{}/preview/pdf/full/{}'.format(content_id, filename), # nopep8 |
|
| 4333 | status=200 |
|
| 4334 | ) |
|
| 4335 | assert res.content_type == 'application/pdf' |
|
| 4336 | ||
| 4337 | def test_api__get_full_pdf_preview__ok__200__force_download_case(self) -> None: |
|
| 4338 | """ |
|