| @@ 2230-2278 (lines=49) @@ | ||
| 2227 | ) |
|
| 2228 | assert res.content_type == 'application/pdf' |
|
| 2229 | ||
| 2230 | def test_api__get_full_pdf_preview__err__400__png_UnavailablePreviewType(self) -> None: # nopep8 |
|
| 2231 | """ |
|
| 2232 | get full pdf preview of a png image -> error UnavailablePreviewType |
|
| 2233 | """ |
|
| 2234 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 2235 | admin = dbsession.query(models.User) \ |
|
| 2236 | .filter(models.User.email == '[email protected]') \ |
|
| 2237 | .one() |
|
| 2238 | workspace_api = WorkspaceApi( |
|
| 2239 | current_user=admin, |
|
| 2240 | session=dbsession, |
|
| 2241 | config=self.app_config |
|
| 2242 | ) |
|
| 2243 | content_api = ContentApi( |
|
| 2244 | current_user=admin, |
|
| 2245 | session=dbsession, |
|
| 2246 | config=self.app_config |
|
| 2247 | ) |
|
| 2248 | business_workspace = workspace_api.get_one(1) |
|
| 2249 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
| 2250 | test_file = content_api.create( |
|
| 2251 | content_type_slug=CONTENT_TYPES.File.slug, |
|
| 2252 | workspace=business_workspace, |
|
| 2253 | parent=tool_folder, |
|
| 2254 | label='Test file', |
|
| 2255 | do_save=True, |
|
| 2256 | do_notify=False, |
|
| 2257 | ) |
|
| 2258 | dbsession.flush() |
|
| 2259 | transaction.commit() |
|
| 2260 | content_id = int(test_file.content_id) |
|
| 2261 | image = create_1000px_png_test_image() |
|
| 2262 | self.testapp.authorization = ( |
|
| 2263 | 'Basic', |
|
| 2264 | ( |
|
| 2265 | '[email protected]', |
|
| 2266 | '[email protected]' |
|
| 2267 | ) |
|
| 2268 | ) |
|
| 2269 | self.testapp.put( |
|
| 2270 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
| 2271 | upload_files=[ |
|
| 2272 | ('files', image.name, image.getvalue()) |
|
| 2273 | ], |
|
| 2274 | status=204, |
|
| 2275 | ) |
|
| 2276 | self.testapp.get( |
|
| 2277 | '/api/v2/workspaces/1/files/{}/preview/pdf/full'.format(content_id), # nopep8 |
|
| 2278 | status=400 |
|
| 2279 | ) |
|
| 2280 | ||
| 2281 | def test_api__get_pdf_preview__ok__200__nominal_case(self) -> None: |
|
| @@ 2043-2091 (lines=49) @@ | ||
| 2040 | new_image = Image.open(io.BytesIO(res.body)) |
|
| 2041 | assert 256, 256 == new_image.size |
|
| 2042 | ||
| 2043 | def test_api__get_sized_jpeg_preview__err__400__SizeNotAllowed(self) -> None: # nopep8 |
|
| 2044 | """ |
|
| 2045 | get 256x256 preview of a txt file |
|
| 2046 | """ |
|
| 2047 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 2048 | admin = dbsession.query(models.User) \ |
|
| 2049 | .filter(models.User.email == '[email protected]') \ |
|
| 2050 | .one() |
|
| 2051 | workspace_api = WorkspaceApi( |
|
| 2052 | current_user=admin, |
|
| 2053 | session=dbsession, |
|
| 2054 | config=self.app_config |
|
| 2055 | ) |
|
| 2056 | content_api = ContentApi( |
|
| 2057 | current_user=admin, |
|
| 2058 | session=dbsession, |
|
| 2059 | config=self.app_config |
|
| 2060 | ) |
|
| 2061 | business_workspace = workspace_api.get_one(1) |
|
| 2062 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
| 2063 | test_file = content_api.create( |
|
| 2064 | content_type_slug=CONTENT_TYPES.File.slug, |
|
| 2065 | workspace=business_workspace, |
|
| 2066 | parent=tool_folder, |
|
| 2067 | label='Test file', |
|
| 2068 | do_save=True, |
|
| 2069 | do_notify=False, |
|
| 2070 | ) |
|
| 2071 | dbsession.flush() |
|
| 2072 | transaction.commit() |
|
| 2073 | content_id = int(test_file.content_id) |
|
| 2074 | image = create_1000px_png_test_image() |
|
| 2075 | self.testapp.authorization = ( |
|
| 2076 | 'Basic', |
|
| 2077 | ( |
|
| 2078 | '[email protected]', |
|
| 2079 | '[email protected]' |
|
| 2080 | ) |
|
| 2081 | ) |
|
| 2082 | self.testapp.put( |
|
| 2083 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
| 2084 | upload_files=[ |
|
| 2085 | ('files', image.name, image.getvalue()) |
|
| 2086 | ], |
|
| 2087 | status=204, |
|
| 2088 | ) |
|
| 2089 | self.testapp.get( |
|
| 2090 | '/api/v2/workspaces/1/files/{}/preview/jpg/512x512'.format(content_id), # nopep8 |
|
| 2091 | status=400 |
|
| 2092 | ) |
|
| 2093 | ||
| 2094 | def test_api__get_sized_jpeg_revision_preview__ok__200__nominal_case(self) -> None: # nopep8 |
|