Code Duplication    Length = 57-61 lines in 4 locations

backend/tracim_backend/tests/functional/test_comments.py 1 location

@@ 138-198 (lines=61) @@
135
        # TODO - G.M - 2018-06-179 - better check for datetime
136
        assert comment['created']
137
138
    def test_api__post_content_comment__err_400__content_not_editable(self) -> None:
139
        """
140
        Get alls comments of a content
141
        """
142
        dbsession = get_tm_session(self.session_factory, transaction.manager)
143
        admin = dbsession.query(models.User) \
144
            .filter(models.User.email == '[email protected]') \
145
            .one() # type: models.User
146
        workspace_api = WorkspaceApi(
147
            current_user=admin,
148
            session=dbsession,
149
            config=self.app_config
150
        )
151
        business_workspace = workspace_api.get_one(1)
152
        content_api = ContentApi(
153
            current_user=admin,
154
            session=dbsession,
155
            config=self.app_config
156
        )
157
        tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG)
158
        test_thread = content_api.create(
159
            content_type_slug=content_type_list.Thread.slug,
160
            workspace=business_workspace,
161
            parent=tool_folder,
162
            label='Test Thread',
163
            do_save=True,
164
            do_notify=False,
165
        )
166
        with new_revision(
167
           session=dbsession,
168
           tm=transaction.manager,
169
           content=test_thread,
170
        ):
171
            content_api.update_content(
172
                test_thread,
173
                new_label='test_thread_updated',
174
                new_content='Just a test'
175
            )
176
        content_api.set_status(test_thread, 'closed-deprecated')
177
        transaction.commit()
178
        self.testapp.authorization = (
179
            'Basic',
180
            (
181
                '[email protected]',
182
                '[email protected]'
183
            )
184
        )
185
        params = {
186
            'raw_content': 'I strongly disagree, Tiramisu win!'
187
        }
188
        res = self.testapp.post_json(
189
            '/api/v2/workspaces/{}/contents/{}/comments'.format(
190
                business_workspace.workspace_id,
191
                test_thread.content_id
192
            ),
193
            params=params,
194
            status=400
195
        )
196
        assert res.json_body
197
        assert 'code' in res.json_body
198
        assert res.json_body['code'] == error.CONTENT_IN_NOT_EDITABLE_STATE
199
200
    def test_api__post_content_comment__err_400__empty_raw_content(self) -> None:
201
        """

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

@@ 3700-3759 (lines=60) @@
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
        """
3702
        Set one file of a content
3703
        """
3704
        dbsession = get_tm_session(self.session_factory, transaction.manager)
3705
        admin = dbsession.query(models.User) \
3706
            .filter(models.User.email == '[email protected]') \
3707
            .one()
3708
        workspace_api = WorkspaceApi(
3709
            current_user=admin,
3710
            session=dbsession,
3711
            config=self.app_config
3712
        )
3713
        content_api = ContentApi(
3714
            current_user=admin,
3715
            session=dbsession,
3716
            config=self.app_config
3717
        )
3718
        business_workspace = workspace_api.get_one(1)
3719
        tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG)
3720
        test_file = content_api.create(
3721
            content_type_slug=content_type_list.File.slug,
3722
            workspace=business_workspace,
3723
            parent=tool_folder,
3724
            label='Test file',
3725
            do_save=False,
3726
            do_notify=False,
3727
        )
3728
        with new_revision(
3729
            session=dbsession,
3730
            tm=transaction.manager,
3731
            content=test_file,
3732
        ):
3733
            content_api.update_file_data(
3734
                test_file,
3735
                'Test_file.bin',
3736
                new_mimetype='application/octet-stream',
3737
                new_content=bytes(100),
3738
            )
3739
        dbsession.flush()
3740
        transaction.commit()
3741
        content_id = int(test_file.content_id)
3742
        self.testapp.authorization = (
3743
            'Basic',
3744
            (
3745
                '[email protected]',
3746
                '[email protected]'
3747
            )
3748
        )
3749
        params = {
3750
            'force_download': 0,
3751
        }
3752
        res = self.testapp.get(
3753
            '/api/v2/workspaces/1/files/{}/preview/jpg/'.format(content_id),
3754
            status=400,
3755
            params=params
3756
        )
3757
        assert isinstance(res.json, dict)
3758
        assert 'code' in res.json.keys()
3759
        assert res.json_body['code'] == error.UNAIVALABLE_PREVIEW
3760
3761
    def test_api__get_sized_jpeg_preview__ok__200__nominal_case(self) -> None:
3762
        """
@@ 4593-4650 (lines=58) @@
4590
        )
4591
        assert res.content_type == 'application/pdf'
