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