Skip to content

Commit

Permalink
test job creation with file input
Browse files Browse the repository at this point in the history
  • Loading branch information
ammar257ammar committed Dec 20, 2024
1 parent ea8b841 commit 616ba99
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
40 changes: 32 additions & 8 deletions app/tests/algorithms_tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)
from grandchallenge.components.schemas import GPUTypeChoices
from grandchallenge.subdomains.utils import reverse
from grandchallenge.uploads.models import UserUpload
from tests.algorithms_tests.factories import (
AlgorithmFactory,
AlgorithmImageFactory,
Expand Down Expand Up @@ -1357,11 +1358,34 @@ def test_create_job_is_idempotent(
assert Job.objects.count() == 1

@override_settings(task_eager_propagates=True, task_always_eager=True)
def test_create_job_with_faulty_file_input(
@pytest.mark.django_db
@pytest.mark.parametrize(
"file_json_content,job_status,error_message,detailed_error_message,ci_count,upload_exists",
[
(
b'{"Foo": "bar"}',
Job.CANCELLED,
"One or more of the inputs failed validation.",
{
"ci_json_file": "JSON does not fulfill schema: instance is not of type 'array'"
},
0,
True,
),
(b'[{"Foo": "bar"}]', Job.PROVISIONED, "", {}, 1, False),
],
)
def test_create_job_with_file_input(
self,
client,
django_capture_on_commit_callbacks,
algorithm_with_multiple_inputs,
file_json_content,
error_message,
detailed_error_message,
ci_count,
upload_exists,
job_status,
):
# configure file input
algorithm_with_multiple_inputs.algorithm.inputs.set(
Expand All @@ -1371,7 +1395,7 @@ def test_create_job_with_faulty_file_input(
filename="file.json", creator=algorithm_with_multiple_inputs.editor
)
presigned_urls = file_upload.generate_presigned_urls(part_numbers=[1])
response = put(presigned_urls["1"], data=b'{"Foo": "bar"}')
response = put(presigned_urls["1"], data=file_json_content)
file_upload.complete_multipart_upload(
parts=[{"ETag": response.headers["ETag"], "PartNumber": 1}]
)
Expand All @@ -1394,15 +1418,15 @@ def test_create_job_with_faulty_file_input(
assert Job.objects.count() == 1
job = Job.objects.get()
# but in cancelled state and with an error message
assert job.status == Job.CANCELLED
assert job.status == job_status
assert error_message == job.error_message
assert job.detailed_error_message == detailed_error_message
assert (
"One or more of the inputs failed validation." == job.error_message
UserUpload.objects.filter(pk=file_upload.pk).exists()
== upload_exists
)
assert job.detailed_error_message == {
algorithm_with_multiple_inputs.ci_json_file.title: "JSON does not fulfill schema: instance is not of type 'array'"
}
# and no CIVs should have been created
assert ComponentInterfaceValue.objects.count() == 0
assert ComponentInterfaceValue.objects.count() == ci_count

@override_settings(task_eager_propagates=True, task_always_eager=True)
def test_create_job_with_faulty_json_input(
Expand Down
1 change: 1 addition & 0 deletions app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ def algorithm_with_multiple_inputs():
},
)
ci_json_file = ComponentInterfaceFactory(
title="ci_json_file",
kind=InterfaceKind.InterfaceKindChoices.ANY,
store_in_database=False,
schema={
Expand Down

0 comments on commit 616ba99

Please sign in to comment.