Skip to content

Commit

Permalink
accept 403 (ForbiddenException) when trying to allocate (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
jupe authored Nov 25, 2022
1 parent 186d54d commit f3c5a27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion stf_appium_client/StfClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import json
from pydash import filter_, map_, wrap, find, uniq
import atexit

from stf_client.exceptions import ForbiddenException

from stf_appium_client.Logger import Logger
from stf_appium_client.exceptions import DeviceNotFound, NotConnectedError
from stf_client.api_client import ApiClient, Configuration
Expand Down Expand Up @@ -197,7 +200,7 @@ def allocate_first():
def try_allocate(device):
try:
return self.allocate(device, timeout_seconds=timeout_seconds)
except AssertionError as error:
except (AssertionError, ForbiddenException) as error:
self.logger.warning(f"{device.get('serial')}Allocation fails: {error}")
return None

Expand Down
7 changes: 5 additions & 2 deletions test/test_StfClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import logging
import types
from unittest.mock import patch, MagicMock

from stf_client.exceptions import ForbiddenException

from stf_appium_client.StfClient import StfClient
from stf_appium_client.exceptions import *

Expand Down Expand Up @@ -134,12 +137,12 @@ def test_find_and_allocate_success(self):
def test_find_and_allocate_second_success(self, mock_choise):
invalid = {'serial': '12', 'present': False, '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.get_devices = MagicMock(return_value=[invalid, available, available])

def dummy_alloc(dev, timeout_seconds):
return dev

self.client.allocate = MagicMock(side_effect=dummy_alloc)
self.client.allocate = MagicMock(side_effect=[ForbiddenException, dummy_alloc])

device = self.client.find_and_allocate({})
available['owner'] = 'me'
Expand Down

0 comments on commit f3c5a27

Please sign in to comment.