|
|
|
@ -33,7 +33,7 @@ from tests.unit.framework.common import test_constants |
|
|
|
|
import tests.protoc_plugin.protos.payload.test_payload_pb2 as payload_pb2 |
|
|
|
|
import tests.protoc_plugin.protos.requests.r.test_requests_pb2 as request_pb2 |
|
|
|
|
import tests.protoc_plugin.protos.responses.test_responses_pb2 as response_pb2 |
|
|
|
|
import tests.protoc_plugin.protos.service.test_service_pb2 as service_pb2 |
|
|
|
|
import tests.protoc_plugin.protos.service.test_service_pb2_grpc as service_pb2_grpc |
|
|
|
|
|
|
|
|
|
# Identifiers of entities we expect to find in the generated module. |
|
|
|
|
STUB_IDENTIFIER = 'TestServiceStub' |
|
|
|
@ -138,7 +138,7 @@ def _CreateService(): |
|
|
|
|
""" |
|
|
|
|
servicer_methods = _ServicerMethods() |
|
|
|
|
|
|
|
|
|
class Servicer(getattr(service_pb2, SERVICER_IDENTIFIER)): |
|
|
|
|
class Servicer(getattr(service_pb2_grpc, SERVICER_IDENTIFIER)): |
|
|
|
|
|
|
|
|
|
def UnaryCall(self, request, context): |
|
|
|
|
return servicer_methods.UnaryCall(request, context) |
|
|
|
@ -157,11 +157,12 @@ def _CreateService(): |
|
|
|
|
|
|
|
|
|
server = grpc.server( |
|
|
|
|
futures.ThreadPoolExecutor(max_workers=test_constants.POOL_SIZE)) |
|
|
|
|
getattr(service_pb2, ADD_SERVICER_TO_SERVER_IDENTIFIER)(Servicer(), server) |
|
|
|
|
getattr(service_pb2_grpc, ADD_SERVICER_TO_SERVER_IDENTIFIER)(Servicer(), |
|
|
|
|
server) |
|
|
|
|
port = server.add_insecure_port('[::]:0') |
|
|
|
|
server.start() |
|
|
|
|
channel = grpc.insecure_channel('localhost:{}'.format(port)) |
|
|
|
|
stub = getattr(service_pb2, STUB_IDENTIFIER)(channel) |
|
|
|
|
stub = getattr(service_pb2_grpc, STUB_IDENTIFIER)(channel) |
|
|
|
|
return _Service(servicer_methods, server, stub) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -173,16 +174,17 @@ def _CreateIncompleteService(): |
|
|
|
|
servicer_methods implements none of the methods required of it. |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
class Servicer(getattr(service_pb2, SERVICER_IDENTIFIER)): |
|
|
|
|
class Servicer(getattr(service_pb2_grpc, SERVICER_IDENTIFIER)): |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
server = grpc.server( |
|
|
|
|
futures.ThreadPoolExecutor(max_workers=test_constants.POOL_SIZE)) |
|
|
|
|
getattr(service_pb2, ADD_SERVICER_TO_SERVER_IDENTIFIER)(Servicer(), server) |
|
|
|
|
getattr(service_pb2_grpc, ADD_SERVICER_TO_SERVER_IDENTIFIER)(Servicer(), |
|
|
|
|
server) |
|
|
|
|
port = server.add_insecure_port('[::]:0') |
|
|
|
|
server.start() |
|
|
|
|
channel = grpc.insecure_channel('localhost:{}'.format(port)) |
|
|
|
|
stub = getattr(service_pb2, STUB_IDENTIFIER)(channel) |
|
|
|
|
stub = getattr(service_pb2_grpc, STUB_IDENTIFIER)(channel) |
|
|
|
|
return _Service(None, server, stub) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -223,10 +225,11 @@ class PythonPluginTest(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
def testImportAttributes(self): |
|
|
|
|
# check that we can access the generated module and its members. |
|
|
|
|
self.assertIsNotNone(getattr(service_pb2, STUB_IDENTIFIER, None)) |
|
|
|
|
self.assertIsNotNone(getattr(service_pb2, SERVICER_IDENTIFIER, None)) |
|
|
|
|
self.assertIsNotNone(getattr(service_pb2_grpc, STUB_IDENTIFIER, None)) |
|
|
|
|
self.assertIsNotNone( |
|
|
|
|
getattr(service_pb2, ADD_SERVICER_TO_SERVER_IDENTIFIER, None)) |
|
|
|
|
getattr(service_pb2_grpc, SERVICER_IDENTIFIER, None)) |
|
|
|
|
self.assertIsNotNone( |
|
|
|
|
getattr(service_pb2_grpc, ADD_SERVICER_TO_SERVER_IDENTIFIER, None)) |
|
|
|
|
|
|
|
|
|
def testUpDown(self): |
|
|
|
|
service = _CreateService() |
|
|
|
|