@@ -247,3 +247,143 @@ async def test_mock_generic_as_none(self):
247
247
self .assertEqual (
248
248
r .response .return_value ,
249
249
protos .TypedData (string = "hello" ))
250
+
251
+ async def test_mock_generic_return_dict (self ):
252
+ async with testutils .start_mockhost (
253
+ script_root = self .generic_funcs_dir ) as host :
254
+
255
+ await host .init_worker ("4.17.1" )
256
+ func_id , r = await host .load_function ('foobar_return_dict' )
257
+
258
+ self .assertEqual (r .response .function_id , func_id )
259
+ self .assertEqual (r .response .result .status ,
260
+ protos .StatusResult .Success )
261
+
262
+ _ , r = await host .invoke_function (
263
+ 'foobar_return_dict' , [
264
+ protos .ParameterBinding (
265
+ name = 'input' ,
266
+ data = protos .TypedData (
267
+ string = 'test'
268
+ )
269
+ )
270
+ ]
271
+ )
272
+ self .assertEqual (r .response .result .status ,
273
+ protos .StatusResult .Success )
274
+ self .assertEqual (
275
+ r .response .return_value ,
276
+ protos .TypedData (json = "{\" hello\" : \" world\" }" )
277
+ )
278
+
279
+ async def test_mock_generic_return_list (self ):
280
+ async with testutils .start_mockhost (
281
+ script_root = self .generic_funcs_dir ) as host :
282
+
283
+ await host .init_worker ("4.17.1" )
284
+ func_id , r = await host .load_function ('foobar_return_list' )
285
+
286
+ self .assertEqual (r .response .function_id , func_id )
287
+ self .assertEqual (r .response .result .status ,
288
+ protos .StatusResult .Success )
289
+
290
+ _ , r = await host .invoke_function (
291
+ 'foobar_return_list' , [
292
+ protos .ParameterBinding (
293
+ name = 'input' ,
294
+ data = protos .TypedData (
295
+ string = 'test'
296
+ )
297
+ )
298
+ ]
299
+ )
300
+ self .assertEqual (r .response .result .status ,
301
+ protos .StatusResult .Success )
302
+ self .assertEqual (
303
+ r .response .return_value ,
304
+ protos .TypedData (json = "[1, 2, 3]" )
305
+ )
306
+
307
+ async def test_mock_generic_return_int (self ):
308
+ async with testutils .start_mockhost (
309
+ script_root = self .generic_funcs_dir ) as host :
310
+
311
+ await host .init_worker ("4.17.1" )
312
+ func_id , r = await host .load_function ('foobar_return_int' )
313
+
314
+ self .assertEqual (r .response .function_id , func_id )
315
+ self .assertEqual (r .response .result .status ,
316
+ protos .StatusResult .Success )
317
+
318
+ _ , r = await host .invoke_function (
319
+ 'foobar_return_int' , [
320
+ protos .ParameterBinding (
321
+ name = 'input' ,
322
+ data = protos .TypedData (
323
+ string = 'test'
324
+ )
325
+ )
326
+ ]
327
+ )
328
+ self .assertEqual (r .response .result .status ,
329
+ protos .StatusResult .Success )
330
+ self .assertEqual (
331
+ r .response .return_value ,
332
+ protos .TypedData (int = 12 )
333
+ )
334
+
335
+ async def test_mock_generic_return_double (self ):
336
+ async with testutils .start_mockhost (
337
+ script_root = self .generic_funcs_dir ) as host :
338
+
339
+ await host .init_worker ("4.17.1" )
340
+ func_id , r = await host .load_function ('foobar_return_double' )
341
+
342
+ self .assertEqual (r .response .function_id , func_id )
343
+ self .assertEqual (r .response .result .status ,
344
+ protos .StatusResult .Success )
345
+
346
+ _ , r = await host .invoke_function (
347
+ 'foobar_return_double' , [
348
+ protos .ParameterBinding (
349
+ name = 'input' ,
350
+ data = protos .TypedData (
351
+ string = 'test'
352
+ )
353
+ )
354
+ ]
355
+ )
356
+ self .assertEqual (r .response .result .status ,
357
+ protos .StatusResult .Success )
358
+ self .assertEqual (
359
+ r .response .return_value ,
360
+ protos .TypedData (double = 12.34 )
361
+ )
362
+
363
+ async def test_mock_generic_return_bool (self ):
364
+ async with testutils .start_mockhost (
365
+ script_root = self .generic_funcs_dir ) as host :
366
+
367
+ await host .init_worker ("4.17.1" )
368
+ func_id , r = await host .load_function ('foobar_return_bool' )
369
+
370
+ self .assertEqual (r .response .function_id , func_id )
371
+ self .assertEqual (r .response .result .status ,
372
+ protos .StatusResult .Success )
373
+
374
+ _ , r = await host .invoke_function (
375
+ 'foobar_return_bool' , [
376
+ protos .ParameterBinding (
377
+ name = 'input' ,
378
+ data = protos .TypedData (
379
+ string = 'test'
380
+ )
381
+ )
382
+ ]
383
+ )
384
+ self .assertEqual (r .response .result .status ,
385
+ protos .StatusResult .Success )
386
+ self .assertEqual (
387
+ r .response .return_value ,
388
+ protos .TypedData (int = 1 )
389
+ )
0 commit comments