1
2import pytest
3
4import samples.greeter_pb2_grpc as greeter_services
5
6pytest_plugins = ['pytest_userver.plugins.grpc']
7
8
9
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
21
22
23
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
38
39
40
41@pytest.fixture
42def grpc_client(grpc_channel):
43 return greeter_services.GreeterServiceStub(grpc_channel)
44