| @@ 3635-3698 (lines=64) @@ | ||
| 3632 | assert res.body != image.getvalue() |
|
| 3633 | assert res.content_type == 'image/jpeg' |
|
| 3634 | ||
| 3635 | def test_api__get_jpeg_preview__ok__200__force_download_case(self) -> None: |
|
| 3636 | """ |
|
| 3637 | Set one file of a content |
|
| 3638 | """ |
|
| 3639 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 3640 | admin = dbsession.query(models.User) \ |
|
| 3641 | .filter(models.User.email == '[email protected]') \ |
|
| 3642 | .one() |
|
| 3643 | workspace_api = WorkspaceApi( |
|
| 3644 | current_user=admin, |
|
| 3645 | session=dbsession, |
|
| 3646 | config=self.app_config |
|
| 3647 | ) |
|
| 3648 | content_api = ContentApi( |
|
| 3649 | current_user=admin, |
|
| 3650 | session=dbsession, |
|
| 3651 | config=self.app_config |
|
| 3652 | ) |
|
| 3653 | business_workspace = workspace_api.get_one(1) |
|
| 3654 | tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG) |
|
| 3655 | test_file = content_api.create( |
|
| 3656 | content_type_slug=content_type_list.File.slug, |
|
| 3657 | workspace=business_workspace, |
|
| 3658 | parent=tool_folder, |
|
| 3659 | label='Test file', |
|
| 3660 | do_save=False, |
|
| 3661 | do_notify=False, |
|
| 3662 | ) |
|
| 3663 | test_file.file_extension = '.txt' |
|
| 3664 | test_file.depot_file = FileIntent( |
|
| 3665 | b'Test file', |
|
| 3666 | 'Test_file.txt', |
|
| 3667 | 'text/plain', |
|
| 3668 | ) |
|
| 3669 | dbsession.flush() |
|
| 3670 | transaction.commit() |
|
| 3671 | content_id = int(test_file.content_id) |
|
| 3672 | image = create_1000px_png_test_image() |
|
| 3673 | self.testapp.authorization = ( |
|
| 3674 | 'Basic', |
|
| 3675 | ( |
|
| 3676 | '[email protected]', |
|
| 3677 | '[email protected]' |
|
| 3678 | ) |
|
| 3679 | ) |
|
| 3680 | self.testapp.put( |
|
| 3681 | '/api/v2/workspaces/1/files/{}/raw/{}'.format(content_id, image.name), |
|
| 3682 | upload_files=[ |
|
| 3683 | ('files', image.name, image.getvalue()) |
|
| 3684 | ], |
|
| 3685 | status=204, |
|
| 3686 | ) |
|
| 3687 | params = { |
|
| 3688 | 'force_download': 1, |
|
| 3689 | } |
|
| 3690 | res = self.testapp.get( |
|
| 3691 | '/api/v2/workspaces/1/files/{}/preview/jpg/raw'.format(content_id), |
|
| 3692 | status=200, |
|
| 3693 | params=params |
|
| 3694 | ) |
|
| 3695 | filename = 'test_image_page_1.jpg' |
|
| 3696 | assert res.headers['Content-Disposition'] == 'attachment; filename="{}"; filename*=UTF-8\'\'{};'.format(filename, filename) # nopep8 |
|
| 3697 | assert res.body != image.getvalue() |
|
| 3698 | assert res.content_type == 'image/jpeg' |
|
| 3699 | ||
| 3700 | def test_api__get_jpeg_preview__err_400__UnavailablePreview(self) -> None: |
|
| 3701 | """ |
|
| @@ 3999-4058 (lines=60) @@ | ||
| 3996 | new_image = Image.open(io.BytesIO(res.body)) |
|
| 3997 | assert 256, 256 == new_image.size |
|
| 3998 | ||
| 3999 | def test_api__get_sized_jpeg_preview__ok__200__force_download_case_filename_is_raw(self) -> None: |
|
| 4000 | """ |
|
| 4001 | get 256x256 preview of a txt file |
|
| 4002 | """ |
|
| 4003 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4004 | admin = dbsession.query(models.User) \ |
|
| 4005 | .filter(models.User.email == '[email protected]') \ |
|
| 4006 | .one() |
|
| 4007 | workspace_api = WorkspaceApi( |
|
| 4008 | current_user=admin, |
|
| 4009 | session=dbsession, |
|
| 4010 | config=self.app_config |
|
| 4011 | ) |
|
| 4012 | content_api = ContentApi( |
|
| 4013 | current_user=admin, |
|
| 4014 | session=dbsession, |
|
| 4015 | config=self.app_config |
|
| 4016 | ) |
|
| 4017 | business_workspace = workspace_api.get_one(1) |
|
| 4018 | tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG) |
|
| 4019 | test_file = content_api.create( |
|
| 4020 | content_type_slug=content_type_list.File.slug, |
|
| 4021 | workspace=business_workspace, |
|
| 4022 | parent=tool_folder, |
|
| 4023 | label='Test file', |
|
| 4024 | do_save=True, |
|
| 4025 | do_notify=False, |
|
| 4026 | ) |
|
| 4027 | dbsession.flush() |
|
| 4028 | transaction.commit() |
|
| 4029 | content_id = int(test_file.content_id) |
|
| 4030 | image = create_1000px_png_test_image() |
|
| 4031 | self.testapp.authorization = ( |
|
| 4032 | 'Basic', |
|
| 4033 | ( |
|
| 4034 | '[email protected]', |
|
| 4035 | '[email protected]' |
|
| 4036 | ) |
|
| 4037 | ) |
|
| 4038 | self.testapp.put( |
|
| 4039 | '/api/v2/workspaces/1/files/{}/raw/{}'.format(content_id, image.name), |
|
| 4040 | upload_files=[ |
|
| 4041 | ('files', image.name, image.getvalue()) |
|
| 4042 | ], |
|
| 4043 | status=204, |
|
| 4044 | ) |
|
| 4045 | params = { |
|
| 4046 | 'force_download': 1, |
|
| 4047 | } |
|
| 4048 | dl_filename = 'test_image_page_1_256x256.jpg' |
|
| 4049 | res = self.testapp.get( |
|
| 4050 | '/api/v2/workspaces/1/files/{}/preview/jpg/256x256/raw'.format(content_id), # nopep8 |
|
| 4051 | status=200, |
|
| 4052 | params=params, |
|
| 4053 | ) |
|
| 4054 | assert res.body != image.getvalue() |
|
| 4055 | assert res.headers['Content-Disposition'] == 'attachment; filename="{}"; filename*=UTF-8\'\'{};'.format(dl_filename, dl_filename) # nopep8 |
|
| 4056 | assert res.content_type == 'image/jpeg' |
|
| 4057 | new_image = Image.open(io.BytesIO(res.body)) |
|
| 4058 | assert 256, 256 == new_image.size |
|
| 4059 | ||
| 4060 | def test_api__get_sized_jpeg_preview__err__400__SizeNotAllowed(self) -> None: # nopep8 |
|
| 4061 | """ |
|
| @@ 3938-3997 (lines=60) @@ | ||
| 3935 | new_image = Image.open(io.BytesIO(res.body)) |
|
| 3936 | assert 256, 256 == new_image.size |
|
| 3937 | ||
| 3938 | def test_api__get_sized_jpeg_preview__ok__200__force_download_case_no_filename(self) -> None: |
|
| 3939 | """ |
|
| 3940 | get 256x256 preview of a txt file |
|
| 3941 | """ |
|
| 3942 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 3943 | admin = dbsession.query(models.User) \ |
|
| 3944 | .filter(models.User.email == '[email protected]') \ |
|
| 3945 | .one() |
|
| 3946 | workspace_api = WorkspaceApi( |
|
| 3947 | current_user=admin, |
|
| 3948 | session=dbsession, |
|
| 3949 | config=self.app_config |
|
| 3950 | ) |
|
| 3951 | content_api = ContentApi( |
|
| 3952 | current_user=admin, |
|
| 3953 | session=dbsession, |
|
| 3954 | config=self.app_config |
|
| 3955 | ) |
|
| 3956 | business_workspace = workspace_api.get_one(1) |
|
| 3957 | tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG) |
|
| 3958 | test_file = content_api.create( |
|
| 3959 | content_type_slug=content_type_list.File.slug, |
|
| 3960 | workspace=business_workspace, |
|
| 3961 | parent=tool_folder, |
|
| 3962 | label='Test file', |
|
| 3963 | do_save=True, |
|
| 3964 | do_notify=False, |
|
| 3965 | ) |
|
| 3966 | dbsession.flush() |
|
| 3967 | transaction.commit() |
|
| 3968 | content_id = int(test_file.content_id) |
|
| 3969 | image = create_1000px_png_test_image() |
|
| 3970 | self.testapp.authorization = ( |
|
| 3971 | 'Basic', |
|
| 3972 | ( |
|
| 3973 | '[email protected]', |
|
| 3974 | '[email protected]' |
|
| 3975 | ) |
|
| 3976 | ) |
|
| 3977 | self.testapp.put( |
|
| 3978 | '/api/v2/workspaces/1/files/{}/raw/{}'.format(content_id, image.name), |
|
| 3979 | upload_files=[ |
|
| 3980 | ('files', image.name, image.getvalue()) |
|
| 3981 | ], |
|
| 3982 | status=204, |
|
| 3983 | ) |
|
| 3984 | params = { |
|
| 3985 | 'force_download': 1, |
|
| 3986 | } |
|
| 3987 | dl_filename = 'test_image_page_1_256x256.jpg' |
|
| 3988 | res = self.testapp.get( |
|
| 3989 | '/api/v2/workspaces/1/files/{}/preview/jpg/256x256/'.format(content_id), # nopep8 |
|
| 3990 | status=200, |
|
| 3991 | params=params, |
|
| 3992 | ) |
|
| 3993 | assert res.body != image.getvalue() |
|
| 3994 | assert res.headers['Content-Disposition'] == 'attachment; filename="{}"; filename*=UTF-8\'\'{};'.format(dl_filename, dl_filename) # nopep8 |
|
| 3995 | assert res.content_type == 'image/jpeg' |
|
| 3996 | new_image = Image.open(io.BytesIO(res.body)) |
|
| 3997 | assert 256, 256 == new_image.size |
|
| 3998 | ||
| 3999 | def test_api__get_sized_jpeg_preview__ok__200__force_download_case_filename_is_raw(self) -> None: |
|
| 4000 | """ |
|
| @@ 3877-3936 (lines=60) @@ | ||
| 3874 | assert 'code' in res.json.keys() |
|
| 3875 | assert res.json_body['code'] == error.UNAIVALABLE_PREVIEW |
|
| 3876 | ||
| 3877 | def test_api__get_sized_jpeg_preview__ok__200__force_download_case(self) -> None: |
|
| 3878 | """ |
|
| 3879 | get 256x256 preview of a txt file |
|
| 3880 | """ |
|
| 3881 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 3882 | admin = dbsession.query(models.User) \ |
|
| 3883 | .filter(models.User.email == '[email protected]') \ |
|
| 3884 | .one() |
|
| 3885 | workspace_api = WorkspaceApi( |
|
| 3886 | current_user=admin, |
|
| 3887 | session=dbsession, |
|
| 3888 | config=self.app_config |
|
| 3889 | ) |
|
| 3890 | content_api = ContentApi( |
|
| 3891 | current_user=admin, |
|
| 3892 | session=dbsession, |
|
| 3893 | config=self.app_config |
|
| 3894 | ) |
|
| 3895 | business_workspace = workspace_api.get_one(1) |
|
| 3896 | tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG) |
|
| 3897 | test_file = content_api.create( |
|
| 3898 | content_type_slug=content_type_list.File.slug, |
|
| 3899 | workspace=business_workspace, |
|
| 3900 | parent=tool_folder, |
|
| 3901 | label='Test file', |
|
| 3902 | do_save=True, |
|
| 3903 | do_notify=False, |
|
| 3904 | ) |
|
| 3905 | dbsession.flush() |
|
| 3906 | transaction.commit() |
|
| 3907 | content_id = int(test_file.content_id) |
|
| 3908 | image = create_1000px_png_test_image() |
|
| 3909 | self.testapp.authorization = ( |
|
| 3910 | 'Basic', |
|
| 3911 | ( |
|
| 3912 | '[email protected]', |
|
| 3913 | '[email protected]' |
|
| 3914 | ) |
|
| 3915 | ) |
|
| 3916 | self.testapp.put( |
|
| 3917 | '/api/v2/workspaces/1/files/{}/raw/{}'.format(content_id, image.name), |
|
| 3918 | upload_files=[ |
|
| 3919 | ('files', image.name, image.getvalue()) |
|
| 3920 | ], |
|
| 3921 | status=204, |
|
| 3922 | ) |
|
| 3923 | params = { |
|
| 3924 | 'force_download': 1, |
|
| 3925 | } |
|
| 3926 | dl_filename = 'test_image_page_1_256x256.jpg' |
|
| 3927 | res = self.testapp.get( |
|
| 3928 | '/api/v2/workspaces/1/files/{}/preview/jpg/256x256/{}'.format(content_id, dl_filename), # nopep8 |
|
| 3929 | status=200, |
|
| 3930 | params=params, |
|
| 3931 | ) |
|
| 3932 | assert res.body != image.getvalue() |
|
| 3933 | assert res.headers['Content-Disposition'] == 'attachment; filename="{}"; filename*=UTF-8\'\'{};'.format(dl_filename, dl_filename) # nopep8 |
|
| 3934 | assert res.content_type == 'image/jpeg' |
|
| 3935 | new_image = Image.open(io.BytesIO(res.body)) |
|
| 3936 | assert 256, 256 == new_image.size |
|
| 3937 | ||
| 3938 | def test_api__get_sized_jpeg_preview__ok__200__force_download_case_no_filename(self) -> None: |
|
| 3939 | """ |
|