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