Code Duplication    Length = 75-76 lines in 2 locations

backend/tracim_backend/tests/functional/test_contents.py 2 locations

@@ 4933-5008 (lines=76) @@
4930
        )
4931
        assert res.content_type == 'application/pdf'
4932
4933
    def test_api__get_full_pdf_revision_preview__ok__200__force_download_case(self) -> None:
4934
        """
4935
        get pdf revision preview of content
4936
        """
4937
        dbsession = get_tm_session(self.session_factory, transaction.manager)
4938
        admin = dbsession.query(models.User) \
4939
            .filter(models.User.email == '[email protected]') \
4940
            .one()
4941
        workspace_api = WorkspaceApi(
4942
            current_user=admin,
4943
            session=dbsession,
4944
            config=self.app_config
4945
        )
4946
        content_api = ContentApi(
4947
            current_user=admin,
4948
            session=dbsession,
4949
            config=self.app_config
4950
        )
4951
        business_workspace = workspace_api.get_one(1)
4952
        tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG)
4953
        test_file = content_api.create(
4954
            content_type_slug=content_type_list.File.slug,
4955
            workspace=business_workspace,
4956
            parent=tool_folder,
4957
            label='Test file',
4958
            do_save=False,
4959
            do_notify=False,
4960
        )
4961
        test_file.file_extension = '.txt'
4962
        test_file.depot_file = FileIntent(
4963
            b'Test file',
4964
            'Test_file.txt',
4965
            'text/plain',
4966
        )
4967
        dbsession.flush()
4968
        transaction.commit()
4969
        content_id = int(test_file.content_id)
4970
        revision_id = int(test_file.revision_id)
4971
        image = create_1000px_png_test_image()
4972
        self.testapp.authorization = (
4973
            'Basic',
4974
            (
4975
                '[email protected]',
4976
                '[email protected]'
4977
            )
4978
        )
4979
        self.testapp.put(
4980
            '/api/v2/workspaces/1/files/{}/raw/{}'.format(content_id, image.name),
4981
            upload_files=[
4982
                ('files', image.name, image.getvalue())
4983
            ],
4984
            status=204,
4985
        )
4986
        res = self.testapp.get(
4987
            '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/raw/{filename}'.format(  # nopep8
4988
                content_id=content_id,
4989
                revision_id=revision_id,
4990
                filename=image.name
4991
            ),
4992
            status=200
4993
        )
4994
        assert res.content_type == 'text/plain'
4995
        params = {'force_download': 1}
4996
        filename = 'Test_file.pdf'
4997
        res = self.testapp.get(
4998
            '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/preview/pdf/full/{filename}'.format(  # nopep8
4999
                content_id=content_id,
5000
                revision_id=revision_id,
5001
                filename='Test_file.pdf'
5002
            ),
5003
            status=200,
5004
            params=params,
5005
        )
5006
5007
        assert res.headers['Content-Disposition'] == 'attachment; filename="{}"; filename*=UTF-8\'\'{};'.format(filename, filename)  # nopep8
5008
        assert res.content_type == 'application/pdf'
5009
5010
    def test_api__get_pdf_revision_preview__ok__200__force_download_case(self) -> None:
5011
        """
@@ 5010-5084 (lines=75) @@
5007
        assert res.headers['Content-Disposition'] == 'attachment; filename="{}"; filename*=UTF-8\'\'{};'.format(filename, filename)  # nopep8
5008
        assert res.content_type == 'application/pdf'
5009
5010
    def test_api__get_pdf_revision_preview__ok__200__force_download_case(self) -> None:
5011
        """
5012
        get pdf revision preview of content
5013
        """
5014
        dbsession = get_tm_session(self.session_factory, transaction.manager)
5015
        admin = dbsession.query(models.User) \
5016
            .filter(models.User.email == '[email protected]') \
5017
            .one()
5018
        workspace_api = WorkspaceApi(
5019
            current_user=admin,
5020
            session=dbsession,
5021
            config=self.app_config
5022
        )
5023
        content_api = ContentApi(
5024
            current_user=admin,
5025
            session=dbsession,
5026
            config=self.app_config
5027
        )
5028
        business_workspace = workspace_api.get_one(1)
5029
        tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG)
5030
        test_file = content_api.create(
5031
            content_type_slug=content_type_list.File.slug,
5032
            workspace=business_workspace,
5033
            parent=tool_folder,
5034
            label='Test file',
5035
            do_save=False,
5036
            do_notify=False,
5037
        )
5038
        test_file.file_extension = '.txt'
5039
        test_file.depot_file = FileIntent(
5040
            b'Test file',
5041
            'Test_file.txt',
5042
            'text/plain',
5043
        )
5044
        dbsession.flush()
5045
        transaction.commit()
5046
        content_id = int(test_file.content_id)
5047
        revision_id = int(test_file.revision_id)
5048
        image = create_1000px_png_test_image()
5049
        self.testapp.authorization = (
5050
            'Basic',
5051
            (
5052
                '[email protected]',
5053
                '[email protected]'
5054
            )
5055
        )
5056
        self.testapp.put(
5057
            '/api/v2/workspaces/1/files/{}/raw/{}'.format(content_id, image.name),
5058
            upload_files=[
5059
                ('files', image.name, image.getvalue())
5060
            ],
5061
            status=204,
5062
        )
5063
        res = self.testapp.get(
5064
            '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/raw/{filename}'.format(  # nopep8
5065
                content_id=content_id,
5066
                revision_id=revision_id,
5067
                filename=image.name
5068
            ),
5069
            status=200
5070
        )
5071
        assert res.content_type == 'text/plain'
5072
        params = {'page': 1, 'force_download': 1}
5073
        filename = 'test_image_page_1.pdf'
5074
        res = self.testapp.get(
5075
            '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/preview/pdf/{filename}'.format(  # nopep8
5076
                content_id=content_id,
5077
                revision_id=revision_id,
5078
                filename=filename
5079
            ),
5080
            status=200,
5081
            params=params,
5082
        )
5083
        assert res.headers['Content-Disposition'] == 'attachment; filename="{}"; filename*=UTF-8\'\'{};'.format(filename, filename)  # nopep8
5084
        assert res.content_type == 'application/pdf'
5085
5086
5087
class TestThreads(FunctionalTest):