@@ 3548-3619 (lines=72) @@ | ||
3545 | assert res.headers['Content-Disposition'] == 'attachment; filename="Test file.pdf"' # nopep8 |
|
3546 | assert res.content_type == 'application/pdf' |
|
3547 | ||
3548 | def test_api__get_pdf_revision_preview__ok__200__force_download_case(self) -> None: |
|
3549 | """ |
|
3550 | get pdf revision preview of content |
|
3551 | """ |
|
3552 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
3553 | admin = dbsession.query(models.User) \ |
|
3554 | .filter(models.User.email == '[email protected]') \ |
|
3555 | .one() |
|
3556 | workspace_api = WorkspaceApi( |
|
3557 | current_user=admin, |
|
3558 | session=dbsession, |
|
3559 | config=self.app_config |
|
3560 | ) |
|
3561 | content_api = ContentApi( |
|
3562 | current_user=admin, |
|
3563 | session=dbsession, |
|
3564 | config=self.app_config |
|
3565 | ) |
|
3566 | business_workspace = workspace_api.get_one(1) |
|
3567 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
3568 | test_file = content_api.create( |
|
3569 | content_type_slug=CONTENT_TYPES.File.slug, |
|
3570 | workspace=business_workspace, |
|
3571 | parent=tool_folder, |
|
3572 | label='Test file', |
|
3573 | do_save=False, |
|
3574 | do_notify=False, |
|
3575 | ) |
|
3576 | test_file.file_extension = '.txt' |
|
3577 | test_file.depot_file = FileIntent( |
|
3578 | b'Test file', |
|
3579 | 'Test_file.txt', |
|
3580 | 'text/plain', |
|
3581 | ) |
|
3582 | dbsession.flush() |
|
3583 | transaction.commit() |
|
3584 | content_id = int(test_file.content_id) |
|
3585 | revision_id = int(test_file.revision_id) |
|
3586 | image = create_1000px_png_test_image() |
|
3587 | self.testapp.authorization = ( |
|
3588 | 'Basic', |
|
3589 | ( |
|
3590 | '[email protected]', |
|
3591 | '[email protected]' |
|
3592 | ) |
|
3593 | ) |
|
3594 | self.testapp.put( |
|
3595 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
3596 | upload_files=[ |
|
3597 | ('files', image.name, image.getvalue()) |
|
3598 | ], |
|
3599 | status=204, |
|
3600 | ) |
|
3601 | res = self.testapp.get( |
|
3602 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/raw'.format( # nopep8 |
|
3603 | content_id=content_id, |
|
3604 | revision_id=revision_id, |
|
3605 | ), |
|
3606 | status=200 |
|
3607 | ) |
|
3608 | assert res.content_type == 'text/plain' |
|
3609 | params = {'page': 1, 'force_download': 1} |
|
3610 | res = self.testapp.get( |
|
3611 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/preview/pdf'.format( # nopep8 |
|
3612 | content_id=content_id, |
|
3613 | revision_id=revision_id, |
|
3614 | ), |
|
3615 | status=200, |
|
3616 | params=params, |
|
3617 | ) |
|
3618 | assert res.headers['Content-Disposition'] == 'attachment; filename="test_image_page_1.pdf"' # nopep8 |
|
3619 | assert res.content_type == 'application/pdf' |
|
3620 | ||
3621 | ||
3622 | class TestThreads(FunctionalTest): |
|
@@ 3475-3546 (lines=72) @@ | ||
3472 | ) |
|
3473 | assert res.content_type == 'application/pdf' |
|
3474 | ||
3475 | def test_api__get_full_pdf_revision_preview__ok__200__force_download_case(self) -> None: |
|
3476 | """ |
|
3477 | get pdf revision preview of content |
|
3478 | """ |
|
3479 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
3480 | admin = dbsession.query(models.User) \ |
|
3481 | .filter(models.User.email == '[email protected]') \ |
|
3482 | .one() |
|
3483 | workspace_api = WorkspaceApi( |
|
3484 | current_user=admin, |
|
3485 | session=dbsession, |
|
3486 | config=self.app_config |
|
3487 | ) |
|
3488 | content_api = ContentApi( |
|
3489 | current_user=admin, |
|
3490 | session=dbsession, |
|
3491 | config=self.app_config |
|
3492 | ) |
|
3493 | business_workspace = workspace_api.get_one(1) |
|
3494 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
3495 | test_file = content_api.create( |
|
3496 | content_type_slug=CONTENT_TYPES.File.slug, |
|
3497 | workspace=business_workspace, |
|
3498 | parent=tool_folder, |
|
3499 | label='Test file', |
|
3500 | do_save=False, |
|
3501 | do_notify=False, |
|
3502 | ) |
|
3503 | test_file.file_extension = '.txt' |
|
3504 | test_file.depot_file = FileIntent( |
|
3505 | b'Test file', |
|
3506 | 'Test_file.txt', |
|
3507 | 'text/plain', |
|
3508 | ) |
|
3509 | dbsession.flush() |
|
3510 | transaction.commit() |
|
3511 | content_id = int(test_file.content_id) |
|
3512 | revision_id = int(test_file.revision_id) |
|
3513 | image = create_1000px_png_test_image() |
|
3514 | self.testapp.authorization = ( |
|
3515 | 'Basic', |
|
3516 | ( |
|
3517 | '[email protected]', |
|
3518 | '[email protected]' |
|
3519 | ) |
|
3520 | ) |
|
3521 | self.testapp.put( |
|
3522 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
3523 | upload_files=[ |
|
3524 | ('files', image.name, image.getvalue()) |
|
3525 | ], |
|
3526 | status=204, |
|
3527 | ) |
|
3528 | res = self.testapp.get( |
|
3529 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/raw'.format( # nopep8 |
|
3530 | content_id=content_id, |
|
3531 | revision_id=revision_id, |
|
3532 | ), |
|
3533 | status=200 |
|
3534 | ) |
|
3535 | assert res.content_type == 'text/plain' |
|
3536 | params = {'force_download': 1} |
|
3537 | res = self.testapp.get( |
|
3538 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/preview/pdf/full'.format( # nopep8 |
|
3539 | content_id=content_id, |
|
3540 | revision_id=revision_id, |
|
3541 | ), |
|
3542 | status=200, |
|
3543 | params=params, |
|
3544 | ) |
|
3545 | assert res.headers['Content-Disposition'] == 'attachment; filename="Test file.pdf"' # nopep8 |
|
3546 | assert res.content_type == 'application/pdf' |
|
3547 | ||
3548 | def test_api__get_pdf_revision_preview__ok__200__force_download_case(self) -> None: |
|
3549 | """ |