Ejemplo n.º 1
0
def test_app_exceptions_are_not_handled(app_mock, type_defs):
    exception = Exception("Test exception")
    app_mock = Mock(side_effect=exception)
    middleware = GraphQLMiddleware(app_mock, type_defs=type_defs, resolvers={})
    middleware.handle_request = Mock()

    with pytest.raises(Exception) as excinfo:
        middleware({"PATH_INFO": "/"}, Mock())
    assert excinfo.value is exception
    assert not middleware.handle_request.called
Ejemplo n.º 2
0
def test_initializing_middleware_without_app_raises_type_error(type_defs):
    with pytest.raises(Exception) as excinfo:
        GraphQLMiddleware(None, type_defs=type_defs, resolvers={})
    assert isinstance(excinfo.value, TypeError)
    assert excinfo.value.args[0] == (
        "can't set custom path on WSGI middleware without providing "
        "application callable as first argument"
    )
Ejemplo n.º 3
0
def test_initializing_middleware_with_app_and_root_path_raises_value_error(
    app_mock, type_defs
):
    with pytest.raises(Exception) as excinfo:
        GraphQLMiddleware(app_mock, type_defs=type_defs, resolvers={}, path="/")
    assert isinstance(excinfo.value, ValueError)
    assert excinfo.value.args[0] == (
        "WSGI middleware can't use root path together with application callable"
    )
Ejemplo n.º 4
0
def test_make_simple_server_creates_server_with_custom_port(
        type_defs, resolvers, make_server):
    GraphQLMiddleware.make_simple_server(type_defs, resolvers, port=4444)
    assert make_server.call_count == 1
    called_with_args = make_server.call_args[0]
    assert called_with_args[1] == 4444
Ejemplo n.º 5
0
def test_make_simple_server_creates_server_with_custom_host(
        type_defs, resolvers, make_server):
    GraphQLMiddleware.make_simple_server(type_defs, resolvers, host="0.0.0.0")
    assert make_server.call_count == 1
    called_with_args = make_server.call_args[0]
    assert called_with_args[0] == "0.0.0.0"
Ejemplo n.º 6
0
def test_make_simple_server_returns_mocked_true(type_defs, resolvers,
                                                make_server):  # pylint: disable=unused-argument
    result = GraphQLMiddleware.make_simple_server(type_defs, resolvers)
    assert result is True
Ejemplo n.º 7
0
def server(type_defs, resolvers):
    return GraphQLMiddleware(None,
                             type_defs=type_defs,
                             resolvers=resolvers,
                             path="/")
Ejemplo n.º 8
0
def middleware(app_mock, type_defs, resolvers):
    return GraphQLMiddleware(app_mock,
                             type_defs=type_defs,
                             resolvers=resolvers)
Ejemplo n.º 9
0
def test_initializing_middleware_without_path_raises_value_error(type_defs):
    with pytest.raises(Exception) as excinfo:
        GraphQLMiddleware(None, type_defs=type_defs, resolvers={}, path="")

    assert isinstance(excinfo.value, ValueError)
    assert excinfo.value.args[0] == "path keyword argument can't be empty"
Ejemplo n.º 10
0
def test_initializing_middleware_with_non_callable_app_raises_type_error(type_defs):
    with pytest.raises(Exception) as excinfo:
        GraphQLMiddleware(True, type_defs=type_defs, resolvers={}, path="/")
    assert isinstance(excinfo.value, TypeError)
    assert excinfo.value.args[0] == "first argument must be a callable or None"