Skip to content

Commit f8d140e

Browse files
committed
🚨 test(device): add test case for invalid run_async option
1 parent f8d473d commit f8d140e

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

‎tests/device_test.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from rapyuta_io.utils import ObjDict, InvalidCommandException
2222
from tests.utils.client import get_client, headers
2323
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, \
2525
DELETE_DEVICE_OK, UPDATE_DEVICE_BAD_REQUEST, UPDATE_DEVICE_OK, DEVICE_SELECTION, APPLY_PARAMETERS_SUCCESS_RESPONSE, \
2626
CREATE_DIRECT_LINK_SUCCESS_RESPONSE, CREATE_DOCKERCOMPOSE_DEVICE_SUCCESS, GET_DOCKERCOMPOSE_DEVICE_SUCCESS, \
2727
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):
276276
command.cwd = ''
277277
result = device.execute_command(command)
278278
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'}
281304
self.assertEqual(result, expected)
282305

283306
def test_execute_command_invalid_parameters(self):
@@ -300,6 +323,12 @@ def test_execute_command_invalid_parameters(self):
300323
'value': 'true',
301324
'correct_value': False
302325
},
326+
{
327+
'response': 'Invalid run asynchronous option',
328+
'key': 'run_async',
329+
'value': 'true',
330+
'correct_value': False
331+
},
303332
{
304333
'response': 'Invalid runas option',
305334
'key': 'runas',

‎tests/utils/device_respones.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@
523523
"data": { "test_device_id": "Linux rapyuta 4.9.80-v7+ #1098 SMP Fri Mar 9\
524524
19:11:42 GMT2018 armv7l armv7l armv7l GNU/Linux" } } } '''
525525

526+
EXECUTE_COMMAND_OK_BG = ''' {
527+
"status": "success",
528+
"response": {
529+
"data": { "test_device_id": "SUCCESS" } } } '''
530+
526531
EXECUTE_COMMAND_BAD_REQUEST = ''' {
527532
"status": "error",
528533
"response": { "data": {}, "error": "device_ids parameter missing" } } '''

0 commit comments

Comments
 (0)