Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def server():
return GraphQLMiddleware(None, type_defs=type_defs, resolvers=resolvers, path="/")
def test_initializing_middleware_without_path_raises_value_error():
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"
def test_app_exceptions_are_not_handled(app_mock):
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
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"
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"
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"
)
def test_initializing_middleware_without_app_raises_type_error():
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"
def test_initializing_middleware_with_app_and_root_path_raises_value_error(app_mock):
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"
)
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"