Code Duplication    Length = 115-116 lines in 2 locations

backend/tracim_backend/tests/library/test_content_api.py 2 locations

@@ 2563-2678 (lines=116) @@
2560
        eq_(b'<html>hello world</html>', updated.depot_file.file.read())
2561
        eq_(ActionDescription.REVISION, updated.revision_type)
2562
2563
    def test_update_file_data__err__content_status_closed(self):
2564
        uapi = UserApi(
2565
            session=self.session,
2566
            config=self.app_config,
2567
            current_user=None,
2568
        )
2569
        group_api = GroupApi(
2570
            current_user=None,
2571
            session=self.session,
2572
            config=self.app_config,
2573
        )
2574
        groups = [group_api.get_one(Group.TIM_USER),
2575
                  group_api.get_one(Group.TIM_MANAGER),
2576
                  group_api.get_one(Group.TIM_ADMIN)]
2577
2578
        user1 = uapi.create_minimal_user(
2579
            email='this.is@user',
2580
            groups=groups,
2581
            save_now=True
2582
        )
2583
2584
        workspace_api = WorkspaceApi(
2585
            current_user=user1,
2586
            session=self.session,
2587
            config=self.app_config,
2588
        )
2589
        workspace = workspace_api.create_workspace(
2590
            'test workspace',
2591
            save_now=True
2592
        )
2593
        wid = workspace.workspace_id
2594
2595
        user2 = uapi.create_minimal_user('[email protected]')
2596
        uapi.save(user2)
2597
2598
        RoleApi(
2599
            current_user=user1,
2600
            session=self.session,
2601
            config=self.app_config,
2602
        ).create_one(
2603
            user2,
2604
            workspace,
2605
            UserRoleInWorkspace.CONTENT_MANAGER,
2606
            with_notif=True,
2607
            flush=True
2608
        )
2609
2610
        # Test starts here
2611
        api = ContentApi(
2612
            current_user=user1,
2613
            session=self.session,
2614
            config=self.app_config,
2615
        )
2616
        p = api.create(
2617
            content_type_slug=content_type_list.File.slug,
2618
            workspace=workspace,
2619
            parent=None,
2620
            label='this_is_a_page',
2621
            do_save=False
2622
        )
2623
        p.status = 'closed-validated'
2624
        api.save(p)
2625
2626
        u1id = user1.user_id
2627
        u2id = user2.user_id
2628
        pcid = p.content_id
2629
        poid = p.owner_id
2630
2631
        api.save(p)
2632
        transaction.commit()
2633
2634
        # Refresh instances after commit
2635
        user1 = uapi.get_one(u1id)
2636
        workspace_api2 = WorkspaceApi(
2637
            current_user=user1,
2638
            session=self.session,
2639
            config=self.app_config,
2640
        )
2641
        workspace = workspace_api2.get_one(wid)
2642
        api = ContentApi(
2643
            current_user=user1,
2644
            session=self.session,
2645
            config=self.app_config,
2646
        )
2647
2648
        content = api.get_one(pcid, content_type_list.Any_SLUG, workspace)
2649
        eq_(u1id, content.owner_id)
2650
        eq_(poid, content.owner_id)
2651
2652
        u2 = UserApi(
2653
            current_user=None,
2654
            session=self.session,
2655
            config=self.app_config,
2656
        ).get_one(u2id)
2657
        api2 = ContentApi(
2658
            current_user=u2,
2659
            session=self.session,
2660
            config=self.app_config,
2661
        )
2662
        content2 = api2.get_one(pcid, content_type_list.Any_SLUG, workspace)
2663
        content2_nb_rev = len(content2.revisions)
2664
        with pytest.raises(ContentInNotEditableState):
2665
            with new_revision(
2666
                session=self.session,
2667
                tm=transaction.manager,
2668
                content=content2,
2669
            ):
2670
                    api2.update_file_data(
2671
                        content2,
2672
                        'index.html',
2673
                        'text/html',
2674
                        b'<html>hello world</html>'
2675
                    )
2676
        content3 = api2.get_one(pcid, content_type_list.Any_SLUG, workspace)
2677
        assert content3.label == 'this_is_a_page'
