service HelloService {
rpc SayHello(HelloReq) returns (HelloResp) {};
}
message HelloReq {
string Name = 1;
}
message HelloResp {
string Result = 1;
}
class HelloServicer(hello_pb2_grpc.HelloServiceServicer):
def SayHello(self, request, context):
if len(request.Name) >= 10:
msg = 'Length of `Name` cannot be more than 10 characters'
context.set_details(msg)
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
return hello_pb2.HelloResp()
return hello_pb2.HelloResp(Result="Hey, {}!".format(request.Name))We don't have a stand-alone example of unit testing a gRPC service (yet - I just filed grpc/grpc#17453). The APIs documented at https://grpc.io/grpc/python/grpc_testing.html are what you should be using, but the best I can do right now as far as pointing you to a "simple" usage of these is thetest_successful_unary_unarymethod in https://github.com/grpc/grpc/blob/master/src/python/grpcio_tests/tests/testing/_server_test.py
--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/c313a922-3f94-4bdb-9324-fb419b7d2c12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.