Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_start_simple_server_creates_server_with_custom_port(
type_defs, resolvers, make_server
):
schema = make_executable_schema(type_defs, resolvers)
start_simple_server(schema, port=4444)
called_with_args = make_server.call_args[0]
assert called_with_args[1] == 4444
def test_start_simple_server_from_inheriting_type_respects_inheritance(
type_defs, resolvers, make_server
):
class CustomGraphQL(GraphQL):
pass
schema = make_executable_schema(type_defs, resolvers)
start_simple_server(schema, server_class=CustomGraphQL)
make_server.assert_called_once()
called_with_args = make_server.call_args[0]
assert isinstance(called_with_args[2], CustomGraphQL)
def test_start_simple_server_returns_mocked_true(
type_defs, resolvers, make_server
): # pylint: disable=unused-argument
schema = make_executable_schema(type_defs, resolvers)
start_simple_server(schema)
assert make_server.call_count == 1
def test_custom_host_and_ip_are_printed_on_server_creation(
middleware_make_simple_server_mock, capsys
): # pylint: disable=unused-argument
schema = make_executable_schema("type Query { dummy: Boolean }", {})
start_simple_server(schema, host="0.0.0.0", port=4444)
captured = capsys.readouterr()
assert "http://0.0.0.0:4444" in captured.out
def test_type_defs_resolvers_host_and_ip_are_passed_to_graphql_middleware(
middleware_make_simple_server_mock, schema
):
start_simple_server(schema, host="0.0.0.0", port=4444)
call = middleware_make_simple_server_mock.call_args[0]
assert call[0] == "0.0.0.0"
assert call[1] == 4444
assert isinstance(call[2], GraphQL)
def test_wsgi_simple_server_serve_forever_is_called(mocker, schema, simple_server_mock):
mocker.patch("wsgiref.simple_server.make_server", return_value=simple_server_mock)
start_simple_server(schema)
simple_server_mock.serve_forever.assert_called_once()
def test_default_host_and_ip_are_passed_to_graphql_middleware_if_not_set(
middleware_make_simple_server_mock, schema
):
start_simple_server(schema)
call = middleware_make_simple_server_mock.call_args[0]
assert call[0] == "127.0.0.1"
assert call[1] == 8888
assert isinstance(call[2], GraphQL)
def test_start_simple_server_creates_server_with_custom_host(
type_defs, resolvers, make_server
):
schema = make_executable_schema(type_defs, resolvers)
start_simple_server(schema, host="0.0.0.0")
called_with_args = make_server.call_args[0]
assert called_with_args[0] == "0.0.0.0"
def test_keyboard_interrupt_is_handled_gracefully(mocker, schema):
mocker.patch(
"wsgiref.simple_server.make_server", side_effect=KeyboardInterrupt("test")
)
start_simple_server(schema)
def test_default_host_and_ip_are_printed_on_server_creation(
middleware_make_simple_server_mock, capsys
): # pylint: disable=unused-argument
schema = make_executable_schema("type Query { dummy: Boolean }", {})
start_simple_server(schema)
captured = capsys.readouterr()
assert "http://127.0.0.1:8888" in captured.out