@@ -250,3 +250,59 @@ async def test_command_logging(mock_flow, caplog, log_filter):
250
250
await mock_flow .resolvers ._mutation_mapper ("put_messages" , kwargs , meta )
251
251
assert log_filter (
252
252
caplog , contains = 'Command "put_messages" received from Dr Spock' )
253
+
254
+
255
+ async def test_command_validation_failure (
256
+ mock_flow ,
257
+ caplog ,
258
+ flow_args ,
259
+ monkeypatch ,
260
+ ):
261
+ """It should log command validation failures server side."""
262
+ caplog .set_level (logging .DEBUG , None )
263
+ flow_args ['workflows' ].append (
264
+ {
265
+ 'user' : mock_flow .owner ,
266
+ 'workflow' : mock_flow .name ,
267
+ 'workflow_sel' : None ,
268
+ }
269
+ )
270
+
271
+ # submit a command with invalid arguments:
272
+ async def submit_invalid_command (verbosity = 0 ):
273
+ nonlocal caplog , mock_flow , flow_args
274
+ monkeypatch .setattr ('cylc.flow.flags.verbosity' , verbosity )
275
+ caplog .clear ()
276
+ return await mock_flow .resolvers .mutator (
277
+ None ,
278
+ 'stop' ,
279
+ flow_args ,
280
+ {'task' : 'cycle/task/job' , 'mode' : 'not-a-mode' },
281
+ {},
282
+ )
283
+
284
+ # submitting the invalid command should result in this error
285
+ msg = 'This command does not take job ids:\n * cycle/task/job'
286
+
287
+ # test submitting the command at *default* verbosity
288
+ response = await submit_invalid_command ()
289
+
290
+ # the error should be sent back to the client:
291
+ assert response [0 ]['response' ][1 ] == msg
292
+ # it should also be logged by the server:
293
+ assert caplog .records [- 1 ].levelno == logging .WARNING
294
+ assert msg in caplog .records [- 1 ].message
295
+
296
+ # test submitting the command at *debug* verbosity
297
+ response = await submit_invalid_command (verbosity = 2 )
298
+
299
+ # the error should be sent back to the client:
300
+ assert response [0 ]['response' ][1 ] == msg
301
+ # it should be logged at the server
302
+ assert caplog .records [- 2 ].levelno == logging .WARNING
303
+ assert msg in caplog .records [- 2 ].message
304
+ # the traceback should also be logged
305
+ # (note traceback gets logged at the ERROR level and shows up funny in
306
+ # caplog)
307
+ assert caplog .records [- 1 ].levelno == logging .ERROR
308
+ assert msg in caplog .records [- 1 ].message
0 commit comments