userver: samples/grpc_service/testsuite/conftest.py
Loading...
Searching...
No Matches
samples/grpc_service/testsuite/conftest.py
1# /// [Prepare modules]
2import pytest
3
4import samples.greeter_pb2_grpc as greeter_services # noqa: E402, E501
5
6pytest_plugins = ['pytest_userver.plugins.grpc']
7# /// [Prepare modules]
8
9# /// [Prepare configs]
10USERVER_CONFIG_HOOKS = ['prepare_service_config']
11
12
13@pytest.fixture(scope='session')
14def prepare_service_config(grpc_mockserver_endpoint):
15 def patch_config(config, config_vars):
16 components = config['components_manager']['components']
17 components['greeter-client']['endpoint'] = grpc_mockserver_endpoint
18
19 return patch_config
20 # /// [Prepare configs]
21
22
23# /// [Prepare server mock]
24@pytest.fixture(name='mock_grpc_greeter_session', scope='session')
25def _mock_grpc_greeter_session(grpc_mockserver, create_grpc_mock):
26 mock = create_grpc_mock(
27 greeter_services.GreeterServiceServicer,
28 stream_method_names=['SayHelloResponseStream', 'SayHelloStreams'],
29 )
30 greeter_services.add_GreeterServiceServicer_to_server(
31 mock.servicer, grpc_mockserver,
32 )
33 return mock
34
35
36@pytest.fixture
37def mock_grpc_greeter(mock_grpc_greeter_session):
38 with mock_grpc_greeter_session.mock() as mock:
39 yield mock
40 # /// [Prepare server mock]
41
42
43# /// [grpc client]
44@pytest.fixture
45def grpc_client(grpc_channel, service_client):
46 return greeter_services.GreeterServiceStub(grpc_channel)
47 # /// [grpc client]