Code Duplication    Length = 118-119 lines in 2 locations

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

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