Exemplo n.º 1
0
def _resolver_executor_mock():
    from tartiflette.resolver.factory import _ResolverExecutor

    field = Mock()
    field.schema = None
    field.gql_type = "aType"
    field.arguments = {}

    res_ex = _ResolverExecutor(FakeAsyncMock(), field)
    return res_ex
Exemplo n.º 2
0
def test_resolver_factory__resolver_executor_instance():
    from tartiflette.resolver.factory import _ResolverExecutor

    field = Mock()
    field.schema = None
    field.gql_type = "aType"

    res_ex = _ResolverExecutor("A", field)
    assert res_ex._raw_func == "A"
    assert res_ex._directivated_func == "A"
    assert res_ex._schema_field is field
    assert res_ex._coercer is None
    assert not res_ex._shall_produce_list

    res_ex = _ResolverExecutor("A", field)
    assert res_ex._raw_func == "A"
    assert res_ex._directivated_func == "A"
    assert res_ex._schema_field is field
    assert res_ex._coercer is None
    assert not res_ex._shall_produce_list
Exemplo n.º 3
0
def test_resolverexecutor_bake(
    is_subscription,
    custom_default_resolver,
    update_func_called,
    default_subscription_resolver_called,
):
    with patch("tartiflette.resolver.factory.wraps_with_directives"
               ) as wraps_with_directives_mock:
        from tartiflette.resolver.factory import (
            _ResolverExecutor,
            default_resolver,
            default_subscription_resolver,
        )

        schema_field = Mock(schema=None)
        schema_field.directives = Mock()
        schema_field.subscribe = Mock() if is_subscription else None

        with patch(
                "tartiflette.resolver.factory.default_subscription_resolver",
                wraps=default_subscription_resolver,
        ) as default_subscription_resolver_mock:
            resolver_executor = _ResolverExecutor(default_resolver,
                                                  schema_field)
            resolver_executor.update_coercer = Mock()
            resolver_executor.update_func = Mock(
                wraps=resolver_executor.update_func)

            resolver_executor.bake(custom_default_resolver)

            resolver_executor.update_coercer.assert_called_once()

            if update_func_called:
                resolver_executor.update_func.assert_called_once_with(
                    custom_default_resolver)
            else:
                resolver_executor.update_func.assert_not_called()

            if default_subscription_resolver_called:
                default_subscription_resolver_mock.assert_called_once_with(
                    default_resolver)
            else:
                default_subscription_resolver_mock.assert_not_called()

            wraps_with_directives_mock.assert_called_once_with(
                directives_definition=schema_field.directives,
                directive_hook="on_field_execution",
                func=resolver_executor._raw_func,
            )