@@ -286,3 +286,104 @@ async def test_registers_json_set_invalid_value(self, client, simulator):
286
286
assert "error" in json_response
287
287
# Do not check for error content. It is currently
288
288
# unhandled, so it is not guaranteed to be consistent.
289
+
290
+ @pytest .mark .parametrize ("response_type" , [
291
+ http_server .RESPONSE_NORMAL ,
292
+ http_server .RESPONSE_ERROR ,
293
+ http_server .RESPONSE_EMPTY ,
294
+ http_server .RESPONSE_JUNK
295
+ ])
296
+ @pytest .mark .parametrize ("call" , [
297
+ ("split_delay" , 1 ),
298
+ ("response_cr_pct" , 1 ),
299
+ ("response_delay" , 1 ),
300
+ ("response_error" , 1 ),
301
+ ("response_junk_datalen" , 1 ),
302
+ ("response_clear_after" , 1 ),
303
+ ])
304
+ @pytest .mark .asyncio ()
305
+ async def test_calls_json_simulate (self , client , simulator , response_type , call ):
306
+ """
307
+ Test all the simulation calls to make sure they are started and no errors are raised.
308
+
309
+ Some have extra parameters, others don't
310
+ """
311
+ url = f"http://{ simulator .http_host } :{ simulator .http_port } /api/calls_json"
312
+
313
+ # The default arguments which must be present in the request
314
+ data = {
315
+ "submit" : "Simulate" ,
316
+ "response_type" : response_type ,
317
+ "response_split" : "nomatter" ,
318
+ "split_delay" : 0 ,
319
+ "response_cr" : "nomatter" ,
320
+ "response_cr_pct" : 0 ,
321
+ "response_delay" : 0 ,
322
+ "response_error" : 0 ,
323
+ "response_junk_datalen" : 0 ,
324
+ "response_clear_after" : 0 ,
325
+ }
326
+
327
+ # Change the value of one call based on the parameter
328
+ data [call [0 ]] = call [1 ]
329
+
330
+ async with client .post (url , json = data ) as resp :
331
+ assert resp .status == 200
332
+
333
+ json_response = await resp .json ()
334
+ assert json_response ["result" ] == "ok"
335
+
336
+
337
+ @pytest .mark .asyncio ()
338
+ async def test_calls_json_simulate_reset_no_simulation (self , client , simulator ):
339
+ """
340
+ Test the /api/calls_json endpoint with a reset request.
341
+
342
+ Just make sure that there will be no error when resetting without triggering
343
+ a simulation.
344
+ """
345
+ url = f"http://{ simulator .http_host } :{ simulator .http_port } /api/calls_json"
346
+
347
+ data = {
348
+ "submit" : "Reset" ,
349
+ }
350
+
351
+ async with client .post (url , json = data ) as resp :
352
+ assert resp .status == 200
353
+
354
+ json_response = await resp .json ()
355
+ assert json_response ["result" ] == "ok"
356
+
357
+ @pytest .mark .asyncio ()
358
+ async def test_calls_json_simulate_reset_with_simulation (self , client , simulator ):
359
+ """Test the /api/calls_json endpoint with a reset request after a simulation."""
360
+ url = f"http://{ simulator .http_host } :{ simulator .http_port } /api/calls_json"
361
+
362
+ data = {
363
+ "submit" : "Simulate" ,
364
+ "response_type" : http_server .RESPONSE_EMPTY ,
365
+ "response_split" : "nomatter" ,
366
+ "split_delay" : 0 ,
367
+ "response_cr" : "nomatter" ,
368
+ "response_cr_pct" : 0 ,
369
+ "response_delay" : 100 ,
370
+ "response_error" : 0 ,
371
+ "response_junk_datalen" : 0 ,
372
+ "response_clear_after" : 0 ,
373
+ }
374
+
375
+ async with client .post (url , json = data ) as resp :
376
+ assert resp .status == 200
377
+
378
+ json_response = await resp .json ()
379
+ assert json_response ["result" ] == "ok"
380
+
381
+ data = {
382
+ "submit" : "Reset" ,
383
+ }
384
+
385
+ async with client .post (url , json = data ) as resp :
386
+ assert resp .status == 200
387
+
388
+ json_response = await resp .json ()
389
+ assert json_response ["result" ] == "ok"
0 commit comments