def test_cancel_for_async_cancels_the_api_call(self): http_client = AsynchronousHttpClient() with patch.object(AsynchronousHttpClient, 'cancel') as mock_cancel: with patch.object(AsynchronousHttpClient, 'setup') as mock_setup: self.future = HTTPFuture(http_client, None, None) self.future.cancel() mock_setup.assert_called_once_with(None) mock_cancel.assert_called_once_with()
class HTTPFutureTest(unittest.TestCase): def setUp(self): http_client = Mock() http_client.setup.return_value = None self.future = HTTPFuture(http_client, None, None) def test_raise_cancelled_error_if_result_is_called_after_cancel(self): self.future.cancel() self.assertRaises(CancelledError, self.future.result) def test_cancelled_returns_true_if_called_after_cancel(self): self.future.cancel() self.assertTrue(self.future.cancelled()) def test_cancelled_returns_false_if_called_before_cancel(self): self.assertFalse(self.future.cancelled()) def test_cancel_for_async_cancels_the_api_call(self): http_client = AsynchronousHttpClient() with patch.object(AsynchronousHttpClient, 'cancel') as mock_cancel: with patch.object(AsynchronousHttpClient, 'setup') as mock_setup: self.future = HTTPFuture(http_client, None, None) self.future.cancel() mock_setup.assert_called_once_with(None) mock_cancel.assert_called_once_with()
def __call__(self, **kwargs): log.debug(u"%s?%r" % (self._json[u'nickname'], urllib_utf8.urlencode(kwargs))) request = self._construct_request(**kwargs) def response_future(response, **kwargs): # Assume status is OK, an exception would have been raised already if not response.text: return None return post_receive(response.json(), swagger_type.get_swagger_type(self._json), self._models, **kwargs) return HTTPFuture(self._http_client, request, response_future)
def __call__(self, **kwargs): log.info(u"%s?%r" % (self._json[u'nickname'], urllib.urlencode(kwargs))) request = self._construct_request(**kwargs) def py_model_convert_callback(response, **kwargs): value = None type_ = swagger_type.get_swagger_type(self._json) # Assume status is OK, # as exception would have been raised otherwise # Validate the response if it is not empty. if response.text: # Validate and convert API response to Python model instance value = SwaggerResponse(response.json(), type_, self._models, **kwargs).swagger_object return value return HTTPFuture(self._http_client, request, py_model_convert_callback)
class HTTPFutureTest(unittest.TestCase): def setUp(self): self.http_client = Mock() self.future = HTTPFuture(self.http_client, None, None) def test_raise_cancelled_error_if_result_is_called_after_cancel(self): self.future.cancel() self.assertRaises(CancelledError, self.future.result) def test_cancelled_returns_true_if_called_after_cancel(self): self.future.cancel() self.assertTrue(self.future.cancelled()) response = self.http_client.start_request.return_value response.cancel.assert_called_once_with() def test_cancelled_returns_false_if_called_before_cancel(self): self.assertFalse(self.future.cancelled())
def setUp(self): http_client = Mock() http_client.setup.return_value = None self.future = HTTPFuture(http_client, None, None)
def setUp(self): self.http_client = Mock() self.future = HTTPFuture(self.http_client, None, None)