Code Duplication    Length = 111-111 lines in 2 locations

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

@@ 479-589 (lines=111) @@
476
        assert 'code' in res.json.keys()
477
        assert res.json_body['code'] == error.INSUFFICIENT_USER_PROFILE
478
479
    def test_api__get_recently_active_content__ok__200__limit_2_multiple(self):
480
        # TODO - G.M - 2018-07-20 - Better fix for this test, do not use sleep()
481
        # anymore to fix datetime lack of precision.
482
483
        # init DB
484
        dbsession = get_tm_session(self.session_factory, transaction.manager)
485
        admin = dbsession.query(models.User) \
486
            .filter(models.User.email == '[email protected]') \
487
            .one()
488
        workspace_api = WorkspaceApi(
489
            current_user=admin,
490
            session=dbsession,
491
            config=self.app_config
492
493
        )
494
        workspace = WorkspaceApi(
495
            current_user=admin,
496
            session=dbsession,
497
            config=self.app_config,
498
        ).create_workspace(
499
            'test workspace',
500
            save_now=True
501
        )
502
        workspace2 = WorkspaceApi(
503
            current_user=admin,
504
            session=dbsession,
505
            config=self.app_config,
506
        ).create_workspace(
507
            'test workspace2',
508
            save_now=True
509
        )
510
511
        api = ContentApi(
512
            current_user=admin,
513
            session=dbsession,
514
            config=self.app_config,
515
        )
