def test_non_2XX_with_response_callback(): response_adapter_instance = Mock(spec=IncomingResponse, status_code=400) response_callback = Mock(side_effect=HTTPError(response_adapter_instance)) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture(future=Mock(spec=Future), response_adapter=response_adapter_type, callback=response_callback) with pytest.raises(HTTPError) as excinfo: http_future.result() assert excinfo.value.response.status_code == 400
def test_4XX_5XX_failure(_): response_callback = Mock(return_value='hello world') response_adapter_instance = Mock(spec=ResponseLike, status_code=400) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=Mock(spec=Future), response_adapter=response_adapter_type, callback=response_callback) with pytest.raises(HTTPError): http_future.result()
def test_non_2XX_with_response_callback(): response_adapter_instance = Mock(spec=IncomingResponse, status_code=400) response_callback = Mock(side_effect=HTTPError(response_adapter_instance)) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=Mock(spec=Future), response_adapter=response_adapter_type, callback=response_callback) with pytest.raises(HTTPError) as excinfo: http_future.result() assert excinfo.value.response.status_code == 400
def test_400_service_call(mock_unmarshal_response): response_adapter_instance = Mock(spec=IncomingResponse, status_code=400, swagger_result={'error': 'Blah'}) mock_unmarshal_response.side_effect = HTTPError(response_adapter_instance) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture(future=Mock(spec=FutureAdapter), response_adapter=response_adapter_type, operation=Mock(spec=Operation)) with pytest.raises(HTTPError) as excinfo: http_future.result() assert excinfo.value.response.status_code == 400
def test_200_get_swagger_spec(): response_adapter_instance = Mock(spec=IncomingResponse, status_code=200) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture(future=Mock(spec=FutureAdapter), response_adapter=response_adapter_type) assert response_adapter_instance == http_future.result()
def test_400_service_call(mock_unmarshal_response, mock_future_adapter): response_adapter_instance = Mock( spec=IncomingResponse, status_code=400, swagger_result={'error': 'Blah'}) mock_unmarshal_response.side_effect = HTTPError(response_adapter_instance) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=mock_future_adapter, response_adapter=response_adapter_type, operation=Mock(spec=Operation)) with pytest.raises(HTTPError) as excinfo: http_future.result() assert excinfo.value.response.status_code == 400
def test_200_get_swagger_spec(mock_future_adapter): response_adapter_instance = Mock(spec=IncomingResponse, status_code=200) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=mock_future_adapter, response_adapter=response_adapter_type) assert response_adapter_instance == http_future.result()
def test_200_get_swagger_spec(mock_future_adapter): response_adapter_instance = Mock(spec=IncomingResponse, status_code=200) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=mock_future_adapter, response_adapter=response_adapter_type, ) # type: HttpFuture[None] assert response_adapter_instance == http_future.result()
def test_200_no_response_callback(): # This use case is for http requests that are made outside of the # swagger spec e.g. retrieving the swagger schema response_adapter_instance = Mock(spec=IncomingResponse, status_code=200) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture(future=Mock(spec=Future), response_adapter=response_adapter_type, callback=None) assert response_adapter_instance == http_future.result()
def test_200_with_response_callback(): response_callback = Mock(return_value='hello world') response_adapter_instance = Mock(spec=IncomingResponse, status_code=200) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture(future=Mock(spec=Future), response_adapter=response_adapter_type, callback=response_callback) assert 'hello world' == http_future.result()
def test_no_response_callback(): # This use case is for http requests that are made outside of the # swagger spec e.g. retrieving the swagger schema response_adapter_instance = Mock(spec=ResponseLike) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=Mock(spec=Future), response_adapter=response_adapter_type, callback=None) assert response_adapter_instance == http_future.result()
def test_200_success(): response_callback = Mock(return_value='hello world') response_adapter_instance = Mock(spec=ResponseLike, status_code=200) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=Mock(spec=Future), response_adapter=response_adapter_type, callback=response_callback) assert 'hello world' == http_future.result()
def test_200_service_call(_): response_adapter_instance = Mock(spec=IncomingResponse, status_code=200, swagger_result='hello world') response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture(future=Mock(spec=FutureAdapter), response_adapter=response_adapter_type, operation=Mock(spec=Operation)) assert 'hello world' == http_future.result()
def test_200_service_call(_, mock_future_adapter): response_adapter_instance = Mock( spec=IncomingResponse, status_code=200, swagger_result='hello world') response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=mock_future_adapter, response_adapter=response_adapter_type, operation=Mock(spec=Operation)) assert 'hello world' == http_future.result()
def test_also_return_response_true(_): # Verify HTTPFuture(..., also_return_response=True).result() # returns the (swagger_result, http_response) and not just swagger_result response_adapter_instance = Mock(spec=IncomingResponse, status_code=200, swagger_result='hello world') response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture(future=Mock(spec=FutureAdapter), response_adapter=response_adapter_type, operation=Mock(spec=Operation), also_return_response=True) swagger_result, http_response = http_future.result() assert http_response == response_adapter_instance assert swagger_result == 'hello world'
def test_200_with_response_callback(): def response_callback(incoming_response): incoming_response.swagger_result = 'hello world' response_adapter_instance = Mock( spec=IncomingResponse, status_code=200) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=Mock(spec=Future), response_adapter=response_adapter_type, callback=response_callback) assert 'hello world' == http_future.result()
def test_also_return_response_true(_): # Verify HTTPFuture(..., also_return_response=True).result() # returns the (swagger_result, http_response) and not just swagger_result response_adapter_instance = Mock( spec=IncomingResponse, status_code=200, swagger_result='hello world') response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( concurrent_future=Mock(spec=Future), response_adapter=response_adapter_type, operation=Mock(spec=Operation), also_return_response=True) swagger_result, http_response = http_future.result() assert http_response == response_adapter_instance assert swagger_result == 'hello world'
def test_also_return_response_true(_, mock_future_adapter): # Verify HTTPFuture(..., also_return_response=True).result() # returns the (swagger_result, http_response) and not just swagger_result response_adapter_instance = Mock(spec=IncomingResponse, status_code=200, swagger_result='hello world') response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=mock_future_adapter, response_adapter=response_adapter_type, operation=Mock(spec=Operation), request_config=RequestConfig({}, also_return_response_default=True), ) # type: HttpFuture[typing.Tuple[str, IncomingResponse]] swagger_result, http_response = http_future.result() assert http_response == response_adapter_instance assert swagger_result == 'hello world'
def test_also_return_response_true(_, mock_future_adapter): # Verify HTTPFuture(..., also_return_response=True).result() # returns the (swagger_result, http_response) and not just swagger_result response_adapter_instance = Mock( spec=IncomingResponse, status_code=200, swagger_result='hello world') response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=mock_future_adapter, response_adapter=response_adapter_type, operation=Mock(spec=Operation), request_config=RequestConfig({}, also_return_response_default=True)) swagger_result, http_response = http_future.result() assert http_response == response_adapter_instance assert swagger_result == 'hello world'
def test_also_return_response_true(): # Verify HTTPFuture(..., also_return_response=True).result() # returns the (swagger_result, http_response) and not just swagger_result def response_callback(incoming_response): incoming_response.swagger_result = 'hello world' response_adapter_instance = Mock(spec=IncomingResponse, status_code=200) response_adapter_type = Mock(return_value=response_adapter_instance) http_future = HttpFuture( future=Mock(spec=Future), response_adapter=response_adapter_type, callback=response_callback, also_return_response=True) swagger_result, http_response = http_future.result() assert http_response == response_adapter_instance assert swagger_result == 'hello world'