userver: samples/grpc_middleware_service/tests/conftest.py
Loading...
Searching...
No Matches
samples/grpc_middleware_service/tests/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(greeter_services.GreeterServiceServicer)
27 greeter_services.add_GreeterServiceServicer_to_server(
28 mock.servicer, grpc_mockserver,
29 )
30 return mock
31
32
33@pytest.fixture
34def mock_grpc_greeter(mock_grpc_greeter_session):
35 with mock_grpc_greeter_session.mock() as mock:
36 yield mock
37 # /// [Prepare server mock]
38
39
40# /// [grpc client]
41@pytest.fixture
42def grpc_client(grpc_channel):
43 return greeter_services.GreeterServiceStub(grpc_channel)
44 # /// [grpc client]