Fix parameters missing from services (#381)
This commit is contained in:
committed by
GitHub
parent
bc13e7070d
commit
3fd5a0d662
@@ -9,6 +9,7 @@ xfail = {
|
||||
}
|
||||
|
||||
services = {
|
||||
"googletypes_request",
|
||||
"googletypes_response",
|
||||
"googletypes_response_embedded",
|
||||
"service",
|
||||
|
29
tests/inputs/googletypes_request/googletypes_request.proto
Normal file
29
tests/inputs/googletypes_request/googletypes_request.proto
Normal file
@@ -0,0 +1,29 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package googletypes_request;
|
||||
|
||||
import "google/protobuf/duration.proto";
|
||||
import "google/protobuf/empty.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
||||
// Tests that google types can be used as params
|
||||
|
||||
service Test {
|
||||
rpc SendDouble (google.protobuf.DoubleValue) returns (Input);
|
||||
rpc SendFloat (google.protobuf.FloatValue) returns (Input);
|
||||
rpc SendInt64 (google.protobuf.Int64Value) returns (Input);
|
||||
rpc SendUInt64 (google.protobuf.UInt64Value) returns (Input);
|
||||
rpc SendInt32 (google.protobuf.Int32Value) returns (Input);
|
||||
rpc SendUInt32 (google.protobuf.UInt32Value) returns (Input);
|
||||
rpc SendBool (google.protobuf.BoolValue) returns (Input);
|
||||
rpc SendString (google.protobuf.StringValue) returns (Input);
|
||||
rpc SendBytes (google.protobuf.BytesValue) returns (Input);
|
||||
rpc SendDatetime (google.protobuf.Timestamp) returns (Input);
|
||||
rpc SendTimedelta (google.protobuf.Duration) returns (Input);
|
||||
rpc SendEmpty (google.protobuf.Empty) returns (Input);
|
||||
}
|
||||
|
||||
message Input {
|
||||
|
||||
}
|
47
tests/inputs/googletypes_request/test_googletypes_request.py
Normal file
47
tests/inputs/googletypes_request/test_googletypes_request.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from datetime import (
|
||||
datetime,
|
||||
timedelta,
|
||||
)
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
)
|
||||
|
||||
import pytest
|
||||
|
||||
import betterproto.lib.google.protobuf as protobuf
|
||||
from tests.mocks import MockChannel
|
||||
from tests.output_betterproto.googletypes_request import (
|
||||
Input,
|
||||
TestStub,
|
||||
)
|
||||
|
||||
|
||||
test_cases = [
|
||||
(TestStub.send_double, protobuf.DoubleValue, 2.5),
|
||||
(TestStub.send_float, protobuf.FloatValue, 2.5),
|
||||
(TestStub.send_int64, protobuf.Int64Value, -64),
|
||||
(TestStub.send_u_int64, protobuf.UInt64Value, 64),
|
||||
(TestStub.send_int32, protobuf.Int32Value, -32),
|
||||
(TestStub.send_u_int32, protobuf.UInt32Value, 32),
|
||||
(TestStub.send_bool, protobuf.BoolValue, True),
|
||||
(TestStub.send_string, protobuf.StringValue, "string"),
|
||||
(TestStub.send_bytes, protobuf.BytesValue, bytes(0xFF)[0:4]),
|
||||
(TestStub.send_datetime, protobuf.Timestamp, datetime(2038, 1, 19, 3, 14, 8)),
|
||||
(TestStub.send_timedelta, protobuf.Duration, timedelta(seconds=123456)),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(["service_method", "wrapper_class", "value"], test_cases)
|
||||
async def test_channel_receives_wrapped_type(
|
||||
service_method: Callable[[TestStub, Input], Any], wrapper_class: Callable, value
|
||||
):
|
||||
wrapped_value = wrapper_class()
|
||||
wrapped_value.value = value
|
||||
channel = MockChannel(responses=[Input()])
|
||||
service = TestStub(channel)
|
||||
|
||||
await service_method(service, wrapped_value)
|
||||
|
||||
assert channel.requests[0]["request"] == type(wrapped_value)
|
Reference in New Issue
Block a user