Code Duplication    Length = 118-119 lines in 2 locations

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

@@ 1986-2104 (lines=119) @@
1983
        eq_('new content', updated.description)
1984
        eq_(ActionDescription.EDITION, updated.revision_type)
1985
1986
    def test_unit__update__err__label_already_used(self):
1987
        uapi = UserApi(
1988
            session=self.session,
1989
            config=self.app_config,
1990
            current_user=None,
1991
        )
1992
        group_api = GroupApi(
1993
            current_user=None,
1994
            session=self.session,
1995
            config=self.app_config,
1996
        )
1997
        groups = [group_api.get_one(Group.TIM_USER),
1998
                  group_api.get_one(Group.TIM_MANAGER),
1999
                  group_api.get_one(Group.TIM_ADMIN)]
2000
2001
        user1 = uapi.create_minimal_user(
2002
            email='this.is@user',
2003
            groups=groups,
2004
            save_now=True
2005
        )
2006
2007
        workspace_api = WorkspaceApi(
2008
            current_user=user1,
2009
            session=self.session,
2010
            config=self.app_config,
2011
        )
2012
        workspace = workspace_api.create_workspace(
2013
            'test workspace',
2014
            save_now=True
2015
        )
2016
2017
        wid = workspace.workspace_id
2018
2019
        user2 = uapi.create_minimal_user('[email protected]')
2020
        uapi.save(user2)
2021
2022
        RoleApi(
2023
            current_user=user1,
2024
            session=self.session,
2025
            config=self.app_config,
2026
        ).create_one(
2027
            user2,
2028
            workspace,
2029
            UserRoleInWorkspace.CONTENT_MANAGER,
2030
            with_notif=False,
2031
            flush=True
2032
        )
2033
2034
        # Test starts here
2035
2036
        api = ContentApi(
2037
            current_user=user1,
2038
            session=self.session,
2039
            config=self.app_config,
2040
        )
2041
2042
        p = api.create(
2043
            content_type_slug=CONTENT_TYPES.Page.slug,
2044
            workspace=workspace,
2045
            parent=None,
2046
            label='this_is_a_page',
2047
            do_save=True
2048
        )
2049
        p2 = api.create(
2050
            content_type_slug=CONTENT_TYPES.Page.slug,
2051
            workspace=workspace,
2052
            parent=None,
2053
            label='this_is_a_page2',
2054
            do_save=True
2055
        )
2056
        u1id = user1.user_id
2057
        u2id = user2.user_id
2058
        pcid = p.content_id
2059
        poid = p.owner_id
2060
2061
        transaction.commit()
2062
2063
        # Refresh instances after commit
2064
        user1 = uapi.get_one(u1id)
2065
        workspace = WorkspaceApi(
2066
            current_user=user1,
2067
            session=self.session,
2068
            config=self.app_config,
2069
        ).get_one(wid)
2070
        api = ContentApi(
2071
            current_user=user1,
2072
            session=self.session,
2073
            config=self.app_config,
2074
        )
2075
2076
        content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
2077
        eq_(u1id, content.owner_id)
2078
        eq_(poid, content.owner_id)
2079
2080
        u2 = UserApi(
2081
            session=self.session,
2082
            config=self.app_config,
2083
            current_user=None,
2084
        ).get_one(u2id)
2085
        api2 = ContentApi(
2086
            current_user=u2,
2087
            session=self.session,
2088
            config=self.app_config,
2089
        )
2090
        content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
2091
        with pytest.raises(ContentLabelAlreadyUsedHere):
2092
            with new_revision(
2093
                    session=self.session,
2094
                    tm=transaction.manager,
2095
                    content=content2,
2096
            ):
2097
                api2.update_content(
2098
                    content2,
2099
                    'this_is_a_page2',
2100
                    'new content'
2101
                )
2102
            api2.save(content2)
2103
            content3 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
2104
            assert content3.label == 'this_is_a_page'
