@@ 2428-2489 (lines=62) @@ | ||
2425 | ) |
|
2426 | assert res.content_type == 'application/pdf' |
|
2427 | ||
2428 | def test_api__get_pdf_preview__ok__err__400_page_of_preview_not_found(self) -> None: # nopep8 |
|
2429 | """ |
|
2430 | get full pdf preview of a txt file |
|
2431 | """ |
|
2432 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
2433 | admin = dbsession.query(models.User) \ |
|
2434 | .filter(models.User.email == '[email protected]') \ |
|
2435 | .one() |
|
2436 | workspace_api = WorkspaceApi( |
|
2437 | current_user=admin, |
|
2438 | session=dbsession, |
|
2439 | config=self.app_config |
|
2440 | ) |
|
2441 | content_api = ContentApi( |
|
2442 | current_user=admin, |
|
2443 | session=dbsession, |
|
2444 | config=self.app_config |
|
2445 | ) |
|
2446 | business_workspace = workspace_api.get_one(1) |
|
2447 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
2448 | test_file = content_api.create( |
|
2449 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2450 | workspace=business_workspace, |
|
2451 | parent=tool_folder, |
|
2452 | label='Test file', |
|
2453 | do_save=True, |
|
2454 | do_notify=False, |
|
2455 | ) |
|
2456 | with new_revision( |
|
2457 | session=dbsession, |
|
2458 | tm=transaction.manager, |
|
2459 | content=test_file, |
|
2460 | ): |
|
2461 | test_file.file_extension = '.txt' |
|
2462 | test_file.depot_file = FileIntent( |
|
2463 | b'Test file', |
|
2464 | 'Test_file.txt', |
|
2465 | 'text/plain', |
|
2466 | ) |
|
2467 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
|
2468 | dbsession.flush() |
|
2469 | transaction.commit() |
|
2470 | content_id = int(test_file.content_id) |
|
2471 | self.testapp.authorization = ( |
|
2472 | 'Basic', |
|
2473 | ( |
|
2474 | '[email protected]', |
|
2475 | '[email protected]' |
|
2476 | ) |
|
2477 | ) |
|
2478 | self.testapp.put( |
|
2479 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
2480 | upload_files=[ |
|
2481 | ('files', test_file.file_name, test_file.depot_file.file.read()) |
|
2482 | ], |
|
2483 | status=204, |
|
2484 | ) |
|
2485 | params = {'page': 1} |
|
2486 | self.testapp.get( |
|
2487 | '/api/v2/workspaces/1/files/{}/preview/pdf'.format(content_id), |
|
2488 | status=400, |
|
2489 | params=params, |
|
2490 | ) |
|
2491 | ||
2492 | def test_api__get_pdf_revision_preview__ok__200__nominal_case(self) -> None: |
|
@@ 2249-2310 (lines=62) @@ | ||
2246 | new_image = Image.open(io.BytesIO(res.body)) |
|
2247 | assert 256, 256 == new_image.size |
|
2248 | ||
2249 | def test_api__get_full_pdf_preview__ok__200__nominal_case(self) -> None: |
|
2250 | """ |
|
2251 | get full pdf preview of a txt file |
|
2252 | """ |
|
2253 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
2254 | admin = dbsession.query(models.User) \ |
|
2255 | .filter(models.User.email == '[email protected]') \ |
|
2256 | .one() |
|
2257 | workspace_api = WorkspaceApi( |
|
2258 | current_user=admin, |
|
2259 | session=dbsession, |
|
2260 | config=self.app_config |
|
2261 | ) |
|
2262 | content_api = ContentApi( |
|
2263 | current_user=admin, |
|
2264 | session=dbsession, |
|
2265 | config=self.app_config |
|
2266 | ) |
|
2267 | business_workspace = workspace_api.get_one(1) |
|
2268 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
2269 | test_file = content_api.create( |
|
2270 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2271 | workspace=business_workspace, |
|
2272 | parent=tool_folder, |
|
2273 | label='Test file', |
|
2274 | do_save=True, |
|
2275 | do_notify=False, |
|
2276 | ) |
|
2277 | with new_revision( |
|
2278 | session=dbsession, |
|
2279 | tm=transaction.manager, |
|
2280 | content=test_file, |
|
2281 | ): |
|
2282 | test_file.file_extension = '.txt' |
|
2283 | test_file.depot_file = FileIntent( |
|
2284 | b'Test file', |
|
2285 | 'Test_file.txt', |
|
2286 | 'text/plain', |
|
2287 | ) |
|
2288 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
|
2289 | dbsession.flush() |
|
2290 | transaction.commit() |
|
2291 | content_id = int(test_file.content_id) |
|
2292 | self.testapp.authorization = ( |
|
2293 | 'Basic', |
|
2294 | ( |
|
2295 | '[email protected]', |
|
2296 | '[email protected]' |
|
2297 | ) |
|
2298 | ) |
|
2299 | self.testapp.put( |
|
2300 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
2301 | upload_files=[ |
|
2302 | ('files', test_file.file_name, test_file.depot_file.file.read()) |
|
2303 | ], |
|
2304 | status=204, |
|
2305 | ) |
|
2306 | res = self.testapp.get( |
|
2307 | '/api/v2/workspaces/1/files/{}/preview/pdf/full'.format(content_id), # nopep8 |
|
2308 | status=200 |
|
2309 | ) |
|
2310 | assert res.content_type == 'application/pdf' |
|
2311 | ||
2312 | def test_api__get_full_pdf_preview__err__400__png_UnavailablePreviewType(self) -> None: # nopep8 |
|
2313 | """ |