@@ -30,7 +30,19 @@ def test_monitor_error():
3030 _test_monitor (["not-a-command" ], 127 )
3131
3232
33- def _test_monitor (command , return_code ):
33+ @mock .patch .dict (os .environ , {
34+ "TASKBADGER_ORG" : "org" ,
35+ "TASKBADGER_PROJECT" : "project" ,
36+ "TASKBADGER_TOKEN" : "token" ,
37+ }, clear = True )
38+ def test_monitor_action ():
39+ _test_monitor (
40+ ["echo" , "test" ], 0 , ["-a" , "success,error" , "email" , "to:me@test.com" ],
41+ action = {'trigger' : 'success,error' , 'integration' : 'email' , 'config' : {'to' : 'me@test.com' }}
42+ )
43+
44+
45+ def _test_monitor (command , return_code , args = None , action = None ):
3446 with (
3547 mock .patch ("taskbadger.sdk.task_create.sync_detailed" ) as create ,
3648 mock .patch ("taskbadger.sdk.task_partial_update.sync_detailed" ) as update
@@ -39,15 +51,21 @@ def _test_monitor(command, return_code):
3951 create .return_value = Response (HTTPStatus .OK , b"" , {}, task )
4052
4153 update .return_value = Response (HTTPStatus .OK , b"" , {}, task )
42- result = runner .invoke (app , ["monitor" , "task_name" , "--" ] + command )
54+ args = args or []
55+ result = runner .invoke (app , ["monitor" , "task_name" ] + args + ["--" ] + command )
4356 assert result .exit_code == return_code
4457
4558 settings = _get_settings ()
59+ request = TaskRequest (name = "task_name" , status = StatusEnum .PENDING )
60+ if action :
61+ request .additional_properties = {
62+ 'actions' : [action ]
63+ }
4664 create .assert_called_with (
4765 client = settings .client ,
4866 organization_slug = "org" ,
4967 project_slug = "project" ,
50- json_body = TaskRequest ( name = "task_name" , status = StatusEnum . PENDING )
68+ json_body = request
5169 )
5270
5371 if return_code == 0 :
0 commit comments