| 1484 | |
| 1485 | |
| 1486 | def test_task_chunked_uploads(self): |
| 1487 | with start_processing_node(): |
| 1488 | client = APIClient() |
| 1489 | |
| 1490 | user = User.objects.get(username="testuser") |
| 1491 | self.assertFalse(user.is_superuser) |
| 1492 | |
| 1493 | project = Project.objects.create( |
| 1494 | owner=user, |
| 1495 | name="test project" |
| 1496 | ) |
| 1497 | |
| 1498 | pnode = ProcessingNode.objects.create(hostname="localhost", port=11223) |
| 1499 | assign_perm('view_processingnode', user, pnode) |
| 1500 | |
| 1501 | # task creation via chunked upload |
| 1502 | im1 = "app/fixtures/tiny_drone_image.jpg" |
| 1503 | image1 = open(im1, 'rb') |
| 1504 | image2 = open("app/fixtures/tiny_drone_image_2.jpg", 'rb') |
| 1505 | |
| 1506 | client.login(username="testuser", password="test1234") |
| 1507 | |
| 1508 | res = client.post("/api/projects/{}/tasks/".format(project.id), { |
| 1509 | 'auto_processing_node': 'true', |
| 1510 | 'partial': 'true' |
| 1511 | }, format="multipart") |
| 1512 | self.assertTrue(res.status_code == status.HTTP_201_CREATED) |
| 1513 | |
| 1514 | task = Task.objects.get(pk=res.data['id']) |
| 1515 | |
| 1516 | # Upload works with one chunked image |
| 1517 | image1_size = os.path.getsize(im1) |
| 1518 | chunk_1_size = image1_size // 2 |
| 1519 | chunk_1_path = os.path.join(os.path.dirname(im1), "1.jpg") |
| 1520 | chunk_2_path = os.path.join(os.path.dirname(im1), "2.jpg") |
| 1521 | with open(chunk_1_path, 'wb') as f: |
| 1522 | image1.seek(0) |
| 1523 | f.write(image1.read(chunk_1_size)) |
| 1524 | with open(chunk_2_path, 'wb') as f: |
| 1525 | f.write(image1.read()) |
| 1526 | |
| 1527 | chunk_1 = open(chunk_1_path, 'rb') |
| 1528 | chunk_2 = open(chunk_2_path, 'rb') |
| 1529 | image1.close() |
| 1530 | |
| 1531 | res = client.post("/api/projects/{}/tasks/{}/upload/".format(project.id, task.id), { |
| 1532 | 'images': [chunk_1], |
| 1533 | 'dzuuid': 'abc-test', |
| 1534 | 'dzchunkindex': 0, |
| 1535 | 'dztotalchunkcount': 2, |
| 1536 | 'dzchunkbyteoffset': 0 |
| 1537 | }, format="multipart") |
| 1538 | self.assertEqual(res.status_code, status.HTTP_200_OK) |
| 1539 | self.assertEqual(len(res.data['uploaded']), 0) |
| 1540 | chunk_1.close() |
| 1541 | |
| 1542 | res = client.post("/api/projects/{}/tasks/{}/upload/".format(project.id, task.id), { |
| 1543 | 'images': [chunk_2], |