Code Duplication    Length = 118-120 lines in 2 locations

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

@@ 1129-1248 (lines=120) @@
1126
        eq_('', c.label)
1127
        eq_(ActionDescription.COMMENT, c.revision_type)
1128
1129
    def test_unit_copy_file_different_label_different_parent_ok(self):
1130
        uapi = UserApi(
1131
            session=self.session,
1132
            config=self.app_config,
1133
            current_user=None,
1134
        )
1135
        group_api = GroupApi(
1136
            current_user=None,
1137
            session=self.session,
1138
            config=self.app_config
1139
        )
1140
        groups = [group_api.get_one(Group.TIM_USER),
1141
                  group_api.get_one(Group.TIM_MANAGER),
1142
                  group_api.get_one(Group.TIM_ADMIN)]
1143
1144
        user = uapi.create_minimal_user(
1145
            email='user1@user',
1146
            groups=groups,
1147
            save_now=True
1148
        )
1149
        user2 = uapi.create_minimal_user(
1150
            email='user2@user',
1151
            groups=groups,
1152
            save_now=True
1153
        )
1154
        workspace = WorkspaceApi(
1155
            current_user=user,
1156
            session=self.session,
1157
            config=self.app_config,
1158
        ).create_workspace(
1159
            'test workspace',
1160
            save_now=True
1161
        )
1162
        RoleApi(
1163
            current_user=user,
1164
            session=self.session,
1165
            config=self.app_config,
1166
        ).create_one(
1167
            user2,
1168
            workspace,
1169
            UserRoleInWorkspace.WORKSPACE_MANAGER,
1170
            with_notif=False
1171
        )
1172
        api = ContentApi(
1173
            current_user=user,
1174
            session=self.session,
1175
            config=self.app_config,
1176
        )
1177
        foldera = api.create(
1178
            content_type_list.Folder.slug,
1179
            workspace,
1180
            None,
1181
            'folder a',
1182
            '',
1183
            True
1184
        )
1185
        with self.session.no_autoflush:
1186
            text_file = api.create(
1187
                content_type_slug=content_type_list.File.slug,
1188
                workspace=workspace,
1189
                parent=foldera,
1190
                label='test_file',
1191
                do_save=False,
1192
            )
1193
            api.update_file_data(
1194
                text_file,
1195
                'test_file',
1196
                'text/plain',
1197
                b'test_content'
1198
            )
1199
1200
        api.save(text_file, ActionDescription.CREATION)
1201
        api2 = ContentApi(
1202
            current_user=user2,
1203
            session=self.session,
1204
            config=self.app_config,
1205
        )
1206
        workspace2 = WorkspaceApi(
1207
            current_user=user2,
1208
            session=self.session,
1209
            config=self.app_config,
1210
        ).create_workspace(
1211
            'test workspace2',
1212
            save_now=True
1213
        )
1214
        folderb = api2.create(
1215
            content_type_list.Folder.slug,
1216
            workspace2,
1217
            None,
1218
            'folder b',
1219
            '',
1220
            True
1221
        )
1222
1223
        api2.copy(
1224
            item=text_file,
1225
            new_parent=folderb,
1226
            new_label='test_file_copy'
1227
        )
1228
1229
        transaction.commit()
1230
        text_file_copy = api2.get_one_by_label_and_parent(
1231
            'test_file_copy',
1232
            folderb,
1233
        )
1234
1235
        assert text_file != text_file_copy
1236
        assert text_file_copy.content_id != text_file.content_id
1237
        assert text_file_copy.workspace_id == workspace2.workspace_id
1238
        assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read()   # nopep8
1239
        assert text_file_copy.depot_file.path != text_file.depot_file.path
1240
        assert text_file_copy.label == 'test_file_copy'
1241
        assert text_file_copy.type == text_file.type
1242
        assert text_file_copy.parent.content_id == folderb.content_id
1243
        assert text_file_copy.owner.user_id == user.user_id
1244
        assert text_file_copy.description == text_file.description
1245
        assert text_file_copy.file_extension == text_file.file_extension
1246
        assert text_file_copy.file_mimetype == text_file.file_mimetype
1247
        assert text_file_copy.revision_type == ActionDescription.COPY
1248
        assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
1249
1250
    def test_unit_copy_file__same_label_different_parent_ok(self):
