@@ 1589-1697 (lines=109) @@ | ||
1586 | """ |
|
1587 | Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/unread # nopep8 |
|
1588 | """ |
|
1589 | def test_api_set_content_as_unread__ok__200__admin(self): |
|
1590 | # init DB |
|
1591 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1592 | admin = dbsession.query(models.User) \ |
|
1593 | .filter(models.User.email == '[email protected]') \ |
|
1594 | .one() |
|
1595 | workspace_api = WorkspaceApi( |
|
1596 | current_user=admin, |
|
1597 | session=dbsession, |
|
1598 | config=self.app_config |
|
1599 | ||
1600 | ) |
|
1601 | workspace = WorkspaceApi( |
|
1602 | current_user=admin, |
|
1603 | session=dbsession, |
|
1604 | config=self.app_config, |
|
1605 | ).create_workspace( |
|
1606 | 'test workspace', |
|
1607 | save_now=True |
|
1608 | ) |
|
1609 | uapi = UserApi( |
|
1610 | current_user=admin, |
|
1611 | session=dbsession, |
|
1612 | config=self.app_config, |
|
1613 | ) |
|
1614 | gapi = GroupApi( |
|
1615 | current_user=admin, |
|
1616 | session=dbsession, |
|
1617 | config=self.app_config, |
|
1618 | ) |
|
1619 | groups = [gapi.get_one_with_name('users')] |
|
1620 | test_user = uapi.create_user( |
|
1621 | email='[email protected]', |
|
1622 | password='pass', |
|
1623 | name='bob', |
|
1624 | groups=groups, |
|
1625 | timezone='Europe/Paris', |
|
1626 | lang='fr', |
|
1627 | do_save=True, |
|
1628 | do_notify=False, |
|
1629 | ) |
|
1630 | rapi = RoleApi( |
|
1631 | current_user=admin, |
|
1632 | session=dbsession, |
|
1633 | config=self.app_config, |
|
1634 | ) |
|
1635 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
1636 | api = ContentApi( |
|
1637 | current_user=admin, |
|
1638 | session=dbsession, |
|
1639 | config=self.app_config, |
|
1640 | ) |
|
1641 | api2 = ContentApi( |
|
1642 | current_user=test_user, |
|
1643 | session=dbsession, |
|
1644 | config=self.app_config, |
|
1645 | ) |
|
1646 | main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
1647 | # creation order test |
|
1648 | firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
1649 | api.mark_read(firstly_created) |
|
1650 | api2.mark_read(firstly_created) |
|
1651 | dbsession.flush() |
|
1652 | transaction.commit() |
|
1653 | ||
1654 | self.testapp.authorization = ( |
|
1655 | 'Basic', |
|
1656 | ( |
|
1657 | '[email protected]', |
|
1658 | '[email protected]' |
|
1659 | ) |
|
1660 | ) |
|
1661 | # before |
|
1662 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1663 | user_id=test_user.user_id, |
|
1664 | workspace_id=workspace.workspace_id |
|
1665 | ), status=200) |
|
1666 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1667 | assert res.json_body[0]['read_by_user'] is True |
|
1668 | ||
1669 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1670 | user_id=admin.user_id, |
|
1671 | workspace_id=workspace.workspace_id |
|
1672 | ), status=200) |
|
1673 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1674 | assert res.json_body[0]['read_by_user'] is True |
|
1675 | ||
1676 | # unread |
|
1677 | self.testapp.put( |
|
1678 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/unread'.format( # nopep8 |
|
1679 | workspace_id=workspace.workspace_id, |
|
1680 | content_id=firstly_created.content_id, |
|
1681 | user_id=test_user.user_id, |
|
1682 | ) |
|
1683 | ) |
|
1684 | # after |
|
1685 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1686 | user_id=test_user.user_id, |
|
1687 | workspace_id=workspace.workspace_id |
|
1688 | ), status=200) |
|
1689 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1690 | assert res.json_body[0]['read_by_user'] is False |
|
1691 | ||
1692 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1693 | user_id=admin.user_id, |
|
1694 | workspace_id=workspace.workspace_id |
|
1695 | ), status=200) |
|
1696 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1697 | assert res.json_body[0]['read_by_user'] is True |
|
1698 | ||
1699 | def test_api_set_content_as_unread__err__400__admin_workspace_do_not_exist(self): |
|
1700 | # init DB |
|
@@ 1017-1123 (lines=107) @@ | ||
1014 | """ |
|
1015 | Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/read # nopep8 |
|
1016 | """ |
|
1017 | def test_api_set_content_as_read__ok__200__admin(self): |
|
1018 | # init DB |
|
1019 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1020 | admin = dbsession.query(models.User) \ |
|
1021 | .filter(models.User.email == '[email protected]') \ |
|
1022 | .one() |
|
1023 | workspace_api = WorkspaceApi( |
|
1024 | current_user=admin, |
|
1025 | session=dbsession, |
|
1026 | config=self.app_config |
|
1027 | ||
1028 | ) |
|
1029 | workspace = WorkspaceApi( |
|
1030 | current_user=admin, |
|
1031 | session=dbsession, |
|
1032 | config=self.app_config, |
|
1033 | ).create_workspace( |
|
1034 | 'test workspace', |
|
1035 | save_now=True |
|
1036 | ) |
|
1037 | uapi = UserApi( |
|
1038 | current_user=admin, |
|
1039 | session=dbsession, |
|
1040 | config=self.app_config, |
|
1041 | ) |
|
1042 | gapi = GroupApi( |
|
1043 | current_user=admin, |
|
1044 | session=dbsession, |
|
1045 | config=self.app_config, |
|
1046 | ) |
|
1047 | groups = [gapi.get_one_with_name('users')] |
|
1048 | test_user = uapi.create_user( |
|
1049 | email='[email protected]', |
|
1050 | password='pass', |
|
1051 | name='bob', |
|
1052 | groups=groups, |
|
1053 | timezone='Europe/Paris', |
|
1054 | do_save=True, |
|
1055 | do_notify=False, |
|
1056 | ) |
|
1057 | rapi = RoleApi( |
|
1058 | current_user=admin, |
|
1059 | session=dbsession, |
|
1060 | config=self.app_config, |
|
1061 | ) |
|
1062 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
1063 | api = ContentApi( |
|
1064 | current_user=admin, |
|
1065 | session=dbsession, |
|
1066 | config=self.app_config, |
|
1067 | ) |
|
1068 | api2 = ContentApi( |
|
1069 | current_user=test_user, |
|
1070 | session=dbsession, |
|
1071 | config=self.app_config, |
|
1072 | ) |
|
1073 | main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
1074 | # creation order test |
|
1075 | firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
1076 | api.mark_unread(firstly_created) |
|
1077 | api2.mark_unread(firstly_created) |
|
1078 | dbsession.flush() |
|
1079 | transaction.commit() |
|
1080 | ||
1081 | self.testapp.authorization = ( |
|
1082 | 'Basic', |
|
1083 | ( |
|
1084 | '[email protected]', |
|
1085 | '[email protected]' |
|
1086 | ) |
|
1087 | ) |
|
1088 | # before |
|
1089 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1090 | user_id=test_user.user_id, |
|
1091 | workspace_id=workspace.workspace_id |
|
1092 | ), status=200) |
|
1093 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1094 | assert res.json_body[0]['read_by_user'] is False |
|
1095 | ||
1096 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1097 | user_id=admin.user_id, |
|
1098 | workspace_id=workspace.workspace_id |
|
1099 | ), status=200) |
|
1100 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1101 | assert res.json_body[0]['read_by_user'] is False |
|
1102 | # read |
|
1103 | self.testapp.put( |
|
1104 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/read'.format( # nopep8 |
|
1105 | workspace_id=workspace.workspace_id, |
|
1106 | content_id=firstly_created.content_id, |
|
1107 | user_id=test_user.user_id, |
|
1108 | ) |
|
1109 | ) |
|
1110 | # after |
|
1111 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1112 | user_id=test_user.user_id, |
|
1113 | workspace_id=workspace.workspace_id |
|
1114 | ), status=200) # nopep8 |
|
1115 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1116 | assert res.json_body[0]['read_by_user'] is True |
|
1117 | ||
1118 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1119 | user_id=admin.user_id, |
|
1120 | workspace_id=workspace.workspace_id |
|
1121 | ), status=200) # nopep8 |
|
1122 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1123 | assert res.json_body[0]['read_by_user'] is False |
|
1124 | ||
1125 | def test_api_set_content_as_read__ok__200__admin_workspace_do_not_exist(self): |
|
1126 | # init DB |