Пример #1
0
    def testDefineService(self):
        """Test service definition from descriptor."""
        method_descriptor = descriptor.MethodDescriptor()
        method_descriptor.name = 'get_quote'
        method_descriptor.request_type = 'GetQuoteRequest'
        method_descriptor.response_type = 'GetQuoteResponse'

        service_descriptor = descriptor.ServiceDescriptor()
        service_descriptor.name = 'Stocks'
        service_descriptor.methods = [method_descriptor]

        StockService = definition.define_service(service_descriptor,
                                                 self.module)

        self.assertTrue(issubclass(StockService, remote.Service))
        self.assertTrue(issubclass(StockService.Stub, remote.StubBase))

        request = self.module.GetQuoteRequest()
        service = StockService()
        self.assertRaises(NotImplementedError, service.get_quote, request)

        self.assertEquals(self.module.GetQuoteRequest,
                          service.get_quote.remote.request_type)
        self.assertEquals(self.module.GetQuoteResponse,
                          service.get_quote.remote.response_type)
Пример #2
0
    def testDescribe(self):
        class Request(messages.Message):
            pass

        class Response(messages.Message):
            pass

        @remote.method(Request, Response)
        def remote_method(request):
            pass

        module_name = test_util.get_module_name(DescribeMethodTest)
        expected = descriptor.MethodDescriptor()
        expected.name = 'remote_method'
        expected.request_type = '%s.Request' % module_name
        expected.response_type = '%s.Response' % module_name

        described = descriptor.describe_method(remote_method)
        described.check_initialized()
        self.assertEquals(expected, described)
Пример #3
0
    def testService(self):
        service = descriptor.ServiceDescriptor()
        service.name = 'TheService'

        method1 = descriptor.MethodDescriptor()
        method1.name = 'method1'
        method1.request_type = 'protorpc.descriptor.FileDescriptor'
        method1.response_type = 'protorpc.descriptor.MethodDescriptor'

        service.methods = [method1]

        file_descriptor = descriptor.FileDescriptor()
        file_descriptor.service_types = [service]

        self.DoPythonTest(file_descriptor)

        # Test to make sure that implementation methods raise an exception.
        import blank
        service_instance = blank.TheService()
        self.assertRaisesWithRegexpMatch(NotImplementedError,
                                         'Method method1 is not implemented',
                                         service_instance.method1,
                                         descriptor.FileDescriptor())