def test_wrap_method_with_no_client_info():
    method = mock.Mock(spec=['__call__'])

    wrapped_method = google.api_core.gapic_v1.method.wrap_method(
        method, client_info=None)

    wrapped_method(1, 2, meep='moop')

    method.assert_called_once_with(1, 2, meep='moop')
Exemplo n.º 2
0
def test_wrap_method_with_no_client_info():
    method = mock.Mock(spec=["__call__"])

    wrapped_method = google.api_core.gapic_v1.method.wrap_method(
        method, client_info=None)

    wrapped_method(1, 2, meep="moop")

    method.assert_called_once_with(1, 2, meep="moop")
Exemplo n.º 3
0
def test_invoke_wrapped_method_with_metadata_as_none():
    method = mock.Mock(spec=["__call__"])

    wrapped_method = google.api_core.gapic_v1.method.wrap_method(method)

    wrapped_method(mock.sentinel.request, metadata=None)

    method.assert_called_once_with(mock.sentinel.request, metadata=mock.ANY)
    metadata = method.call_args[1]["metadata"]
    # Metadata should have just one items: the client info metadata.
    assert len(metadata) == 1
def test_invoke_wrapped_method_with_metadata_as_none():
    method = mock.Mock(spec=['__call__'])

    wrapped_method = google.api_core.gapic_v1.method.wrap_method(method)

    wrapped_method(mock.sentinel.request, metadata=None)

    method.assert_called_once_with(mock.sentinel.request, metadata=mock.ANY)
    metadata = method.call_args[1]['metadata']
    # Metadata should have just one items: the client info metadata.
    assert len(metadata) == 1
def test_wrap_method_with_overriding_timeout_as_a_number():
    method = mock.Mock(spec=['__call__'], return_value=42)
    default_retry = retry.Retry()
    default_timeout = timeout.ConstantTimeout(60)
    wrapped_method = google.api_core.gapic_v1.method.wrap_method(
        method, default_retry, default_timeout)

    result = wrapped_method(timeout=22)

    assert result == 42
    method.assert_called_once_with(timeout=22, metadata=mock.ANY)
Exemplo n.º 6
0
def test_wrap_method_with_overriding_timeout_as_a_number():
    method = mock.Mock(spec=["__call__"], return_value=42)
    default_retry = retry.Retry()
    default_timeout = timeout.ConstantTimeout(60)
    wrapped_method = google.api_core.gapic_v1.method.wrap_method(
        method, default_retry, default_timeout)

    result = wrapped_method(timeout=22)

    assert result == 42
    method.assert_called_once_with(timeout=22, metadata=mock.ANY)
Exemplo n.º 7
0
def test_invoke_wrapped_method_with_metadata():
    method = mock.Mock(spec=["__call__"])

    wrapped_method = google.api_core.gapic_v1.method.wrap_method(method)

    wrapped_method(mock.sentinel.request, metadata=[("a", "b")])

    method.assert_called_once_with(mock.sentinel.request, metadata=mock.ANY)
    metadata = method.call_args[1]["metadata"]
    # Metadata should have two items: the client info metadata and our custom
    # metadata.
    assert len(metadata) == 2
    assert ("a", "b") in metadata
def test_invoke_wrapped_method_with_metadata():
    method = mock.Mock(spec=['__call__'])

    wrapped_method = google.api_core.gapic_v1.method.wrap_method(method)

    wrapped_method(mock.sentinel.request, metadata=[('a', 'b')])

    method.assert_called_once_with(mock.sentinel.request, metadata=mock.ANY)
    metadata = method.call_args[1]['metadata']
    # Metadata should have two items: the client info metadata and our custom
    # metadata.
    assert len(metadata) == 2
    assert ('a', 'b') in metadata
Exemplo n.º 9
0
def test_wrap_method_basic():
    method = mock.Mock(spec=["__call__"], return_value=42)

    wrapped_method = google.api_core.gapic_v1.method.wrap_method(method)

    result = wrapped_method(1, 2, meep="moop")

    assert result == 42
    method.assert_called_once_with(1, 2, meep="moop", metadata=mock.ANY)

    # Check that the default client info was specified in the metadata.
    metadata = method.call_args[1]["metadata"]
    assert len(metadata) == 1
    client_info = google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO
    user_agent_metadata = client_info.to_grpc_metadata()
    assert user_agent_metadata in metadata
Exemplo n.º 10
0
def test_wrap_method_with_custom_client_info():
    client_info = google.api_core.gapic_v1.client_info.ClientInfo(
        python_version=1, grpc_version=2, api_core_version=3, gapic_version=4,
        client_library_version=5)
    method = mock.Mock(spec=['__call__'])

    wrapped_method = google.api_core.gapic_v1.method.wrap_method(
        method, client_info=client_info)

    wrapped_method(1, 2, meep='moop')

    method.assert_called_once_with(1, 2, meep='moop', metadata=mock.ANY)

    # Check that the custom client info was specified in the metadata.
    metadata = method.call_args[1]['metadata']
    assert client_info.to_grpc_metadata() in metadata
Exemplo n.º 11
0
def test_wrap_method_basic():
    method = mock.Mock(spec=['__call__'], return_value=42)

    wrapped_method = google.api_core.gapic_v1.method.wrap_method(method)

    result = wrapped_method(1, 2, meep='moop')

    assert result == 42
    method.assert_called_once_with(1, 2, meep='moop', metadata=mock.ANY)

    # Check that the default client info was specified in the metadata.
    metadata = method.call_args[1]['metadata']
    assert len(metadata) == 1
    client_info = google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO
    user_agent_metadata = client_info.to_grpc_metadata()
    assert user_agent_metadata in metadata
Exemplo n.º 12
0
def test_wrap_method_with_custom_client_info():
    client_info = google.api_core.gapic_v1.client_info.ClientInfo(
        python_version=1, grpc_version=2, api_core_version=3, gapic_version=4,
        client_library_version=5)
    method = mock.Mock(spec=['__call__'])

    wrapped_method = google.api_core.gapic_v1.method.wrap_method(
        method, client_info=client_info)

    wrapped_method(1, 2, meep='moop')

    method.assert_called_once_with(1, 2, meep='moop', metadata=mock.ANY)

    # Check that the custom client info was specified in the metadata.
    metadata = method.call_args[1]['metadata']
    assert client_info.to_grpc_metadata() in metadata