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