Test Service instantiation as part of standard test-case

This commit is contained in:
boukeversteegh 2020-05-24 20:02:41 +02:00
parent 20150fdcf3
commit ec5683e572
4 changed files with 14 additions and 7 deletions

View File

@ -10,6 +10,6 @@ message DoThingResponse {
int32 successfulIterations = 1;
}
service ExampleService {
service Test {
rpc DoThing (DoThingRequest) returns (DoThingResponse);
}

View File

@ -7,7 +7,7 @@ from typing import Dict
from betterproto.tests.output_betterproto.service.service import (
DoThingResponse,
DoThingRequest,
ExampleServiceStub,
TestStub as ExampleServiceStub,
)
@ -29,12 +29,12 @@ class ExampleService:
def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
return {
"/service.ExampleService/DoThing": grpclib.const.Handler(
"/service.Test/DoThing": grpclib.const.Handler(
self.DoThing,
grpclib.const.Cardinality.UNARY_UNARY,
DoThingRequest,
DoThingResponse,
)
),
}
@ -99,7 +99,7 @@ async def test_service_call_lower_level_with_overrides():
) as channel:
stub = ExampleServiceStub(channel, deadline=deadline, metadata=metadata)
response = await stub._unary_unary(
"/service.ExampleService/DoThing",
"/service.Test/DoThing",
DoThingRequest(ITERATIONS),
DoThingResponse,
deadline=kwarg_deadline,
@ -123,7 +123,7 @@ async def test_service_call_lower_level_with_overrides():
) as channel:
stub = ExampleServiceStub(channel, deadline=deadline, metadata=metadata)
response = await stub._unary_unary(
"/service.ExampleService/DoThing",
"/service.Test/DoThing",
DoThingRequest(ITERATIONS),
DoThingResponse,
timeout=kwarg_timeout,

View File

@ -5,7 +5,7 @@ from grpclib.client import Channel
class MockChannel(Channel):
# noinspection PyMissingConstructor
def __init__(self, responses: List) -> None:
def __init__(self, responses: List = []) -> None:
self.responses = responses
self.requests = []

View File

@ -9,6 +9,7 @@ import pytest
import betterproto
from betterproto.tests.inputs import xfail
from betterproto.tests.mocks import MockChannel
from betterproto.tests.util import get_directories, get_test_case_json_data, inputs_path
# Force pure-python implementation instead of C++, otherwise imports
@ -113,6 +114,12 @@ def test_message_json(repeat, test_data: TestData) -> None:
assert json.loads(json_data) == json.loads(message_json)
@pytest.mark.parametrize("test_data", test_cases.services, indirect=True)
def test_service_can_be_instantiated(test_data: TestData) -> None:
plugin_module, _, json_data = test_data
plugin_module.TestStub(MockChannel())
@pytest.mark.parametrize("test_data", test_cases.messages_with_json, indirect=True)
def test_binary_compatibility(repeat, test_data: TestData) -> None:
plugin_module, reference_module, json_data = test_data