4592
4593
    def test_api__get_pdf_preview_err__400__UnavailablePreview(self) -> None:
4594
        """
4595
        get full pdf preview of a txt file
4596
        """
4597
        dbsession = get_tm_session(self.session_factory, transaction.manager)
4598
        admin = dbsession.query(models.User) \
4599
            .filter(models.User.email == '[email protected]') \
4600
            .one()
4601
        workspace_api = WorkspaceApi(
4602
            current_user=admin,
4603
            session=dbsession,
4604
            config=self.app_config
4605
        )
4606
        content_api = ContentApi(
4607
            current_user=admin,
4608
            session=dbsession,
4609
            config=self.app_config
4610
        )
4611
        business_workspace = workspace_api.get_one(1)
4612
        tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG)
4613
        test_file = content_api.create(
4614
            content_type_slug=content_type_list.File.slug,
4615
            workspace=business_workspace,
4616
            parent=tool_folder,
4617
            label='Test file',
4618
            do_save=False,
4619
            do_notify=False,
4620
        )
4621
        with new_revision(
4622
            session=dbsession,
4623
            tm=transaction.manager,
4624
            content=test_file,
4625
        ):
4626
            content_api.update_file_data(
4627
                test_file,
4628
                'Test_file.bin',
4629
                new_mimetype='application/octet-stream',
4630
                new_content=bytes(100),
4631
            )
4632
        dbsession.flush()
4633
        transaction.commit()
4634
        content_id = int(test_file.content_id)
4635
        self.testapp.authorization = (
4636
            'Basic',
4637
            (
4638
                '[email protected]',
4639
                '[email protected]'
4640
            )
4641
        )
4642
        params = {'page': 1}
4643
        res = self.testapp.get(
4644
            '/api/v2/workspaces/1/files/{}/preview/pdf/'.format(content_id),
4645
            status=400,
4646
            params=params,
4647
        )
4648
        assert isinstance(res.json, dict)
4649
        assert 'code' in res.json.keys()
4650
        assert res.json_body['code'] == error.UNAIVALABLE_PREVIEW
4651
4652
    def test_api__get_pdf_preview__ok__200__force_download_case(self) -> None:
4653
        """
@@ 4469-4525 (lines=57) @@
4466
        assert 'code' in res.json_body
4467
        assert res.json_body['code'] == error.UNAVAILABLE_PREVIEW_TYPE
4468
4469
    def test_api__get_full_pdf_preview__err__400__png_UnavailablePreview(self) -> None:  # nopep8
4470
        """
4471
       get full pdf preview of a png image -> error UnavailablePreviewType
4472
        """
4473
        dbsession = get_tm_session(self.session_factory, transaction.manager)
4474
        admin = dbsession.query(models.User) \
4475
            .filter(models.User.email == '[email protected]') \
4476
            .one()
4477
        workspace_api = WorkspaceApi(
4478
            current_user=admin,
4479
            session=dbsession,
4480
            config=self.app_config
4481
        )
4482
        content_api = ContentApi(
4483
            current_user=admin,
4484
            session=dbsession,
4485
            config=self.app_config
4486
        )
4487
        business_workspace = workspace_api.get_one(1)
4488
        tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG)
4489
        test_file = content_api.create(
4490
            content_type_slug=content_type_list.File.slug,
4491
            workspace=business_workspace,
4492
            parent=tool_folder,
4493
            label='Test file',
4494
            do_save=False,
4495
            do_notify=False,
4496
        )
4497
        with new_revision(
4498
            session=dbsession,
4499
            tm=transaction.manager,
4500
            content=test_file,
4501
        ):
4502
            content_api.update_file_data(
4503
                test_file,
4504
                'Test_file.bin',
4505
                new_mimetype='application/octet-stream',
4506
                new_content=bytes(100),
4507
            )
4508
        dbsession.flush()
4509
        content_id = test_file.content_id
4510
        transaction.commit()
4511
        self.testapp.authorization = (
4512
            'Basic',
4513
            (
4514
                '[email protected]',
4515
                '[email protected]'
4516
            )
4517
        )
4518
        filename = 'Test_file.bin'
4519
        res = self.testapp.get(
4520
            '/api/v2/workspaces/1/files/{}/preview/pdf/full/{}'.format(content_id, filename),  # nopep8
4521
            status=400
4522
        )
4523
        assert isinstance(res.json, dict)
4524
        assert 'code' in res.json.keys()
4525
        assert res.json_body['code'] == error.UNAIVALABLE_PREVIEW
4526
4527
    def test_api__get_pdf_preview__ok__200__nominal_case(self) -> None:
4528
        """