Skip to content

Commit d1b829b

Browse files
committed
Fix tests
1 parent d94744d commit d1b829b

File tree

3 files changed

+52
-23
lines changed

3 files changed

+52
-23
lines changed

app/tests/algorithms_tests/test_api.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,9 @@ def test_create_job_with_multiple_new_inputs(
221221
pk=algorithm_with_multiple_inputs.file_upload.pk
222222
).exists()
223223

224-
assert sorted(
225-
[
226-
int.pk
227-
for int in algorithm_with_multiple_inputs.algorithm.inputs.all()
228-
]
229-
) == sorted([civ.interface.pk for civ in job.inputs.all()])
224+
assert sorted([int.pk for int in interface.inputs.all()]) == sorted(
225+
[civ.interface.pk for civ in job.inputs.all()]
226+
)
230227

231228
value_inputs = [civ.value for civ in job.inputs.all() if civ.value]
232229
assert "Foo" in value_inputs

app/tests/algorithms_tests/test_permissions.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,21 +353,23 @@ def test_job_permissions_from_api(self, rf):
353353
is_in_registry=True,
354354
is_desired_version=True,
355355
)
356-
interfaces = {
357-
ComponentInterfaceFactory(
358-
kind=ComponentInterface.Kind.STRING,
359-
title="TestInterface 1",
360-
default_value="default",
361-
),
362-
}
363-
interface = AlgorithmInterfaceFactory(inputs=[interfaces])
356+
ci = ComponentInterfaceFactory(
357+
kind=ComponentInterface.Kind.STRING,
358+
title="TestInterface 1",
359+
default_value="default",
360+
)
361+
362+
interface = AlgorithmInterfaceFactory(inputs=[ci])
364363
algorithm_image.algorithm.interfaces.add(
365364
interface, through_defaults={"is_default": True}
366365
)
367366
algorithm_image.algorithm.add_user(user)
368367
algorithm_image.algorithm.add_editor(UserFactory())
369368

370-
job = {"algorithm": algorithm_image.algorithm.api_url, "inputs": []}
369+
job = {
370+
"algorithm": algorithm_image.algorithm.api_url,
371+
"inputs": [{"interface": ci.slug, "value": "foo"}],
372+
}
371373

372374
# test
373375
request = rf.get("/foo")

app/tests/algorithms_tests/test_serializers.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_algorithm_relations_on_job_serializer(rf):
7979
True,
8080
("TestInterface 1", "TestInterface 2"),
8181
("testinterface-1",),
82-
"Interface(s) TestInterface 2 do not have a default value and should be provided.",
82+
"The set of inputs provided does not match any of the algorithm's interfaces.",
8383
False,
8484
),
8585
(
@@ -88,7 +88,7 @@ def test_algorithm_relations_on_job_serializer(rf):
8888
True,
8989
("TestInterface 1",),
9090
("testinterface-1", "testinterface-2"),
91-
"Provided inputs(s) TestInterface 2 are not defined for this algorithm",
91+
"The set of inputs provided does not match any of the algorithm's interfaces.",
9292
False,
9393
),
9494
(
@@ -164,8 +164,7 @@ def test_algorithm_job_post_serializer_validations(
164164
job = {
165165
"algorithm": algorithm_image.algorithm.api_url,
166166
"inputs": [
167-
{"interface": interface, "value": "dummy"}
168-
for interface in job_interface_slugs
167+
{"interface": int, "value": "dummy"} for int in job_interface_slugs
169168
],
170169
}
171170

@@ -233,8 +232,22 @@ def test_algorithm_job_post_serializer_create(
233232
request.user = user
234233
serializer = JobPostSerializer(data=job, context={"request": request})
235234

236-
# verify
235+
# all inputs need to be provided, also those with default value
236+
assert not serializer.is_valid()
237+
238+
# add missing input
239+
job = {
240+
"algorithm": algorithm_image.algorithm.api_url,
241+
"inputs": [
242+
{"interface": ci_img1.slug, "upload_session": upload.api_url},
243+
{"interface": ci_img2.slug, "image": image2.api_url},
244+
{"interface": ci_string.slug, "value": "foo"},
245+
],
246+
}
247+
serializer = JobPostSerializer(data=job, context={"request": request})
248+
237249
assert serializer.is_valid()
250+
238251
# fake successful upload
239252
upload.status = RawImageUploadSession.SUCCESS
240253
upload.save()
@@ -245,6 +258,7 @@ def test_algorithm_job_post_serializer_create(
245258
job = Job.objects.first()
246259
assert job.creator == user
247260
assert len(job.inputs.all()) == 3
261+
assert job.algorithm_interface == interface
248262

249263

250264
@pytest.mark.django_db
@@ -296,13 +310,20 @@ def test_form_valid_for_editor(self, rf, settings):
296310
user = UserFactory()
297311

298312
algorithm_image.algorithm.add_editor(user=user)
313+
ci = ComponentInterfaceFactory(kind=ComponentInterface.Kind.STRING)
314+
interface = AlgorithmInterfaceFactory(inputs=[ci])
315+
algorithm_image.algorithm.interfaces.add(
316+
interface, through_defaults={"is_default": True}
317+
)
299318

300319
request = rf.get("/foo")
301320
request.user = user
302321
serializer = JobPostSerializer(
303322
data={
304323
"algorithm": algorithm_image.algorithm.api_url,
305-
"inputs": [],
324+
"inputs": [
325+
{"interface": ci.slug, "value": "foo"},
326+
],
306327
},
307328
context={"request": request},
308329
)
@@ -319,7 +340,9 @@ def test_form_valid_for_editor(self, rf, settings):
319340
serializer = JobPostSerializer(
320341
data={
321342
"algorithm": algorithm_image.algorithm.api_url,
322-
"inputs": [],
343+
"inputs": [
344+
{"interface": ci.slug, "value": "foo"},
345+
],
323346
},
324347
context={"request": request},
325348
)
@@ -337,13 +360,20 @@ def test_form_valid_with_credits(self, rf):
337360
user = UserFactory()
338361

339362
algorithm_image.algorithm.add_user(user=user)
363+
ci = ComponentInterfaceFactory(kind=ComponentInterface.Kind.STRING)
364+
interface = AlgorithmInterfaceFactory(inputs=[ci])
365+
algorithm_image.algorithm.interfaces.add(
366+
interface, through_defaults={"is_default": True}
367+
)
340368

341369
request = rf.get("/foo")
342370
request.user = user
343371
serializer = JobPostSerializer(
344372
data={
345373
"algorithm": algorithm_image.algorithm.api_url,
346-
"inputs": [],
374+
"inputs": [
375+
{"interface": ci.slug, "value": "foo"},
376+
],
347377
},
348378
context={"request": request},
349379
)

0 commit comments

Comments
 (0)