Skip to content

Commit 616ba99

Browse files
committed
test job creation with file input
1 parent ea8b841 commit 616ba99

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

app/tests/algorithms_tests/test_views.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
)
2727
from grandchallenge.components.schemas import GPUTypeChoices
2828
from grandchallenge.subdomains.utils import reverse
29+
from grandchallenge.uploads.models import UserUpload
2930
from tests.algorithms_tests.factories import (
3031
AlgorithmFactory,
3132
AlgorithmImageFactory,
@@ -1357,11 +1358,34 @@ def test_create_job_is_idempotent(
13571358
assert Job.objects.count() == 1
13581359

13591360
@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(
13611379
self,
13621380
client,
13631381
django_capture_on_commit_callbacks,
13641382
algorithm_with_multiple_inputs,
1383+
file_json_content,
1384+
error_message,
1385+
detailed_error_message,
1386+
ci_count,
1387+
upload_exists,
1388+
job_status,
13651389
):
13661390
# configure file input
13671391
algorithm_with_multiple_inputs.algorithm.inputs.set(
@@ -1371,7 +1395,7 @@ def test_create_job_with_faulty_file_input(
13711395
filename="file.json", creator=algorithm_with_multiple_inputs.editor
13721396
)
13731397
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)
13751399
file_upload.complete_multipart_upload(
13761400
parts=[{"ETag": response.headers["ETag"], "PartNumber": 1}]
13771401
)
@@ -1394,15 +1418,15 @@ def test_create_job_with_faulty_file_input(
13941418
assert Job.objects.count() == 1
13951419
job = Job.objects.get()
13961420
# 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
13981424
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
14001427
)
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-
}
14041428
# and no CIVs should have been created
1405-
assert ComponentInterfaceValue.objects.count() == 0
1429+
assert ComponentInterfaceValue.objects.count() == ci_count
14061430

14071431
@override_settings(task_eager_propagates=True, task_always_eager=True)
14081432
def test_create_job_with_faulty_json_input(

app/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ def algorithm_with_multiple_inputs():
548548
},
549549
)
550550
ci_json_file = ComponentInterfaceFactory(
551+
title="ci_json_file",
551552
kind=InterfaceKind.InterfaceKindChoices.ANY,
552553
store_in_database=False,
553554
schema={

0 commit comments

Comments
 (0)