Code Duplication    Length = 145-146 lines in 2 locations

tracim/tests/library/test_content_api.py 2 locations

@@ 1629-1774 (lines=146) @@
1626
        eq_(ActionDescription.UNARCHIVING, updated2.revision_type)
1627
        eq_(u1id, updated2.owner_id)
1628
1629
    def test_delete_undelete(self):
1630
        uapi = UserApi(
1631
            session=self.session,
1632
            config=self.app_config,
1633
            current_user=None,
1634
        )
1635
        group_api = GroupApi(
1636
            current_user=None,
1637
            session=self.session
1638
        )
1639
        groups = [group_api.get_one(Group.TIM_USER),
1640
                  group_api.get_one(Group.TIM_MANAGER),
1641
                  group_api.get_one(Group.TIM_ADMIN)]
1642
1643
        user1 = uapi.create_user(
1644
            email='this.is@user',
1645
            groups=groups,
1646
            save_now=True
1647
        )
1648
        u1id = user1.user_id
1649
1650
        workspace_api = WorkspaceApi(current_user=user1, session=self.session)
1651
        workspace = workspace_api.create_workspace(
1652
            'test workspace',
1653
            save_now=True
1654
        )
1655
        wid = workspace.workspace_id
1656
1657
        user2 = uapi.create_user()
1658
        user2.email = '[email protected]'
1659
        uapi.save(user2)
1660
1661
        RoleApi(
1662
            current_user=user1,
1663
            session=self.session
1664
        ).create_one(
1665
            user2,
1666
            workspace,
1667
            UserRoleInWorkspace.CONTENT_MANAGER,
1668
            with_notif=True,
1669
            flush=True
1670
        )
1671
1672
        # show archived is used at the top end of the test
1673
        api = ContentApi(
1674
            current_user=user1,
1675
            session=self.session,
1676
            config=self.app_config,
1677
            show_deleted=True,
1678
        )
1679
        p = api.create(ContentType.File, workspace, None,
1680
                       'this_is_a_page', True)
1681
1682
        u1id = user1.user_id
1683
        u2id = user2.user_id
1684
        pcid = p.content_id
1685
        poid = p.owner_id
1686
1687
        transaction.commit()
1688
1689
        ####
1690
        user1 = UserApi(
1691
            current_user=None,
1692
            session=self.session,
1693
            config=self.app_config,
1694
        ).get_one(u1id)
1695
        workspace = WorkspaceApi(
1696
            current_user=user1,
1697
            session=self.session,
1698
        ).get_one(wid)
1699
1700
        content = api.get_one(pcid, ContentType.Any, workspace)
1701
        eq_(u1id, content.owner_id)
1702
        eq_(poid, content.owner_id)
1703
1704
        u2 = UserApi(
1705
            current_user=None,
1706
            session=self.session,
1707
            config=self.app_config,
1708
        ).get_one(u2id)
1709
        api2 = ContentApi(
1710
            current_user=u2,
1711
            session=self.session,
1712
            config=self.app_config,
1713
            show_deleted=True,
1714
        )
1715
        content2 = api2.get_one(pcid, ContentType.Any, workspace)
1716
        with new_revision(
1717
                session=self.session,
1718
                tm=transaction.manager,
1719
                content=content2,
1720
        ):
1721
            api2.delete(content2)
1722
        api2.save(content2)
1723
        transaction.commit()
1724
1725
        ####
1726
1727
        user1 = UserApi(
1728
            current_user=None,
1729
            session=self.session,
1730
            config=self.app_config,
1731
        ).get_one(u1id)
1732
        workspace = WorkspaceApi(
1733
            current_user=user1,
1734
            session=self.session,
1735
        ).get_one(wid)
1736
        # show archived is used at the top end of the test
1737
        api = ContentApi(
1738
            current_user=user1,
1739
            session=self.session,
1740
            config=self.app_config,
1741
            show_deleted=True,
1742
        )
1743
        u2 = UserApi(
1744
            current_user=None,
1745
            session=self.session,
1746
            config=self.app_config,
1747
        ).get_one(u2id)
1748
        api2 = ContentApi(
1749
            current_user=u2,
1750
            session=self.session,
1751
            config=self.app_config,
1752
            show_deleted=True
1753
        )
1754
1755
        updated = api2.get_one(pcid, ContentType.Any, workspace)
1756
        eq_(u2id, updated.owner_id,
1757
            'the owner id should be {} (found {})'.format(u2id,
1758
                                                          updated.owner_id))
1759
        eq_(True, updated.is_deleted)
1760
        eq_(ActionDescription.DELETION, updated.revision_type)
1761
1762
        ####
1763
1764
        updated2 = api.get_one(pcid, ContentType.Any, workspace)
1765
        with new_revision(
1766
            tm=transaction.manager,
1767
            session=self.session,
1768
            content=updated2,
1769
        ):
1770
            api.undelete(updated2)
1771
        api.save(updated2)
1772
        eq_(False, updated2.is_deleted)
1773
        eq_(ActionDescription.UNDELETION, updated2.revision_type)
1774
        eq_(u1id, updated2.owner_id)
