def test_retry_until_limit(self): self.counter = 0 def on_retry(func, trial_number): self.counter = self.counter + 1 config = ExponentialBackoffConfig(5, 0.1, on_retry) api = APIManager("CLIENT_ID", "CLIENT_SECRET", self.server.path, compression_enabled=False, backoff_config = config, token_override=None) with self.assertRaises(ServiceUnavailable) as ctx: api.get('unvailable/100') self.assertEqual(self.counter, 5)
def test_retry_until_200(self): self.counter = 0 def on_retry(func, trial_number): self.counter = self.counter + 1 config = ExponentialBackoffConfig(5, 0.5, on_retry) api = APIManager("CLIENT_ID", "CLIENT_SECRET", self.server.path, compression_enabled=False, backoff_config = config, token_override=None) value = api.get('unvailable/3') self.assertEqual(self.counter, 4) self.assertEqual(value.json()['data'], "ok")
def test_do_not_retry_if_success(self): api = APIManager("CLIENT_ID", "CLIENT_SECRET", self.server.path, compression_enabled=False, backoff_config=None, token_override=None) value = api.get('/api/v3/unvailable/0') self.assertEqual(value.json()['data'], "ok")
def test_retry_default(self): config = ExponentialBackoffConfig() api = APIManager("CLIENT_ID", "CLIENT_SECRET", self.server.path, compression_enabled=False, backoff_config=config, token_override=None) value = api.get('/api/v3/unvailable/1') self.assertEqual(value.json()['data'], "ok")
def __init__(self, client_id, client_secret, environment, compression_enabled=True): """ Initialization of the smartobjects client The client exposes the Events, Objects, Owners and Search services. Initialization will fetch an API token with the id and secret provided. :param client_id (string): client_id part of the OAuth 2.0 credentials (available in your dashboard) :param client_secret (string): client_secret part of the OAuth 2.0 credentials (available in your dashboard) :param environment: either Environments.Sandbox or Environments.Production (note: client_id and client_secret are unique per environment) :param compression_enabled: gzip compress the request body (default: True) :note: Do not expose publicly code containing your client_id and client_secret .. seealso:: examples/simple_workflow.py """ if environment not in (Environments.Sandbox, Environments.Production): raise ValueError( "Invalid 'environment' argument, must be one of: Environments.Sandbox, Environments.Production" ) self._api_manager = APIManager(client_id, client_secret, environment, compression_enabled) self.owners = OwnersService(self._api_manager) self.events = EventsService(self._api_manager) self.objects = ObjectsService(self._api_manager) self.search = SearchService(self._api_manager)
def setUpClass(cls): cls.server = LocalApiServer() cls.server.start() cls.api = APIManager("CLIENT_ID", "CLIENT_SECRET", cls.server.path, compression_enabled=False, backoff_config=None, token_override=None) cls.search = SearchService(cls.api)
def setUpClass(cls): cls.server = LocalApiServer() cls.server.start() cls.api = APIManager("CLIENT_ID", "CLIENT_SECRET", cls.server.path, False) cls.search = SearchService(cls.api)
def __init__(self, client_id, client_secret, environment, compression_enabled=True, backoff_config=None, token_override=None): """ Initialization of the smartobjects client The client exposes the Events, Objects, Owners and Search services. Initialization will fetch an API token with the id and secret provided. :param client_id (string): client_id part of the OAuth 2.0 credentials (available in your dashboard) :param client_secret (string): client_secret part of the OAuth 2.0 credentials (available in your dashboard) :param environment: a URL to the targeted environment (Environments.Sandbox or Environments.Production can be used) (note: client_id and client_secret are unique per environment) :param compression_enabled: gzip compress the request body (default: True) :param backoff_config: retry with exponential backoff (default: None) :param token_override: this token will be used instead of performing the OAuth2 dance with the client_id and client_secret. This is not recommended for production (default: None) :note: Do not expose publicly code containing your client_id and client_secret .. seealso:: examples/simple_workflow.py """ if not environment: raise ValueError("environment cannot be null or empty.") self._api_manager = APIManager(client_id, client_secret, environment, compression_enabled, backoff_config, token_override) self.owners = OwnersService(self._api_manager) self.events = EventsService(self._api_manager) self.objects = ObjectsService(self._api_manager) self.search = SearchService(self._api_manager) self.model = ModelService(self._api_manager)