Skip to content

Commit

Permalink
require online device when allocate (#13)
Browse files Browse the repository at this point in the history
status: 3 = online
  • Loading branch information
jupe authored Jul 5, 2021
1 parent 1b69f7c commit 6a1ff66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 4 additions & 2 deletions stf_appium_client/StfClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def get_devices(self, fields: list = []) -> list:
NotConnectedError.invariant(self._client, 'Not connected')
fields.extend([
'present', 'ready', 'using', 'owner', 'marketName',
'serial', 'manufacturer', 'model', 'platform', 'sdk', 'version'
'serial', 'manufacturer', 'model', 'platform', 'sdk', 'version',
'status'
])
self.logger.debug('stf: get devices..')
req, resp = self._app.op['getDevices'](fields=','.join(fields))
Expand Down Expand Up @@ -178,7 +179,8 @@ def list_devices(self, requirements: dict, fields: str = "") -> list:
present=True,
ready=True,
using=False,
owner=None)
owner=None,
status=3) # 3=Online
)

self.logger.debug(
Expand Down
22 changes: 14 additions & 8 deletions test/test_StfClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,19 @@ def test_find_and_allocate_but_device_not_found(self):
self.client.find_and_allocate({})

def test_list_devices(self):
available = {'serial': 123, 'present': True, 'ready': True, 'using': False, 'owner': None}
available = {'serial': 123, 'present': True, 'ready': True, 'using': False, 'owner': None, 'status': 3}
self.client.get_devices = MagicMock(return_value=[available])
response = self.client.list_devices(requirements={})
self.assertEqual(response, [available])

def test_list_devices_offline(self):
available = {'serial': 123, 'present': True, 'ready': True, 'using': False, 'owner': None, 'status': 1}
self.client.get_devices = MagicMock(return_value=[available])
response = self.client.list_devices(requirements={})
self.assertEqual(response, [])

def test_find_and_allocate_success(self):
available = {'serial': 123, 'present': True, 'ready': True, 'using': False, 'owner': None}
available = {'serial': 123, 'present': True, 'ready': True, 'using': False, 'owner': None, 'status': 3}
self.client.get_devices = MagicMock(return_value=[available])
self.client._client.request = MagicMock(return_value=Response(status=200, data={}))

Expand All @@ -131,8 +137,8 @@ def test_find_and_allocate_success(self):

@patch('random.shuffle', side_effect=MagicMock())
def test_find_and_allocate_second_success(self, mock_choise):
invalid = {'serial': '12', 'present': True, 'ready': True, 'using': False, 'owner': None}
available = {'serial': '123', 'present': True, 'ready': True, 'using': False, 'owner': None}
invalid = {'serial': '12', 'present': True, 'ready': True, 'using': False, 'owner': None, 'status': 3}
available = {'serial': '123', 'present': True, 'ready': True, 'using': False, 'owner': None, 'status': 3}
self.client.get_devices = MagicMock(return_value=[invalid, available])

self.client._client.request = MagicMock(side_effect=[
Expand All @@ -148,8 +154,8 @@ def test_find_and_allocate_second_success(self, mock_choise):
self.client.get_devices.assert_called_once()

def test_find_and_allocate_no_suitable(self):
dev1 = {'serial': '12', 'present': True, 'ready': True, 'using': False, 'owner': None}
dev2 = {'serial': '123', 'present': True, 'ready': True, 'using': False, 'owner': None}
dev1 = {'serial': '12', 'present': True, 'ready': True, 'using': False, 'owner': None, 'status': 3}
dev2 = {'serial': '123', 'present': True, 'ready': True, 'using': False, 'owner': None, 'status': 3}
self.client.get_devices = MagicMock(return_value=[dev1, dev2])

self.client._client.request = MagicMock(side_effect=[
Expand Down Expand Up @@ -189,7 +195,7 @@ def test_release(self):
self.client._client.request.assert_called_once()

def test_allocation_context_first_success(self):
dev1 = {'serial': '123', 'present': True, 'ready': True, 'using': False, 'owner': None}
dev1 = {'serial': '123', 'present': True, 'ready': True, 'using': False, 'owner': None, 'status': 3}
self.client.get_devices = MagicMock(return_value=[dev1])
url = '123'
self.client._client.request = MagicMock(return_value=Response(status=200, data={'remoteConnectUrl': url}))
Expand All @@ -200,7 +206,7 @@ def test_allocation_context_first_success(self):

@patch('time.sleep', side_effect=MagicMock())
def test_allocation_context_wait_success(self, mock_sleep):
dev1 = {'serial': '123', 'present': True, 'ready': True, 'using': False, 'owner': None}
dev1 = {'serial': '123', 'present': True, 'ready': True, 'using': False, 'owner': None, 'status': 3}
self.client.get_devices = MagicMock(side_effect=[[], [dev1]])
url = '123'
self.client._client.request = MagicMock(return_value=Response(status=200, data={'remoteConnectUrl': url}))
Expand Down

0 comments on commit 6a1ff66

Please sign in to comment.