1251
        uapi = UserApi(
@@ 1250-1367 (lines=118) @@
1247
        assert text_file_copy.revision_type == ActionDescription.COPY
1248
        assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
1249
1250
    def test_unit_copy_file__same_label_different_parent_ok(self):
1251
        uapi = UserApi(
1252
            session=self.session,
1253
            config=self.app_config,
1254
            current_user=None,
1255
        )
1256
        group_api = GroupApi(
1257
            current_user=None,
1258
            session=self.session,
1259
            config=self.app_config,
1260
        )
1261
        groups = [group_api.get_one(Group.TIM_USER),
1262
                  group_api.get_one(Group.TIM_MANAGER),
1263
                  group_api.get_one(Group.TIM_ADMIN)]
1264
1265
        user = uapi.create_minimal_user(
1266
            email='user1@user',
1267
            groups=groups,
1268
            save_now=True
1269
        )
1270
        user2 = uapi.create_minimal_user(
1271
            email='user2@user',
1272
            groups=groups,
1273
            save_now=True
1274
        )
1275
        workspace = WorkspaceApi(
1276
            current_user=user,
1277
            session=self.session,
1278
            config=self.app_config,
1279
        ).create_workspace(
1280
            'test workspace',
1281
            save_now=True
1282
        )
1283
        RoleApi(
1284
            current_user=user,
1285
            session=self.session,
1286
            config=self.app_config,
1287
        ).create_one(
1288
            user2,
1289
            workspace,
1290
            UserRoleInWorkspace.WORKSPACE_MANAGER,
1291
            with_notif=False
1292
        )
1293
        api = ContentApi(
1294
            current_user=user,
1295
            session=self.session,
1296
            config=self.app_config,
1297
        )
1298
        foldera = api.create(
1299
            content_type_list.Folder.slug,
1300
            workspace,
1301
            None,
1302
            'folder a',
1303
            '',
1304
            True
1305
        )
1306
        with self.session.no_autoflush:
1307
            text_file = api.create(
1308
                content_type_slug=content_type_list.File.slug,
1309
                workspace=workspace,
1310
                parent=foldera,
1311
                label='test_file',
1312
                do_save=False,
1313
            )
1314
            api.update_file_data(
1315
                text_file,
1316
                'test_file',
1317
                'text/plain',
1318
                b'test_content'
1319
            )
1320
1321
        api.save(text_file, ActionDescription.CREATION)
1322
        api2 = ContentApi(
1323
            current_user=user2,
1324
            session=self.session,
1325
            config=self.app_config,
1326
        )
1327
        workspace2 = WorkspaceApi(
1328
            current_user=user2,
1329
            session=self.session,
1330
            config=self.app_config,
1331
        ).create_workspace(
1332
            'test workspace2',
1333
            save_now=True
1334
        )
1335
        folderb = api2.create(
1336
            content_type_list.Folder.slug,
1337
            workspace2,
1338
            None,
1339
            'folder b',
1340
            '',
1341
            True
1342
        )
1343
        api2.copy(
1344
            item=text_file,
1345
            new_parent=folderb,
1346
        )
1347
1348
        transaction.commit()
1349
        text_file_copy = api2.get_one_by_label_and_parent(
1350
            'test_file',
1351
            folderb,
1352
        )
1353
1354
        assert text_file != text_file_copy
1355
        assert text_file_copy.content_id != text_file.content_id
1356
        assert text_file_copy.workspace_id == workspace2.workspace_id
1357
        assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read()  # nopep8
1358
        assert text_file_copy.depot_file.path != text_file.depot_file.path
1359
        assert text_file_copy.label == text_file.label
1360
        assert text_file_copy.type == text_file.type
1361
        assert text_file_copy.parent.content_id == folderb.content_id
1362
        assert text_file_copy.owner.user_id == user.user_id
1363
        assert text_file_copy.description == text_file.description
1364
        assert text_file_copy.file_extension == text_file.file_extension
1365
        assert text_file_copy.file_mimetype == text_file.file_mimetype
1366
        assert text_file_copy.revision_type == ActionDescription.COPY
1367
        assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
1368
1369
    def test_unit_copy_file_different_label_same_parent_ok(self):
1370
        uapi = UserApi(