2678
        assert content2_nb_rev == len(content3.revisions)
2679
2680
    def test_update_file_data__err__content_archived(self):
2681
        uapi = UserApi(
@@ 1989-2103 (lines=115) @@
1986
        eq_('new content', updated.description)
1987
        eq_(ActionDescription.EDITION, updated.revision_type)
1988
1989
    def test_unit__update__err__status_closed(self):
1990
        uapi = UserApi(
1991
            session=self.session,
1992
            config=self.app_config,
1993
            current_user=None,
1994
        )
1995
        group_api = GroupApi(
1996
            current_user=None,
1997
            session=self.session,
1998
            config=self.app_config,
1999
        )
2000
        groups = [group_api.get_one(Group.TIM_USER),
2001
                  group_api.get_one(Group.TIM_MANAGER),
2002
                  group_api.get_one(Group.TIM_ADMIN)]
2003
2004
        user1 = uapi.create_minimal_user(
2005
            email='this.is@user',
2006
            groups=groups,
2007
            save_now=True
2008
        )
2009
2010
        workspace_api = WorkspaceApi(
2011
            current_user=user1,
2012
            session=self.session,
2013
            config=self.app_config,
2014
        )
2015
        workspace = workspace_api.create_workspace(
2016
            'test workspace',
2017
            save_now=True
2018
        )
2019
2020
        wid = workspace.workspace_id
2021
2022
        user2 = uapi.create_minimal_user('[email protected]')
2023
        uapi.save(user2)
2024
2025
        RoleApi(
2026
            current_user=user1,
2027
            session=self.session,
2028
            config=self.app_config,
2029
        ).create_one(
2030
            user2,
2031
            workspace,
2032
            UserRoleInWorkspace.CONTENT_MANAGER,
2033
            with_notif=False,
2034
            flush=True
2035
        )
2036
2037
        # Test starts here
2038
2039
        api = ContentApi(
2040
            current_user=user1,
2041
            session=self.session,
2042
            config=self.app_config,
2043
        )
2044
2045
        p = api.create(
2046
            content_type_slug=content_type_list.Page.slug,
2047
            workspace=workspace,
2048
            parent=None,
2049
            label='this_is_a_page',
2050
            do_save=False
2051
        )
2052
        p.status = 'closed-validated'
2053
        api.save(p)
2054
        u1id = user1.user_id
2055
        u2id = user2.user_id
2056
        pcid = p.content_id
2057
        poid = p.owner_id
2058
2059
        transaction.commit()
2060
2061
        # Refresh instances after commit
2062
        user1 = uapi.get_one(u1id)
2063
        workspace = WorkspaceApi(
2064
            current_user=user1,
2065
            session=self.session,
2066
            config=self.app_config,
2067
        ).get_one(wid)
2068
        api = ContentApi(
2069
            current_user=user1,
2070
            session=self.session,
2071
            config=self.app_config,
2072
        )
2073
2074
        content = api.get_one(pcid, content_type_list.Any_SLUG, workspace)
2075
        eq_(u1id, content.owner_id)
2076
        eq_(poid, content.owner_id)
2077
2078
        u2 = UserApi(
2079
            session=self.session,
2080
            config=self.app_config,
2081
            current_user=None,
2082
        ).get_one(u2id)
2083
        api2 = ContentApi(
2084
            current_user=u2,
2085
            session=self.session,
2086
            config=self.app_config,
2087
        )
2088
        content2 = api2.get_one(pcid, content_type_list.Any_SLUG, workspace)
2089
        content2_nb_rev = len(content2.revisions)
2090
        with pytest.raises(ContentInNotEditableState):
2091
            with new_revision(
2092
                    session=self.session,
2093
                    tm=transaction.manager,
2094
                    content=content2,
2095
            ):
2096
                    api2.update_content(
2097
                        content2,
2098
                        'this is an updated page',
2099
                        'new content'
2100
                    )
2101
        content3 = api2.get_one(pcid, content_type_list.Any_SLUG, workspace)
2102
        assert content3.label == 'this_is_a_page'
2103
        assert content2_nb_rev == len(content3.revisions)
2104
2105
    def test_unit__update__err__label_already_used(self):
2106
        uapi = UserApi(