示例#1
0
def test_initializing_middleware_with_app_and_root_path_raises_value_error(
    app_mock, schema
):
    with pytest.raises(Exception) as excinfo:
        GraphQLMiddleware(app_mock, schema, path="/")
    assert isinstance(excinfo.value, ValueError)
    assert excinfo.value.args[0] == (
        "WSGI middleware can't use root path together with application callable"
    )
def test_app_exceptions_are_not_handled(app_mock, schema):
    exception = Exception("Test exception")
    app_mock = Mock(side_effect=exception)
    middleware = GraphQLMiddleware(app_mock, schema)
    handle_request = middleware.graphql_server.handle_request = Mock()

    with pytest.raises(Exception) as excinfo:
        middleware({"PATH_INFO": "/"}, Mock())
    assert excinfo.value is exception
    assert not handle_request.called
示例#3
0
def test_allowed_methods_list_returned_for_options_request_excludes_get(
        app_mock, middleware_request, start_response, schema):
    middleware_request["REQUEST_METHOD"] = "OPTIONS"
    server = GraphQL(schema, introspection=False)
    middleware = GraphQLMiddleware(app_mock, server)
    middleware(middleware_request, start_response)
    start_response.assert_called_once_with(
        HTTP_STATUS_200_OK,
        [
            ("Content-Type", CONTENT_TYPE_TEXT_PLAIN),
            ("Content-Length", 0),
            ("Allow", "OPTIONS, POST"),
        ],
    )
示例#4
0
def middleware(app_mock, schema):
    return GraphQLMiddleware(app_mock, schema)
示例#5
0
def middleware(app_mock, server):
    return GraphQLMiddleware(app_mock, server)
示例#6
0
def test_initializing_middleware_without_path_raises_value_error(schema):
    with pytest.raises(Exception) as excinfo:
        GraphQLMiddleware(lambda *_: None, schema, path="")

    assert isinstance(excinfo.value, ValueError)
    assert excinfo.value.args[0] == "path can't be empty"
示例#7
0
def test_initializing_middleware_without_app_raises_type_error(schema):
    with pytest.raises(Exception) as excinfo:
        GraphQLMiddleware(None, schema)
    assert isinstance(excinfo.value, TypeError)
    assert excinfo.value.args[0] == ("app must be a callable WSGI application")