1from grpc import StatusCode
2from grpc.aio._call import AioRpcError
3
4import samples.greeter_pb2 as greeter_protos
5
6
7
8async def test_correct_credentials(grpc_client):
9 request = greeter_protos.GreetingRequest(name='Python')
10 response = await grpc_client.SayHello(
11 request=request, metadata=[('x-key', 'secret-credentials')],
12 )
13 assert response.greeting == 'Hello, Python!'
14
15
16async def test_incorrect_credentials(grpc_client):
17 request = greeter_protos.GreetingRequest(name='Python')
18
19 try:
20 await grpc_client.SayHello(
21 request=request, metadata=[('x-key', 'secretcredentials')],
22 )
23 assert False
24 except AioRpcError as err:
25 assert err.code() == StatusCode.PERMISSION_DENIED
26
27
28async def test_no_credentials(grpc_client):
29 request = greeter_protos.GreetingRequest(name='Python')
30
31 try:
32 await grpc_client.SayHello(request=request)
33 assert False
34 except AioRpcError as err:
35 assert err.code() == StatusCode.PERMISSION_DENIED
36
37
38