예제 #1
0
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())
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()
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()