예제 #1
0
def test_client_incorrect_args_raises_error(spec_dict, config):
    app = Application(spec_dict, module=config.endpoint_base)
    client = Client(spec_dict, client=TestClient(app))
    with pytest.raises(RuntimeError) as error:
        client.dummy_test_endpoint("foo")
    assert (
        error.exconly() ==
        "RuntimeError: Incorrect arguments: dummyTestEndpoint accepts no positional arguments"
    )
예제 #2
0
def test_common_headers_included_in_request(spec_dict, config, monkeypatch):
    app = Application(spec_dict, module=config.endpoint_base)
    client = Client(spec_dict, client=TestClient(app), headers={"foo": "bar"})

    def patch_request(request):
        def wrapper(*args, **kwargs):
            client.request_info = {"args": args, "kwargs": kwargs}
            return request(*args, **kwargs)

        return wrapper

    monkeypatch.setattr(client.client, "request",
                        patch_request(client.client.request))
    client.dummy_test_endpoint(headers_={"baz": "bam"})
    headers = client.request_info["kwargs"]["headers"]
    assert dict(headers) == {"foo": "bar", "baz": "bam"}
예제 #3
0
def test_client_calls_endpoint_using_server_with_path(spec_dict, config):
    spec_dict["servers"].insert(0, {"url": "http://localhost:8001/with/path"})
    app = Application(spec_dict, module=config.endpoint_base)
    client = Client(spec_dict, client=TestClient(app))
    response = client.dummy_test_endpoint()
    assert isinstance(response, OpenAPIResponse)
    assert response.data == b'{"foo":"bar"}'
예제 #4
0
def test_client_calls_endpoint(spec_dict, config):
    app = Application(spec_dict, module=config.endpoint_base)
    client = Client(spec_dict, client=TestClient(app))
    response = client.dummy_test_endpoint()
    assert isinstance(response, OpenAPIResponse)
    assert response.data == b'{"foo":"bar"}'