def test_custom_validation_rules_function_is_set_and_called_on_query_execution( schema, validation_rule): get_validation_rules = Mock(return_value=[validation_rule]) app = GraphQL(schema, validation_rules=get_validation_rules) app.execute_query({}, {"query": "{ status }"}) get_validation_rules.assert_called_once() validation_rule.assert_called_once()
def test_custom_root_value_function_is_called_with_context_value(schema): get_root_value = Mock(return_value=True) app = GraphQL(schema, context_value={"test": "TEST-CONTEXT"}, root_value=get_root_value) app.execute_query({}, {"query": "{ status }"}) get_root_value.assert_called_once_with({"test": "TEST-CONTEXT"}, ANY)
def test_custom_validation_rules_function_is_set_and_called_on_query_execution( mocker, schema, validation_rule): spy_validation_rule = mocker.spy(validation_rule, "__init__") get_validation_rules = Mock(return_value=[validation_rule]) app = GraphQL(schema, validation_rules=get_validation_rules) app.execute_query({}, {"query": "{ status }"}) get_validation_rules.assert_called_once() spy_validation_rule.assert_called_once()
def test_custom_validation_rules_function_is_called_with_context_value( schema, validation_rule): get_validation_rules = Mock(return_value=[validation_rule]) app = GraphQL( schema, context_value={"test": "TEST-CONTEXT"}, validation_rules=get_validation_rules, ) app.execute_query({}, {"query": "{ status }"}) get_validation_rules.assert_called_once_with({"test": "TEST-CONTEXT"}, ANY, ANY)
def test_middleware_function_result_is_passed_to_query_executor(schema): def get_middleware(*_): return [middleware] app = GraphQL(schema, middleware=get_middleware) _, result = app.execute_query({}, {"query": '{ hello(name: "BOB") }'}) assert result == {"data": {"hello": "**Hello, BOB!**"}}
def test_custom_context_value_is_passed_to_resolvers(schema): app = GraphQL(schema, context_value={"test": "TEST-CONTEXT"}) _, result = app.execute_query({}, {"query": "{ testContext }"}) assert result == {"data": {"testContext": "TEST-CONTEXT"}}
def test_custom_root_value_function_is_set_and_called_by_app(schema): get_root_value = Mock(return_value=True) app = GraphQL(schema, root_value=get_root_value) app.execute_query({}, {"query": "{ status }"}) get_root_value.assert_called_once()
def test_custom_root_value_is_passed_to_resolvers(schema): app = GraphQL(schema, root_value={"test": "TEST-ROOT"}) _, result = app.execute_query({}, {"query": "{ testRoot }"}) assert result == {"data": {"testRoot": "TEST-ROOT"}}
def test_custom_context_value_function_is_called_with_request_value(schema): get_context_value = Mock(return_value=True) app = GraphQL(schema, context_value=get_context_value) request = {"CONTENT_TYPE": DATA_TYPE_JSON} app.execute_query(request, {"query": "{ status }"}) get_context_value.assert_called_once_with(request)
def test_middlewares_are_passed_to_query_executor(schema): app = GraphQL(schema, middleware=[middleware]) _, result = app.execute_query({}, {"query": '{ hello(name: "BOB") }'}) assert result == {"data": {"hello": "**Hello, BOB!**"}}
def test_custom_validation_rule_is_called_by_query_validation( mocker, schema, validation_rule): spy_validation_rule = mocker.spy(validation_rule, "__init__") app = GraphQL(schema, validation_rules=[validation_rule]) app.execute_query({}, {"query": "{ status }"}) spy_validation_rule.assert_called_once()
def test_custom_validation_rule_is_called_by_query_validation( schema, validation_rule): app = GraphQL(schema, validation_rules=[validation_rule]) app.execute_query({}, {"query": "{ status }"}) validation_rule.assert_called_once()