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