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(
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
41
42
43
44@pytest.fixture
45def grpc_client(grpc_channel, service_client):
46 return greeter_services.GreeterServiceStub(grpc_channel)
47