2105
2106
    def test_unit__update__err__label_dont_change(self):
2107
        uapi = UserApi(
@@ 2106-2223 (lines=118) @@
2103
            content3 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
2104
            assert content3.label == 'this_is_a_page'
2105
2106
    def test_unit__update__err__label_dont_change(self):
2107
        uapi = UserApi(
2108
            session=self.session,
2109
            config=self.app_config,
2110
            current_user=None,
2111
        )
2112
        group_api = GroupApi(
2113
            current_user=None,
2114
            session=self.session,
2115
            config=self.app_config,
2116
        )
2117
        groups = [group_api.get_one(Group.TIM_USER),
2118
                  group_api.get_one(Group.TIM_MANAGER),
2119
                  group_api.get_one(Group.TIM_ADMIN)]
2120
2121
        user1 = uapi.create_minimal_user(
2122
            email='this.is@user',
2123
            groups=groups,
2124
            save_now=True
2125
        )
2126
2127
        workspace_api = WorkspaceApi(
2128
            current_user=user1,
2129
            session=self.session,
2130
            config=self.app_config,
2131
        )
2132
        workspace = workspace_api.create_workspace(
2133
            'test workspace',
2134
            save_now=True
2135
        )
2136
2137
        wid = workspace.workspace_id
2138
2139
        user2 = uapi.create_minimal_user('[email protected]')
2140
        uapi.save(user2)
2141
2142
        RoleApi(
2143
            current_user=user1,
2144
            session=self.session,
2145
            config=self.app_config,
2146
        ).create_one(
2147
            user2,
2148
            workspace,
2149
            UserRoleInWorkspace.CONTENT_MANAGER,
2150
            with_notif=False,
2151
            flush=True
2152
        )
2153
2154
        # Test starts here
2155
2156
        api = ContentApi(
2157
            current_user=user1,
2158
            session=self.session,
2159
            config=self.app_config,
2160
        )
2161
2162
        p = api.create(
2163
            content_type_slug=CONTENT_TYPES.Page.slug,
2164
            workspace=workspace,
2165
            parent=None,
2166
            label='this_is_a_page',
2167
            do_save=True
2168
        )
2169
        p2 = api.create(
2170
            content_type_slug=CONTENT_TYPES.Page.slug,
2171
            workspace=workspace,
2172
            parent=None,
2173
            label='this_is_a_page2',
2174
            do_save=True
2175
        )
2176
        u1id = user1.user_id
2177
        u2id = user2.user_id
2178
        pcid = p.content_id
2179
        poid = p.owner_id
2180
2181
        transaction.commit()
2182
2183
        # Refresh instances after commit
2184
        user1 = uapi.get_one(u1id)
2185
        workspace = WorkspaceApi(
2186
            current_user=user1,
2187
            session=self.session,
2188
            config=self.app_config,
2189
        ).get_one(wid)
2190
        api = ContentApi(
2191
            current_user=user1,
2192
            session=self.session,
2193
            config=self.app_config,
2194
        )
2195
2196
        content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
2197
        eq_(u1id, content.owner_id)
2198
        eq_(poid, content.owner_id)
2199
2200
        u2 = UserApi(
2201
            session=self.session,
2202
            config=self.app_config,
2203
            current_user=None,
2204
        ).get_one(u2id)
2205
        api2 = ContentApi(
2206
            current_user=u2,
2207
            session=self.session,
2208
            config=self.app_config,
2209
        )
2210
        content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
2211
        with new_revision(
2212
                session=self.session,
2213
                tm=transaction.manager,
2214
                content=content2,
2215
        ):
2216
            api2.update_content(
2217
                content2,
2218
                'this_is_a_page',
2219
                'new content'
2220
            )
2221
        api2.save(content2)
2222
        content3 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
2223
        assert content3.label == 'this_is_a_page'
2224
2225
    def test_update_no_change(self):
2226
        uapi = UserApi(