@@ -177,7 +177,7 @@ def test_get_agent_status(self):
177177 self .assertEqual (data ['started_at' ], status .started_at )
178178 self .assertEqual (data ['version' ], status .version )
179179
180- def test_execute_agent_command_success (self ):
180+ def test_execute_agent_command_success_no_wait (self ):
181181 command = {
182182 'name' : 'do_things' ,
183183 'params' : {'key' : 'value' },
@@ -190,7 +190,10 @@ def test_execute_agent_command_success(self):
190190
191191 self .mock_agent .execute_command .return_value = result
192192
193- response = self .post_json ('/commands' , command )
193+ with mock .patch .object (result , 'join' ) as join_mock :
194+ response = self .post_json ('/commands' , command )
195+ self .assertFalse (join_mock .called )
196+
194197 self .assertEqual (response .status_code , 200 )
195198
196199 self .assertEqual (self .mock_agent .execute_command .call_count , 1 )
@@ -201,6 +204,58 @@ def test_execute_agent_command_success(self):
201204 data = response .json
202205 self .assertEqual (data , expected_result )
203206
207+ def test_execute_agent_command_success_with_true_wait (self ):
208+ command = {
209+ 'name' : 'do_things' ,
210+ 'params' : {'key' : 'value' },
211+ }
212+
213+ result = base .SyncCommandResult (command ['name' ],
214+ command ['params' ],
215+ True ,
216+ {'test' : 'result' })
217+
218+ self .mock_agent .execute_command .return_value = result
219+
220+ with mock .patch .object (result , 'join' ) as join_mock :
221+ response = self .post_json ('/commands?wait=true' , command )
222+ join_mock .assert_called_once_with ()
223+
224+ self .assertEqual (response .status_code , 200 )
225+ self .assertEqual (self .mock_agent .execute_command .call_count , 1 )
226+ args , kwargs = self .mock_agent .execute_command .call_args
227+ self .assertEqual (args , ('do_things' ,))
228+ self .assertEqual (kwargs , {'key' : 'value' })
229+ expected_result = result .serialize ()
230+ data = response .json
231+ self .assertEqual (data , expected_result )
232+
233+ def test_execute_agent_command_success_with_false_wait (self ):
234+ command = {
235+ 'name' : 'do_things' ,
236+ 'params' : {'key' : 'value' },
237+ }
238+
239+ result = base .SyncCommandResult (command ['name' ],
240+ command ['params' ],
241+ True ,
242+ {'test' : 'result' })
243+
244+ self .mock_agent .execute_command .return_value = result
245+
246+ with mock .patch .object (result , 'join' ) as join_mock :
247+ response = self .post_json ('/commands?wait=false' , command )
248+ self .assertFalse (join_mock .called )
249+
250+ self .assertEqual (response .status_code , 200 )
251+ self .assertEqual (self .mock_agent .execute_command .call_count , 1 )
252+ args , kwargs = self .mock_agent .execute_command .call_args
253+ self .assertEqual (args , ('do_things' ,))
254+ self .assertEqual (kwargs , {'key' : 'value' })
255+ expected_result = result .serialize ()
256+ data = response .json
257+ self .assertEqual (data , expected_result )
258+
204259 def test_execute_agent_command_validation (self ):
205260 invalid_command = {}
206261 response = self .post_json ('/commands' ,
0 commit comments