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