21
21
from rapyuta_io .utils import ObjDict , InvalidCommandException
22
22
from tests .utils .client import get_client , headers
23
23
from tests .utils .device_respones import DEVICE_LIST , DEVICE_INFO , DEVICE_LIST_EMPTY , \
24
- DEVICE_NOT_FOUND , EXECUTE_COMMAND_BAD_REQUEST , EXECUTE_COMMAND_OK , DELETE_DEVICE_BAD_REQUEST , \
24
+ DEVICE_NOT_FOUND , EXECUTE_COMMAND_BAD_REQUEST , EXECUTE_COMMAND_OK , EXECUTE_COMMAND_OK_BG , DELETE_DEVICE_BAD_REQUEST , \
25
25
DELETE_DEVICE_OK , UPDATE_DEVICE_BAD_REQUEST , UPDATE_DEVICE_OK , DEVICE_SELECTION , APPLY_PARAMETERS_SUCCESS_RESPONSE , \
26
26
CREATE_DIRECT_LINK_SUCCESS_RESPONSE , CREATE_DOCKERCOMPOSE_DEVICE_SUCCESS , GET_DOCKERCOMPOSE_DEVICE_SUCCESS , \
27
27
CREATE_PREINSTALLED_DEVICE_SUCCESS , GET_PREINSTALLED_DEVICE_SUCCESS , UPGRADE_DOCKERCOMPOSE_DEVICE_SUCCESS , \
@@ -276,8 +276,31 @@ def test_execute_command_ok(self, mock_execute, get_device_response):
276
276
command .cwd = ''
277
277
result = device .execute_command (command )
278
278
self .assertEqual (mock_execute .call_count , 2 )
279
- expected = 'Linux rapyuta 4.9.80-v7+ #1098 SMP Fri Mar 9 19:11:42 GMT2018 armv7l ' \
280
- 'armv7l armv7l GNU/Linux'
279
+ expected = {'test_device_id' :'Linux rapyuta 4.9.80-v7+ #1098 SMP Fri Mar 9 19:11:42 GMT2018 armv7l ' \
280
+ 'armv7l armv7l GNU/Linux' }
281
+ self .assertEqual (result , expected )
282
+
283
+ @patch ('requests.Response' , spec = Response )
284
+ @patch ('rapyuta_io.utils.rest_client.RestClient.execute' )
285
+ def test_execute_command_ok_background (self , mock_execute , get_device_response ):
286
+ get_device_response .text = DEVICE_INFO
287
+ get_device_response .status_code = requests .codes .OK
288
+ execute_command_response = get_device_response ()
289
+ execute_command_response .text = EXECUTE_COMMAND_OK_BG
290
+ execute_command_response .status_code = requests .codes .OK
291
+ mock_execute .side_effect = [get_device_response , execute_command_response ]
292
+ mock_execute .return_value = get_device_response
293
+ client = get_client ()
294
+ device = client .get_device ('test_device_id' )
295
+ self .assertIsInstance (device , Device , 'Object should be an instance of class Device' )
296
+ command = Command ('uname -a' )
297
+ command .shell = '/bin/bash'
298
+ command .bg = True
299
+ command .runas = 'root'
300
+ command .cwd = ''
301
+ result = device .execute_command (command )
302
+ self .assertEqual (mock_execute .call_count , 2 )
303
+ expected = {'test_device_id' :'SUCCESS' }
281
304
self .assertEqual (result , expected )
282
305
283
306
def test_execute_command_invalid_parameters (self ):
@@ -300,6 +323,12 @@ def test_execute_command_invalid_parameters(self):
300
323
'value' : 'true' ,
301
324
'correct_value' : False
302
325
},
326
+ {
327
+ 'response' : 'Invalid run asynchronous option' ,
328
+ 'key' : 'run_async' ,
329
+ 'value' : 'true' ,
330
+ 'correct_value' : False
331
+ },
303
332
{
304
333
'response' : 'Invalid runas option' ,
305
334
'key' : 'runas' ,
0 commit comments