| 1388 | self.assertTrue(task.processing_node is None) |
| 1389 | |
| 1390 | def test_task_multifile_uploads(self): |
| 1391 | with start_processing_node(): |
| 1392 | client = APIClient() |
| 1393 | |
| 1394 | user = User.objects.get(username="testuser") |
| 1395 | self.assertFalse(user.is_superuser) |
| 1396 | |
| 1397 | project = Project.objects.create( |
| 1398 | owner=user, |
| 1399 | name="test project" |
| 1400 | ) |
| 1401 | |
| 1402 | pnode = ProcessingNode.objects.create(hostname="localhost", port=11223) |
| 1403 | assign_perm('view_processingnode', user, pnode) |
| 1404 | |
| 1405 | # task creation via chunked upload |
| 1406 | image1 = open("app/fixtures/tiny_drone_image.jpg", 'rb') |
| 1407 | image2 = open("app/fixtures/tiny_drone_image_2.jpg", 'rb') |
| 1408 | |
| 1409 | # Cannot create partial task without credentials |
| 1410 | res = client.post("/api/projects/{}/tasks/".format(project.id), { |
| 1411 | 'auto_processing_node': 'true', |
| 1412 | 'partial': 'true' |
| 1413 | }, format="multipart") |
| 1414 | self.assertTrue(res.status_code == status.HTTP_403_FORBIDDEN); |
| 1415 | |
| 1416 | client.login(username="testuser", password="test1234") |
| 1417 | |
| 1418 | # Can after login |
| 1419 | res = client.post("/api/projects/{}/tasks/".format(project.id), { |
| 1420 | 'auto_processing_node': 'true', |
| 1421 | 'partial': 'true' |
| 1422 | }, format="multipart") |
| 1423 | self.assertTrue(res.status_code == status.HTTP_201_CREATED) |
| 1424 | |
| 1425 | task = Task.objects.get(pk=res.data['id']) |
| 1426 | |
| 1427 | # It's partial |
| 1428 | self.assertTrue(task.partial) |
| 1429 | |
| 1430 | # It should not get processed |
| 1431 | worker.tasks.process_pending_tasks() |
| 1432 | time.sleep(DELAY) |
| 1433 | self.assertEqual(task.upload_progress, 0.0) |
| 1434 | |
| 1435 | # Upload to inexisting task lead to 404 |
| 1436 | wrong_task_id = '11111111-1111-1111-1111-111111111111' |
| 1437 | res = client.post("/api/projects/{}/tasks/{}/upload/".format(project.id, wrong_task_id), { |
| 1438 | 'images': [image1], |
| 1439 | }, format="multipart") |
| 1440 | self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND) |
| 1441 | image1.seek(0) |
| 1442 | |
| 1443 | # Upload works with one image |
| 1444 | res = client.post("/api/projects/{}/tasks/{}/upload/".format(project.id, task.id), { |
| 1445 | 'images': [image1], |
| 1446 | }, format="multipart") |
| 1447 | self.assertEqual(res.status_code, status.HTTP_200_OK) |