@@ 1602-1709 (lines=108) @@ | ||
1599 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1600 | assert res.json_body[0]['read_by_user'] is False |
|
1601 | ||
1602 | def test_api_set_content_as_read__ok__200__admin_with_comments_read_comment(self): |
|
1603 | # init DB |
|
1604 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1605 | admin = dbsession.query(models.User) \ |
|
1606 | .filter(models.User.email == '[email protected]') \ |
|
1607 | .one() |
|
1608 | workspace_api = WorkspaceApi( |
|
1609 | current_user=admin, |
|
1610 | session=dbsession, |
|
1611 | config=self.app_config |
|
1612 | ||
1613 | ) |
|
1614 | workspace = WorkspaceApi( |
|
1615 | current_user=admin, |
|
1616 | session=dbsession, |
|
1617 | config=self.app_config, |
|
1618 | ).create_workspace( |
|
1619 | 'test workspace', |
|
1620 | save_now=True |
|
1621 | ) |
|
1622 | uapi = UserApi( |
|
1623 | current_user=admin, |
|
1624 | session=dbsession, |
|
1625 | config=self.app_config, |
|
1626 | ) |
|
1627 | gapi = GroupApi( |
|
1628 | current_user=admin, |
|
1629 | session=dbsession, |
|
1630 | config=self.app_config, |
|
1631 | ) |
|
1632 | groups = [gapi.get_one_with_name('users')] |
|
1633 | test_user = uapi.create_user( |
|
1634 | email='[email protected]', |
|
1635 | password='pass', |
|
1636 | name='bob', |
|
1637 | groups=groups, |
|
1638 | timezone='Europe/Paris', |
|
1639 | lang='fr', |
|
1640 | do_save=True, |
|
1641 | do_notify=False, |
|
1642 | ) |
|
1643 | rapi = RoleApi( |
|
1644 | current_user=admin, |
|
1645 | session=dbsession, |
|
1646 | config=self.app_config, |
|
1647 | ) |
|
1648 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
1649 | api = ContentApi( |
|
1650 | current_user=admin, |
|
1651 | session=dbsession, |
|
1652 | config=self.app_config, |
|
1653 | ) |
|
1654 | api2 = ContentApi( |
|
1655 | current_user=test_user, |
|
1656 | session=dbsession, |
|
1657 | config=self.app_config, |
|
1658 | ) |
|
1659 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
1660 | # creation order test |
|
1661 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
1662 | comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True) # nopep8 |
|
1663 | api.mark_read(firstly_created) |
|
1664 | api.mark_unread(comments) |
|
1665 | dbsession.flush() |
|
1666 | transaction.commit() |
|
1667 | ||
1668 | self.testapp.authorization = ( |
|
1669 | 'Basic', |
|
1670 | ( |
|
1671 | '[email protected]', |
|
1672 | '[email protected]' |
|
1673 | ) |
|
1674 | ) |
|
1675 | # before |
|
1676 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1677 | user_id=test_user.user_id, |
|
1678 | workspace_id=workspace.workspace_id |
|
1679 | ), status=200) # nopep8 |
|
1680 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1681 | assert res.json_body[0]['read_by_user'] is False |
|
1682 | ||
1683 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1684 | user_id=admin.user_id, |
|
1685 | workspace_id=workspace.workspace_id |
|
1686 | ), status=200) # nopep8 |
|
1687 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1688 | assert res.json_body[0]['read_by_user'] is False |
|
1689 | self.testapp.put( |
|
1690 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/read'.format( # nopep8 |
|
1691 | workspace_id=workspace.workspace_id, |
|
1692 | content_id=comments.content_id, |
|
1693 | user_id=test_user.user_id, |
|
1694 | ) |
|
1695 | ) |
|
1696 | # after |
|
1697 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1698 | user_id=test_user.user_id, |
|
1699 | workspace_id=workspace.workspace_id |
|
1700 | ), status=200) # nopep8 |
|
1701 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1702 | assert res.json_body[0]['read_by_user'] is True |
|
1703 | ||
1704 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1705 | user_id=admin.user_id, |
|
1706 | workspace_id=workspace.workspace_id |
|
1707 | ), status=200) # nopep8 |
|
1708 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1709 | assert res.json_body[0]['read_by_user'] is False |
|
1710 | ||
1711 | ||
1712 | class TestUserSetContentAsUnread(FunctionalTest): |
|
@@ 1493-1600 (lines=108) @@ | ||
1490 | assert 'code' in res.json.keys() |
|
1491 | assert res.json_body['code'] == error.INSUFFICIENT_USER_PROFILE |
|
1492 | ||
1493 | def test_api_set_content_as_read__ok__200__admin_with_comments_read_content(self): |
|
1494 | # init DB |
|
1495 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1496 | admin = dbsession.query(models.User) \ |
|
1497 | .filter(models.User.email == '[email protected]') \ |
|
1498 | .one() |
|
1499 | workspace_api = WorkspaceApi( |
|
1500 | current_user=admin, |
|
1501 | session=dbsession, |
|
1502 | config=self.app_config |
|
1503 | ||
1504 | ) |
|
1505 | workspace = WorkspaceApi( |
|
1506 | current_user=admin, |
|
1507 | session=dbsession, |
|
1508 | config=self.app_config, |
|
1509 | ).create_workspace( |
|
1510 | 'test workspace', |
|
1511 | save_now=True |
|
1512 | ) |
|
1513 | uapi = UserApi( |
|
1514 | current_user=admin, |
|
1515 | session=dbsession, |
|
1516 | config=self.app_config, |
|
1517 | ) |
|
1518 | gapi = GroupApi( |
|
1519 | current_user=admin, |
|
1520 | session=dbsession, |
|
1521 | config=self.app_config, |
|
1522 | ) |
|
1523 | groups = [gapi.get_one_with_name('users')] |
|
1524 | test_user = uapi.create_user( |
|
1525 | email='[email protected]', |
|
1526 | password='pass', |
|
1527 | name='bob', |
|
1528 | groups=groups, |
|
1529 | timezone='Europe/Paris', |
|
1530 | lang='fr', |
|
1531 | do_save=True, |
|
1532 | do_notify=False, |
|
1533 | ) |
|
1534 | rapi = RoleApi( |
|
1535 | current_user=admin, |
|
1536 | session=dbsession, |
|
1537 | config=self.app_config, |
|
1538 | ) |
|
1539 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
1540 | api = ContentApi( |
|
1541 | current_user=admin, |
|
1542 | session=dbsession, |
|
1543 | config=self.app_config, |
|
1544 | ) |
|
1545 | api2 = ContentApi( |
|
1546 | current_user=test_user, |
|
1547 | session=dbsession, |
|
1548 | config=self.app_config, |
|
1549 | ) |
|
1550 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
1551 | # creation order test |
|
1552 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
1553 | comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True) # nopep8 |
|
1554 | api.mark_unread(firstly_created) |
|
1555 | api.mark_unread(comments) |
|
1556 | dbsession.flush() |
|
1557 | transaction.commit() |
|
1558 | ||
1559 | self.testapp.authorization = ( |
|
1560 | 'Basic', |
|
1561 | ( |
|
1562 | '[email protected]', |
|
1563 | '[email protected]' |
|
1564 | ) |
|
1565 | ) |
|
1566 | # before |
|
1567 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1568 | user_id=test_user.user_id, |
|
1569 | workspace_id=workspace.workspace_id |
|
1570 | ), status=200) # nopep8 |
|
1571 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1572 | assert res.json_body[0]['read_by_user'] is False |
|
1573 | ||
1574 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1575 | user_id=admin.user_id, |
|
1576 | workspace_id=workspace.workspace_id |
|
1577 | ), status=200) # nopep8 |
|
1578 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1579 | assert res.json_body[0]['read_by_user'] is False |
|
1580 | self.testapp.put( |
|
1581 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/read'.format( # nopep8 |
|
1582 | workspace_id=workspace.workspace_id, |
|
1583 | content_id=firstly_created.content_id, |
|
1584 | user_id=test_user.user_id, |
|
1585 | ) |
|
1586 | ) |
|
1587 | # after |
|
1588 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1589 | user_id=test_user.user_id, |
|
1590 | workspace_id=workspace.workspace_id |
|
1591 | ), status=200) # nopep8 |
|
1592 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1593 | assert res.json_body[0]['read_by_user'] is True |
|
1594 | ||
1595 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
1596 | user_id=admin.user_id, |
|
1597 | workspace_id=workspace.workspace_id |
|
1598 | ), status=200) # nopep8 |
|
1599 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
1600 | assert res.json_body[0]['read_by_user'] is False |
|
1601 | ||
1602 | def test_api_set_content_as_read__ok__200__admin_with_comments_read_comment(self): |
|
1603 | # init DB |