コード例 #1
0
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
コード例 #2
0
ファイル: result_test.py プロジェクト: bpicolo/bravado
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()
コード例 #3
0
ファイル: result_test.py プロジェクト: isysd/bravado
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
コード例 #4
0
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
コード例 #5
0
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()
コード例 #6
0
ファイル: result_test.py プロジェクト: sjaensch/bravado
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
コード例 #7
0
ファイル: result_test.py プロジェクト: sjaensch/bravado
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()
コード例 #8
0
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()
コード例 #9
0
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()
コード例 #10
0
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()
コード例 #11
0
ファイル: result_test.py プロジェクト: bpicolo/bravado
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()
コード例 #12
0
ファイル: result_test.py プロジェクト: bpicolo/bravado
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()
コード例 #13
0
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()
コード例 #14
0
ファイル: result_test.py プロジェクト: sjaensch/bravado
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()
コード例 #15
0
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'
コード例 #16
0
ファイル: result_test.py プロジェクト: isysd/bravado
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()
コード例 #17
0
ファイル: result_test.py プロジェクト: althor880/bravado
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'
コード例 #18
0
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'
コード例 #19
0
ファイル: result_test.py プロジェクト: sjaensch/bravado
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'
コード例 #20
0
ファイル: result_test.py プロジェクト: isysd/bravado
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'