1775
1776
    def test_search_in_label(self):
1777
        # HACK - D.A. - 2015-03-09
@@ 1483-1627 (lines=145) @@
1480
        api2.save(content2)
1481
        transaction.commit()
1482
1483
    def test_archive_unarchive(self):
1484
        uapi = UserApi(
1485
            session=self.session,
1486
            config=self.app_config,
1487
            current_user=None,
1488
        )
1489
        group_api = GroupApi(current_user=None, session=self.session)
1490
        groups = [group_api.get_one(Group.TIM_USER),
1491
                  group_api.get_one(Group.TIM_MANAGER),
1492
                  group_api.get_one(Group.TIM_ADMIN)]
1493
1494
        user1 = uapi.create_user(
1495
            email='this.is@user',
1496
            groups=groups,
1497
            save_now=True
1498
        )
1499
        u1id = user1.user_id
1500
1501
        workspace_api = WorkspaceApi(current_user=user1, session=self.session)
1502
        workspace = workspace_api.create_workspace(
1503
            'test workspace',
1504
            save_now=True
1505
        )
1506
        wid = workspace.workspace_id
1507
1508
        user2 = uapi.create_user()
1509
        user2.email = '[email protected]'
1510
        uapi.save(user2)
1511
1512
        RoleApi(
1513
            current_user=user1,
1514
            session=self.session
1515
        ).create_one(
1516
            user2,
1517
            workspace,
1518
            UserRoleInWorkspace.CONTENT_MANAGER,
1519
            with_notif=True,
1520
            flush=True
1521
        )
1522
1523
        # show archived is used at the top end of the test
1524
        api = ContentApi(
1525
            current_user=user1,
1526
            session=self.session,
1527
            show_archived=True,
1528
            config=self.app_config,
1529
        )
1530
        p = api.create(ContentType.File, workspace, None,
1531
                       'this_is_a_page', True)
1532
1533
        u1id = user1.user_id
1534
        u2id = user2.user_id
1535
        pcid = p.content_id
1536
        poid = p.owner_id
1537
1538
        transaction.commit()
1539
1540
        ####
1541
1542
        # refresh after commit
1543
        user1 = UserApi(
1544
            current_user=None,
1545
            config=self.app_config,
1546
            session=self.session
1547
        ).get_one(u1id)
1548
        workspace = WorkspaceApi(
1549
            current_user=user1,
1550
            session=self.session
1551
        ).get_one(wid)
1552
1553
        content = api.get_one(pcid, ContentType.Any, workspace)
1554
        eq_(u1id, content.owner_id)
1555
        eq_(poid, content.owner_id)
1556
1557
        u2api = UserApi(
1558
            session=self.session,
1559
            config=self.app_config,
1560
            current_user=None,
1561
        )
1562
        u2 = u2api.get_one(u2id)
1563
        api2 = ContentApi(
1564
            current_user=u2,
1565
            session=self.session,
1566
            config=self.app_config,
1567
            show_archived=True,
1568
        )
1569
        content2 = api2.get_one(pcid, ContentType.Any, workspace)
1570
        with new_revision(
1571
                session=self.session,
1572
                tm=transaction.manager,
1573
                content=content2,
1574
        ):
1575
            api2.archive(content2)
1576
        api2.save(content2)
1577
        transaction.commit()
1578
1579
        # refresh after commit
1580
        user1 = UserApi(
1581
            current_user=None,
1582
            session=self.session,
1583
            config=self.app_config,
1584
        ).get_one(u1id)
1585
        workspace = WorkspaceApi(
1586
            current_user=user1,
1587
            session=self.session,
1588
        ).get_one(wid)
1589
        u2 = UserApi(
1590
            current_user=None,
1591
            session=self.session,
1592
            config=self.app_config,
1593
        ).get_one(u2id)
1594
        api = ContentApi(
1595
            current_user=user1,
1596
            session=self.session,
1597
            config=self.app_config,
1598
            show_archived=True,
1599
        )
1600
        api2 = ContentApi(
1601
            current_user=u2,
1602
            session=self.session,
1603
            config=self.app_config,
1604
            show_archived=True,
1605
        )
1606
1607
        updated = api2.get_one(pcid, ContentType.Any, workspace)
1608
        eq_(u2id, updated.owner_id,
1609
            'the owner id should be {} (found {})'.format(u2id,
1610
                                                          updated.owner_id))
1611
        eq_(True, updated.is_archived)
1612
        eq_(ActionDescription.ARCHIVING, updated.revision_type)
1613
1614
        ####
1615
1616
        updated2 = api.get_one(pcid, ContentType.Any, workspace)
1617
        with new_revision(
1618
            session=self.session,
1619
            tm=transaction.manager,
1620
            content=updated,
1621
1622
        ):
1623
            api.unarchive(updated)
1624
        api.save(updated2)
1625
        eq_(False, updated2.is_archived)
1626
        eq_(ActionDescription.UNARCHIVING, updated2.revision_type)
1627
        eq_(u1id, updated2.owner_id)
1628
1629
    def test_delete_undelete(self):
1630
        uapi = UserApi(