| @@ 788-910 (lines=123) @@ | ||
| 785 | # folder subcontent modification does not change folder order |
|
| 786 | assert res[6]['content_id'] == main_folder.content_id |
|
| 787 | ||
| 788 | def test_api__get_read_status__ok__200__user_itself(self): |
|
| 789 | ||
| 790 | # init DB |
|
| 791 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 792 | admin = dbsession.query(models.User) \ |
|
| 793 | .filter(models.User.email == '[email protected]') \ |
|
| 794 | .one() |
|
| 795 | workspace_api = WorkspaceApi( |
|
| 796 | current_user=admin, |
|
| 797 | session=dbsession, |
|
| 798 | config=self.app_config |
|
| 799 | ||
| 800 | ) |
|
| 801 | workspace = WorkspaceApi( |
|
| 802 | current_user=admin, |
|
| 803 | session=dbsession, |
|
| 804 | config=self.app_config, |
|
| 805 | ).create_workspace( |
|
| 806 | 'test workspace', |
|
| 807 | save_now=True |
|
| 808 | ) |
|
| 809 | workspace2 = WorkspaceApi( |
|
| 810 | current_user=admin, |
|
| 811 | session=dbsession, |
|
| 812 | config=self.app_config, |
|
| 813 | ).create_workspace( |
|
| 814 | 'test workspace2', |
|
| 815 | save_now=True |
|
| 816 | ) |
|
| 817 | uapi = UserApi( |
|
| 818 | current_user=admin, |
|
| 819 | session=dbsession, |
|
| 820 | config=self.app_config, |
|
| 821 | ) |
|
| 822 | gapi = GroupApi( |
|
| 823 | current_user=admin, |
|
| 824 | session=dbsession, |
|
| 825 | config=self.app_config, |
|
| 826 | ) |
|
| 827 | groups = [gapi.get_one_with_name('users')] |
|
| 828 | test_user = uapi.create_user( |
|
| 829 | email='[email protected]', |
|
| 830 | password='pass', |
|
| 831 | name='bob', |
|
| 832 | groups=groups, |
|
| 833 | timezone='Europe/Paris', |
|
| 834 | lang='fr', |
|
| 835 | do_save=True, |
|
| 836 | do_notify=False, |
|
| 837 | ) |
|
| 838 | rapi = RoleApi( |
|
| 839 | current_user=admin, |
|
| 840 | session=dbsession, |
|
| 841 | config=self.app_config, |
|
| 842 | ) |
|
| 843 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
| 844 | api = ContentApi( |
|
| 845 | current_user=admin, |
|
| 846 | session=dbsession, |
|
| 847 | config=self.app_config, |
|
| 848 | ) |
|
| 849 | main_folder_workspace2 = api.create(content_type_list.Folder.slug, workspace2, None, 'Hepla', '', True) # nopep8 |
|
| 850 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
| 851 | # creation order test |
|
| 852 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
| 853 | secondly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'another creation_order_test', '', True) # nopep8 |
|
| 854 | # update order test |
|
| 855 | firstly_created_but_recently_updated = api.create(content_type_list.Page.slug, workspace, main_folder, 'update_order_test', '', True) # nopep8 |
|
| 856 | secondly_created_but_not_updated = api.create(content_type_list.Page.slug, workspace, main_folder, 'another update_order_test', '', True) # nopep8 |
|
| 857 | with new_revision( |
|
| 858 | session=dbsession, |
|
| 859 | tm=transaction.manager, |
|
| 860 | content=firstly_created_but_recently_updated, |
|
| 861 | ): |
|
| 862 | firstly_created_but_recently_updated.description = 'Just an update' |
|
| 863 | api.save(firstly_created_but_recently_updated) |
|
| 864 | # comment change order |
|
| 865 | firstly_created_but_recently_commented = api.create(content_type_list.Page.slug, workspace, main_folder, 'this is randomized label content', '', True) # nopep8 |
|
| 866 | secondly_created_but_not_commented = api.create(content_type_list.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8 |
|
| 867 | comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8 |
|
| 868 | content_workspace_2 = api.create(content_type_list.Page.slug, workspace2, main_folder_workspace2, 'content_workspace_2', '', True) # nopep8 |
|
| 869 | dbsession.flush() |
|
| 870 | transaction.commit() |
|
| 871 | ||
| 872 | self.testapp.authorization = ( |
|
| 873 | 'Basic', |
|
| 874 | ( |
|
| 875 | '[email protected]', |
|
| 876 | 'pass' |
|
| 877 | ) |
|
| 878 | ) |
|
| 879 | selected_contents_id = [ |
|
| 880 | firstly_created_but_recently_commented.content_id, |
|
| 881 | firstly_created_but_recently_updated.content_id, |
|
| 882 | firstly_created.content_id, |
|
| 883 | main_folder.content_id, |
|
| 884 | ] |
|
| 885 | url = '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status?contents_ids={cid1}&contents_ids={cid2}&contents_ids={cid3}&contents_ids={cid4}'.format( # nopep8 |
|
| 886 | workspace_id=workspace.workspace_id, |
|
| 887 | cid1=selected_contents_id[0], |
|
| 888 | cid2=selected_contents_id[1], |
|
| 889 | cid3=selected_contents_id[2], |
|
| 890 | cid4=selected_contents_id[3], |
|
| 891 | user_id=test_user.user_id, |
|
| 892 | ) |
|
| 893 | res = self.testapp.get( |
|
| 894 | url=url, |
|
| 895 | status=200, |
|
| 896 | ) |
|
| 897 | res = res.json_body |
|
| 898 | assert len(res) == 4 |
|
| 899 | for elem in res: |
|
| 900 | assert isinstance(elem['content_id'], int) |
|
| 901 | assert isinstance(elem['read_by_user'], bool) |
|
| 902 | # comment is newest than page2 |
|
| 903 | assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id |
|
| 904 | # last updated content is newer than other one despite creation |
|
| 905 | # of the other is more recent |
|
| 906 | assert res[1]['content_id'] == firstly_created_but_recently_updated.content_id |
|
| 907 | # creation order is inverted here as last created is last active |
|
| 908 | assert res[2]['content_id'] == firstly_created.content_id |
|
| 909 | # folder subcontent modification does not change folder order |
|
| 910 | assert res[3]['content_id'] == main_folder.content_id |
|
| 911 | ||
| 912 | def test_api__get_read_status__err__403__other_user(self): |
|
| 913 | ||
| @@ 356-477 (lines=122) @@ | ||
| 353 | """ |
|
| 354 | Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status # nopep8 |
|
| 355 | """ |
|
| 356 | def test_api__get_read_status__ok__200__nominal(self): |
|
| 357 | ||
| 358 | # init DB |
|
| 359 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 360 | admin = dbsession.query(models.User) \ |
|
| 361 | .filter(models.User.email == '[email protected]') \ |
|
| 362 | .one() |
|
| 363 | workspace_api = WorkspaceApi( |
|
| 364 | current_user=admin, |
|
| 365 | session=dbsession, |
|
| 366 | config=self.app_config |
|
| 367 | ||
| 368 | ) |
|
| 369 | workspace = WorkspaceApi( |
|
| 370 | current_user=admin, |
|
| 371 | session=dbsession, |
|
| 372 | config=self.app_config, |
|
| 373 | ).create_workspace( |
|
| 374 | 'test workspace', |
|
| 375 | save_now=True |
|
| 376 | ) |
|
| 377 | workspace2 = WorkspaceApi( |
|
| 378 | current_user=admin, |
|
| 379 | session=dbsession, |
|
| 380 | config=self.app_config, |
|
| 381 | ).create_workspace( |
|
| 382 | 'test workspace2', |
|
| 383 | save_now=True |
|
| 384 | ) |
|
| 385 | uapi = UserApi( |
|
| 386 | current_user=admin, |
|
| 387 | session=dbsession, |
|
| 388 | config=self.app_config, |
|
| 389 | ) |
|
| 390 | gapi = GroupApi( |
|
| 391 | current_user=admin, |
|
| 392 | session=dbsession, |
|
| 393 | config=self.app_config, |
|
| 394 | ) |
|
| 395 | groups = [gapi.get_one_with_name('users')] |
|
| 396 | test_user = uapi.create_user( |
|
| 397 | email='[email protected]', |
|
| 398 | password='pass', |
|
| 399 | name='bob', |
|
| 400 | groups=groups, |
|
| 401 | timezone='Europe/Paris', |
|
| 402 | lang='fr', |
|
| 403 | do_save=True, |
|
| 404 | do_notify=False, |
|
| 405 | ) |
|
| 406 | rapi = RoleApi( |
|
| 407 | current_user=admin, |
|
| 408 | session=dbsession, |
|
| 409 | config=self.app_config, |
|
| 410 | ) |
|
| 411 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
| 412 | api = ContentApi( |
|
| 413 | current_user=admin, |
|
| 414 | session=dbsession, |
|
| 415 | config=self.app_config, |
|
| 416 | ) |
|
| 417 | main_folder_workspace2 = api.create(content_type_list.Folder.slug, workspace2, None, 'Hepla', '', True) # nopep8 |
|
| 418 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
| 419 | # creation order test |
|
| 420 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
| 421 | secondly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'another creation_order_test', '', True) # nopep8 |
|
| 422 | # update order test |
|
| 423 | firstly_created_but_recently_updated = api.create(content_type_list.Page.slug, workspace, main_folder, 'update_order_test', '', True) # nopep8 |
|
| 424 | secondly_created_but_not_updated = api.create(content_type_list.Page.slug, workspace, main_folder, 'another update_order_test', '', True) # nopep8 |
|
| 425 | with new_revision( |
|
| 426 | session=dbsession, |
|
| 427 | tm=transaction.manager, |
|
| 428 | content=firstly_created_but_recently_updated, |
|
| 429 | ): |
|
| 430 | firstly_created_but_recently_updated.description = 'Just an update' |
|
| 431 | api.save(firstly_created_but_recently_updated) |
|
| 432 | # comment change order |
|
| 433 | firstly_created_but_recently_commented = api.create(content_type_list.Page.slug, workspace, main_folder, 'this is randomized label content', '', True) # nopep8 |
|
| 434 | secondly_created_but_not_commented = api.create(content_type_list.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8 |
|
| 435 | comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8 |
|
| 436 | content_workspace_2 = api.create(content_type_list.Page.slug, workspace2, main_folder_workspace2, 'content_workspace_2', '', True) # nopep8 |
|
| 437 | dbsession.flush() |
|
| 438 | transaction.commit() |
|
| 439 | ||
| 440 | self.testapp.authorization = ( |
|
| 441 | 'Basic', |
|
| 442 | ( |
|
| 443 | '[email protected]', |
|
| 444 | 'pass' |
|
| 445 | ) |
|
| 446 | ) |
|
| 447 | selected_contents_id = [ |
|
| 448 | firstly_created_but_recently_commented.content_id, |
|
| 449 | firstly_created_but_recently_updated.content_id, |
|
| 450 | firstly_created.content_id, |
|
| 451 | main_folder.content_id, |
|
| 452 | ] |
|
| 453 | url = '/api/v2/users/me/workspaces/{workspace_id}/contents/read_status?contents_ids={cid1}&contents_ids={cid2}&contents_ids={cid3}&contents_ids={cid4}'.format( # nopep8 |
|
| 454 | workspace_id=workspace.workspace_id, |
|
| 455 | cid1=selected_contents_id[0], |
|
| 456 | cid2=selected_contents_id[1], |
|
| 457 | cid3=selected_contents_id[2], |
|
| 458 | cid4=selected_contents_id[3], |
|
| 459 | ) |
|
| 460 | res = self.testapp.get( |
|
| 461 | url=url, |
|
| 462 | status=200, |
|
| 463 | ) |
|
| 464 | res = res.json_body |
|
| 465 | assert len(res) == 4 |
|
| 466 | for elem in res: |
|
| 467 | assert isinstance(elem['content_id'], int) |
|
| 468 | assert isinstance(elem['read_by_user'], bool) |
|
| 469 | # comment is newest than page2 |
|
| 470 | assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id |
|
| 471 | # last updated content is newer than other one despite creation |
|
| 472 | # of the other is more recent |
|
| 473 | assert res[1]['content_id'] == firstly_created_but_recently_updated.content_id |
|
| 474 | # creation order is inverted here as last created is last active |
|
| 475 | assert res[2]['content_id'] == firstly_created.content_id |
|
| 476 | # folder subcontent modification does not change folder order |
|
| 477 | assert res[3]['content_id'] == main_folder.content_id |
|
| 478 | ||
| 479 | ||
| 480 | class TestUserSetContentAsRead(FunctionalTest): |
|