userver: samples/grpc_service/tests/test_grpc.py
Loading...
Searching...
No Matches
samples/grpc_service/tests/test_grpc.py
1import sys
2
3import pytest
4import samples.greeter_pb2 as greeter_protos # noqa: E402, E501
5
6
7# /// [grpc client test]
8async def test_grpc_client(service_client, mock_grpc_greeter):
9 @mock_grpc_greeter('SayHello')
10 async def _mock_say_hello(request, context):
11 return greeter_protos.GreetingResponse(
12 greeting=f'Hello, {request.name} from mockserver!',
13 )
14
15 response = await service_client.post(
16 '/hello', data='tests', headers={'Content-type': 'text/plain'},
17 )
18 assert response.status == 200
19 assert response.content == b'Hello, tests from mockserver!'
20
21 assert _mock_say_hello.times_called == 1
22 # /// [grpc client test]
23
24
25@pytest.mark.skipif(
26 sys.platform == 'darwin', reason='this test fails in old packages',
27)
28# /// [grpc server test]
29async def test_say_hello(grpc_client):
30 request = greeter_protos.GreetingRequest(name='Python')
31 response = await grpc_client.SayHello(request)
32 assert response.greeting == 'Hello, Python!'
33 # /// [grpc server test]