예제 #1
0
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()
예제 #2
0
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)
예제 #3
0
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()
예제 #4
0
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)
예제 #5
0
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!**"}}
예제 #6
0
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"}}
예제 #7
0
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()
예제 #8
0
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"}}
예제 #9
0
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)
예제 #10
0
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!**"}}
예제 #11
0
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()
예제 #12
0
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()