26
26
)
27
27
from grandchallenge .components .schemas import GPUTypeChoices
28
28
from grandchallenge .subdomains .utils import reverse
29
+ from grandchallenge .uploads .models import UserUpload
29
30
from tests .algorithms_tests .factories import (
30
31
AlgorithmFactory ,
31
32
AlgorithmImageFactory ,
@@ -1357,11 +1358,34 @@ def test_create_job_is_idempotent(
1357
1358
assert Job .objects .count () == 1
1358
1359
1359
1360
@override_settings (task_eager_propagates = True , task_always_eager = True )
1360
- def test_create_job_with_faulty_file_input (
1361
+ @pytest .mark .django_db
1362
+ @pytest .mark .parametrize (
1363
+ "file_json_content,job_status,error_message,detailed_error_message,ci_count,upload_exists" ,
1364
+ [
1365
+ (
1366
+ b'{"Foo": "bar"}' ,
1367
+ Job .CANCELLED ,
1368
+ "One or more of the inputs failed validation." ,
1369
+ {
1370
+ "ci_json_file" : "JSON does not fulfill schema: instance is not of type 'array'"
1371
+ },
1372
+ 0 ,
1373
+ True ,
1374
+ ),
1375
+ (b'[{"Foo": "bar"}]' , Job .PROVISIONED , "" , {}, 1 , False ),
1376
+ ],
1377
+ )
1378
+ def test_create_job_with_file_input (
1361
1379
self ,
1362
1380
client ,
1363
1381
django_capture_on_commit_callbacks ,
1364
1382
algorithm_with_multiple_inputs ,
1383
+ file_json_content ,
1384
+ error_message ,
1385
+ detailed_error_message ,
1386
+ ci_count ,
1387
+ upload_exists ,
1388
+ job_status ,
1365
1389
):
1366
1390
# configure file input
1367
1391
algorithm_with_multiple_inputs .algorithm .inputs .set (
@@ -1371,7 +1395,7 @@ def test_create_job_with_faulty_file_input(
1371
1395
filename = "file.json" , creator = algorithm_with_multiple_inputs .editor
1372
1396
)
1373
1397
presigned_urls = file_upload .generate_presigned_urls (part_numbers = [1 ])
1374
- response = put (presigned_urls ["1" ], data = b'{"Foo": "bar"}' )
1398
+ response = put (presigned_urls ["1" ], data = file_json_content )
1375
1399
file_upload .complete_multipart_upload (
1376
1400
parts = [{"ETag" : response .headers ["ETag" ], "PartNumber" : 1 }]
1377
1401
)
@@ -1394,15 +1418,15 @@ def test_create_job_with_faulty_file_input(
1394
1418
assert Job .objects .count () == 1
1395
1419
job = Job .objects .get ()
1396
1420
# but in cancelled state and with an error message
1397
- assert job .status == Job .CANCELLED
1421
+ assert job .status == job_status
1422
+ assert error_message == job .error_message
1423
+ assert job .detailed_error_message == detailed_error_message
1398
1424
assert (
1399
- "One or more of the inputs failed validation." == job .error_message
1425
+ UserUpload .objects .filter (pk = file_upload .pk ).exists ()
1426
+ == upload_exists
1400
1427
)
1401
- assert job .detailed_error_message == {
1402
- algorithm_with_multiple_inputs .ci_json_file .title : "JSON does not fulfill schema: instance is not of type 'array'"
1403
- }
1404
1428
# and no CIVs should have been created
1405
- assert ComponentInterfaceValue .objects .count () == 0
1429
+ assert ComponentInterfaceValue .objects .count () == ci_count
1406
1430
1407
1431
@override_settings (task_eager_propagates = True , task_always_eager = True )
1408
1432
def test_create_job_with_faulty_json_input (
0 commit comments