def test_client_callback(self, mocker, http_client_mock): # Setup callback = mocker.stub() deferred = mocker.Mock() deferToThread = mocker.patch.object(twisted_.threads, "deferToThread") deferToThread.return_value = deferred client = twisted_.TwistedClient(http_client_mock) # Run response = client.apply_callback(callback, 1) # Verify assert response is deferred deferToThread.assert_called_with(http_client_mock.apply_callback, callback, 1)
def test_create_requests_no_twisted(self, http_client_mock): with _patch(twisted_, "threads", None): with pytest.raises(NotImplementedError): twisted_.TwistedClient(http_client_mock)
def test_create_requests(self, http_client_mock): twisted = twisted_.TwistedClient(http_client_mock) request = twisted.create_request() assert request._proxy is http_client_mock.create_request() assert isinstance(request, twisted_.Request)
def test_init_without_client(self): twisted = twisted_.TwistedClient() assert isinstance(twisted._requests, requests_.RequestsClient)
def test_exceptions(self, http_client_mock): twisted_client = twisted_.TwistedClient(http_client_mock) assert http_client_mock.exceptions == twisted_client.exceptions
def test_client_send(self, mocker, http_client_mock): deferToThread = mocker.patch.object(twisted_.threads, "deferToThread") request = twisted_.TwistedClient(http_client_mock) request.send((1, 2, 3)) deferToThread.assert_called_with(http_client_mock.send, (1, 2, 3))