516
        main_folder_workspace2 = api.create(content_type_list.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
517
        main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
518
        # creation order test
519
        firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
520
        secondly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
521
        # update order test
522
        firstly_created_but_recently_updated = api.create(content_type_list.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
523
        secondly_created_but_not_updated = api.create(content_type_list.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
524
        with new_revision(
525
            session=dbsession,
526
            tm=transaction.manager,
527
            content=firstly_created_but_recently_updated,
528
        ):
529
            firstly_created_but_recently_updated.description = 'Just an update'
530
        api.save(firstly_created_but_recently_updated)
531
        # comment change order
532
        firstly_created_but_recently_commented = api.create(content_type_list.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
533
        secondly_created_but_not_commented = api.create(content_type_list.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
534
        comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
535
        content_workspace_2 = api.create(content_type_list.Page.slug, workspace2, main_folder_workspace2, 'content_workspace_2', '', True)  # nopep8
536
        dbsession.flush()
537
        transaction.commit()
538
539
        self.testapp.authorization = (
540
            'Basic',
541
            (
542
                '[email protected]',
543
                '[email protected]'
544
            )
545
        )
546
        params = {
547
            'limit': 2,
548
        }
549
        res = self.testapp.get(
550
            '/api/v2/users/1/workspaces/{}/contents/recently_active'.format(workspace.workspace_id),  # nopep8
551
            status=200,
552
            params=params
553
        ) # nopep8
554
        res = res.json_body
555
        assert len(res) == 2
556
        for elem in res:
557
            assert isinstance(elem['content_id'], int)
558
            assert isinstance(elem['content_type'], str)
559
            assert elem['content_type'] != 'comments'
560
            assert isinstance(elem['is_archived'], bool)
561
            assert isinstance(elem['is_deleted'], bool)
562
            assert isinstance(elem['label'], str)
563
            assert isinstance(elem['parent_id'], int) or elem['parent_id'] is None
564
            assert isinstance(elem['show_in_ui'], bool)
565
            assert isinstance(elem['slug'], str)
566
            assert isinstance(elem['status'], str)
567
            assert isinstance(elem['sub_content_types'], list)
568
            for sub_content_type in elem['sub_content_types']:
569
                assert isinstance(sub_content_type, str)
570
            assert isinstance(elem['workspace_id'], int)
571
        # comment is newest than page2
572
        assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id
573
        assert res[1]['content_id'] == secondly_created_but_not_commented.content_id
574
575
        params = {
576
            'limit': 2,
577
            'before_content_id': secondly_created_but_not_commented.content_id,  # nopep8
578
        }
579
        res = self.testapp.get(
580
            '/api/v2/users/1/workspaces/{}/contents/recently_active'.format(workspace.workspace_id),  # nopep8
581
            status=200,
582
            params=params
583
        )
584
        res = res.json_body
585
        assert len(res) == 2
586
        # last updated content is newer than other one despite creation
587
        # of the other is more recent
588
        assert res[0]['content_id'] == firstly_created_but_recently_updated.content_id
589
        assert res[1]['content_id'] == secondly_created_but_not_updated.content_id
590
591
    def test_api__get_recently_active_content__err__400__bad_before_content_id(self):  # nopep8
592
        # TODO - G.M - 2018-07-20 - Better fix for this test, do not use sleep()

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

@@ 160-270 (lines=111) @@
157
        # folder subcontent modification does not change folder order
158
        assert res[6]['content_id'] == main_folder.content_id
159
160
    def test_api__get_recently_active_content__ok__200__limit_2_multiple(self):
161
        # TODO - G.M - 2018-07-20 - Better fix for this test, do not use sleep()
162
        # anymore to fix datetime lack of precision.
163
164
        # init DB
165
        dbsession = get_tm_session(self.session_factory, transaction.manager)
166
        admin = dbsession.query(models.User) \
167
            .filter(models.User.email == '[email protected]') \
168
            .one()
169
        workspace_api = WorkspaceApi(
170
            current_user=admin,
171
            session=dbsession,
172
            config=self.app_config
173
174
        )
175
        workspace = WorkspaceApi(
176
            current_user=admin,
177
            session=dbsession,
178
            config=self.app_config,
179
        ).create_workspace(
180
            'test workspace',
181
            save_now=True
182
        )
183
        workspace2 = WorkspaceApi(
184
            current_user=admin,
185
            session=dbsession,
186
            config=self.app_config,
187
        ).create_workspace(
188
            'test workspace2',
189
            save_now=True
190
        )
191
192
        api = ContentApi(
193
            current_user=admin,
194
            session=dbsession,
195
            config=self.app_config,
196
        )
197
        main_folder_workspace2 = api.create(content_type_list.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
198
        main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
199
        # creation order test
200
        firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
201
        secondly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
202
        # update order test
203
        firstly_created_but_recently_updated = api.create(content_type_list.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
204
        secondly_created_but_not_updated = api.create(content_type_list.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
205
        with new_revision(
206
            session=dbsession,
207
            tm=transaction.manager,
208
            content=firstly_created_but_recently_updated,
209
        ):
210
            firstly_created_but_recently_updated.description = 'Just an update'
211
        api.save(firstly_created_but_recently_updated)
212
        # comment change order
213
        firstly_created_but_recently_commented = api.create(content_type_list.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
214
        secondly_created_but_not_commented = api.create(content_type_list.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
215
        comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
216
        content_workspace_2 = api.create(content_type_list.Page.slug, workspace2, main_folder_workspace2, 'content_workspace_2', '', True)  # nopep8
217
        dbsession.flush()
218
        transaction.commit()
219
220
        self.testapp.authorization = (
221
            'Basic',
222
            (
223
                '[email protected]',
224
                '[email protected]'
225
            )
226
        )
227
        params = {
228
            'limit': 2,
229
        }
230
        res = self.testapp.get(
231
            '/api/v2/users/me/workspaces/{}/contents/recently_active'.format(workspace.workspace_id),  # nopep8
232
            status=200,
233
            params=params
234
        ) # nopep8
235
        res = res.json_body
236
        assert len(res) == 2
237
        for elem in res:
238
            assert isinstance(elem['content_id'], int)
239
            assert isinstance(elem['content_type'], str)
240
            assert elem['content_type'] != 'comments'
241
            assert isinstance(elem['is_archived'], bool)
242
            assert isinstance(elem['is_deleted'], bool)
243
            assert isinstance(elem['label'], str)
244
            assert isinstance(elem['parent_id'], int) or elem['parent_id'] is None
245
            assert isinstance(elem['show_in_ui'], bool)
246
            assert isinstance(elem['slug'], str)
247
            assert isinstance(elem['status'], str)
248
            assert isinstance(elem['sub_content_types'], list)
249
            for sub_content_type in elem['sub_content_types']:
250
                assert isinstance(sub_content_type, str)
251
            assert isinstance(elem['workspace_id'], int)
252
        # comment is newest than page2
253
        assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id
254
        assert res[1]['content_id'] == secondly_created_but_not_commented.content_id
255
256
        params = {
257
            'limit': 2,
258
            'before_content_id': secondly_created_but_not_commented.content_id,  # nopep8
259
        }
260
        res = self.testapp.get(
261
            '/api/v2/users/me/workspaces/{}/contents/recently_active'.format(workspace.workspace_id),  # nopep8
262
            status=200,
263
            params=params
264
        )
265
        res = res.json_body
266
        assert len(res) == 2
267
        # last updated content is newer than other one despite creation
268
        # of the other is more recent
269
        assert res[0]['content_id'] == firstly_created_but_recently_updated.content_id
270
        assert res[1]['content_id'] == secondly_created_but_not_updated.content_id
271
272
    def test_api__get_recently_active_content__err__400__bad_before_content_id(self):  # nopep8
273
        # TODO - G.M - 2018-07-20 - Better fix for this test, do not use sleep()