@@ 2778-2854 (lines=77) @@ | ||
2775 | new_image = Image.open(io.BytesIO(res.body)) |
|
2776 | assert 256, 256 == new_image.size |
|
2777 | ||
2778 | def test_api__get_sized_jpeg_revision_preview__ok__200__force_download_case(self) -> None: # nopep8 |
|
2779 | """ |
|
2780 | get 256x256 revision preview of a txt file |
|
2781 | """ |
|
2782 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
2783 | admin = dbsession.query(models.User) \ |
|
2784 | .filter(models.User.email == '[email protected]') \ |
|
2785 | .one() |
|
2786 | workspace_api = WorkspaceApi( |
|
2787 | current_user=admin, |
|
2788 | session=dbsession, |
|
2789 | config=self.app_config |
|
2790 | ) |
|
2791 | content_api = ContentApi( |
|
2792 | current_user=admin, |
|
2793 | session=dbsession, |
|
2794 | config=self.app_config |
|
2795 | ) |
|
2796 | business_workspace = workspace_api.get_one(1) |
|
2797 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
2798 | test_file = content_api.create( |
|
2799 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2800 | workspace=business_workspace, |
|
2801 | parent=tool_folder, |
|
2802 | label='Test file', |
|
2803 | do_save=False, |
|
2804 | do_notify=False, |
|
2805 | ) |
|
2806 | test_file.file_extension = '.txt' |
|
2807 | test_file.depot_file = FileIntent( |
|
2808 | b'Test file', |
|
2809 | 'Test_file.txt', |
|
2810 | 'text/plain', |
|
2811 | ) |
|
2812 | dbsession.flush() |
|
2813 | transaction.commit() |
|
2814 | content_id = int(test_file.content_id) |
|
2815 | revision_id = int(test_file.revision_id) |
|
2816 | image = create_1000px_png_test_image() |
|
2817 | self.testapp.authorization = ( |
|
2818 | 'Basic', |
|
2819 | ( |
|
2820 | '[email protected]', |
|
2821 | '[email protected]' |
|
2822 | ) |
|
2823 | ) |
|
2824 | self.testapp.put( |
|
2825 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
2826 | upload_files=[ |
|
2827 | ('files', image.name, image.getvalue()) |
|
2828 | ], |
|
2829 | status=204, |
|
2830 | ) |
|
2831 | res = self.testapp.get( |
|
2832 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/raw'.format( # nopep8 |
|
2833 | content_id=content_id, |
|
2834 | revision_id=revision_id, |
|
2835 | ), |
|
2836 | status=200 |
|
2837 | ) |
|
2838 | assert res.content_type == 'text/plain' |
|
2839 | params = { |
|
2840 | 'force_download': 1, |
|
2841 | } |
|
2842 | res = self.testapp.get( |
|
2843 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/preview/jpg/256x256'.format( # nopep8 |
|
2844 | content_id=content_id, |
|
2845 | revision_id=revision_id, |
|
2846 | ), |
|
2847 | status=200, |
|
2848 | params=params, |
|
2849 | ) |
|
2850 | assert res.headers['Content-Disposition'] == 'attachment; filename="Test file_page_1_256x256.jpg"' # nopep8 |
|
2851 | assert res.body != image.getvalue() |
|
2852 | assert res.content_type == 'image/jpeg' |
|
2853 | new_image = Image.open(io.BytesIO(res.body)) |
|
2854 | assert 256, 256 == new_image.size |
|
2855 | ||
2856 | def test_api__get_full_pdf_preview__ok__200__nominal_case(self) -> None: |
|
2857 | """ |
|
@@ 2705-2776 (lines=72) @@ | ||
2702 | status=400 |
|
2703 | ) |
|
2704 | ||
2705 | def test_api__get_sized_jpeg_revision_preview__ok__200__nominal_case(self) -> None: # nopep8 |
|
2706 | """ |
|
2707 | get 256x256 revision preview of a txt file |
|
2708 | """ |
|
2709 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
2710 | admin = dbsession.query(models.User) \ |
|
2711 | .filter(models.User.email == '[email protected]') \ |
|
2712 | .one() |
|
2713 | workspace_api = WorkspaceApi( |
|
2714 | current_user=admin, |
|
2715 | session=dbsession, |
|
2716 | config=self.app_config |
|
2717 | ) |
|
2718 | content_api = ContentApi( |
|
2719 | current_user=admin, |
|
2720 | session=dbsession, |
|
2721 | config=self.app_config |
|
2722 | ) |
|
2723 | business_workspace = workspace_api.get_one(1) |
|
2724 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
2725 | test_file = content_api.create( |
|
2726 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2727 | workspace=business_workspace, |
|
2728 | parent=tool_folder, |
|
2729 | label='Test file', |
|
2730 | do_save=False, |
|
2731 | do_notify=False, |
|
2732 | ) |
|
2733 | test_file.file_extension = '.txt' |
|
2734 | test_file.depot_file = FileIntent( |
|
2735 | b'Test file', |
|
2736 | 'Test_file.txt', |
|
2737 | 'text/plain', |
|
2738 | ) |
|
2739 | dbsession.flush() |
|
2740 | transaction.commit() |
|
2741 | content_id = int(test_file.content_id) |
|
2742 | revision_id = int(test_file.revision_id) |
|
2743 | image = create_1000px_png_test_image() |
|
2744 | self.testapp.authorization = ( |
|
2745 | 'Basic', |
|
2746 | ( |
|
2747 | '[email protected]', |
|
2748 | '[email protected]' |
|
2749 | ) |
|
2750 | ) |
|
2751 | self.testapp.put( |
|
2752 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
2753 | upload_files=[ |
|
2754 | ('files', image.name, image.getvalue()) |
|
2755 | ], |
|
2756 | status=204, |
|
2757 | ) |
|
2758 | res = self.testapp.get( |
|
2759 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/raw'.format( # nopep8 |
|
2760 | content_id=content_id, |
|
2761 | revision_id=revision_id, |
|
2762 | ), |
|
2763 | status=200 |
|
2764 | ) |
|
2765 | assert res.content_type == 'text/plain' |
|
2766 | res = self.testapp.get( |
|
2767 | '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/preview/jpg/256x256'.format( # nopep8 |
|
2768 | content_id=content_id, |
|
2769 | revision_id=revision_id, |
|
2770 | ), |
|
2771 | status=200 |
|
2772 | ) |
|
2773 | assert res.body != image.getvalue() |
|
2774 | assert res.content_type == 'image/jpeg' |
|
2775 | new_image = Image.open(io.BytesIO(res.body)) |
|
2776 | assert 256, 256 == new_image.size |
|
2777 | ||
2778 | def test_api__get_sized_jpeg_revision_preview__ok__200__force_download_case(self) -> None: # nopep8 |
|
2779 | """ |