@@ -79,7 +79,7 @@ def test_algorithm_relations_on_job_serializer(rf):
79
79
True ,
80
80
("TestInterface 1" , "TestInterface 2" ),
81
81
("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 ." ,
83
83
False ,
84
84
),
85
85
(
@@ -88,7 +88,7 @@ def test_algorithm_relations_on_job_serializer(rf):
88
88
True ,
89
89
("TestInterface 1" ,),
90
90
("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. " ,
92
92
False ,
93
93
),
94
94
(
@@ -164,8 +164,7 @@ def test_algorithm_job_post_serializer_validations(
164
164
job = {
165
165
"algorithm" : algorithm_image .algorithm .api_url ,
166
166
"inputs" : [
167
- {"interface" : interface , "value" : "dummy" }
168
- for interface in job_interface_slugs
167
+ {"interface" : int , "value" : "dummy" } for int in job_interface_slugs
169
168
],
170
169
}
171
170
@@ -233,8 +232,22 @@ def test_algorithm_job_post_serializer_create(
233
232
request .user = user
234
233
serializer = JobPostSerializer (data = job , context = {"request" : request })
235
234
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
+
237
249
assert serializer .is_valid ()
250
+
238
251
# fake successful upload
239
252
upload .status = RawImageUploadSession .SUCCESS
240
253
upload .save ()
@@ -245,6 +258,7 @@ def test_algorithm_job_post_serializer_create(
245
258
job = Job .objects .first ()
246
259
assert job .creator == user
247
260
assert len (job .inputs .all ()) == 3
261
+ assert job .algorithm_interface == interface
248
262
249
263
250
264
@pytest .mark .django_db
@@ -296,13 +310,20 @@ def test_form_valid_for_editor(self, rf, settings):
296
310
user = UserFactory ()
297
311
298
312
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
+ )
299
318
300
319
request = rf .get ("/foo" )
301
320
request .user = user
302
321
serializer = JobPostSerializer (
303
322
data = {
304
323
"algorithm" : algorithm_image .algorithm .api_url ,
305
- "inputs" : [],
324
+ "inputs" : [
325
+ {"interface" : ci .slug , "value" : "foo" },
326
+ ],
306
327
},
307
328
context = {"request" : request },
308
329
)
@@ -319,7 +340,9 @@ def test_form_valid_for_editor(self, rf, settings):
319
340
serializer = JobPostSerializer (
320
341
data = {
321
342
"algorithm" : algorithm_image .algorithm .api_url ,
322
- "inputs" : [],
343
+ "inputs" : [
344
+ {"interface" : ci .slug , "value" : "foo" },
345
+ ],
323
346
},
324
347
context = {"request" : request },
325
348
)
@@ -337,13 +360,20 @@ def test_form_valid_with_credits(self, rf):
337
360
user = UserFactory ()
338
361
339
362
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
+ )
340
368
341
369
request = rf .get ("/foo" )
342
370
request .user = user
343
371
serializer = JobPostSerializer (
344
372
data = {
345
373
"algorithm" : algorithm_image .algorithm .api_url ,
346
- "inputs" : [],
374
+ "inputs" : [
375
+ {"interface" : ci .slug , "value" : "foo" },
376
+ ],
347
377
},
348
378
context = {"request" : request },
349
379
)
0 commit comments