1. youngking
  2. protorpc

Commits

rafek  committed 12fde24

Additional tests for method overriding

  • Participants
  • Parent commits 14e41e0
  • Branches default

Comments (0)

Files changed (2)

File python/protorpc/remote.py

View file
 service.  It also has convenience methods for creating factory functions that
 can pass persistent global state to a new service instance.
 
-The 'remote' decorator is used to declare which methods of a class are
+The 'method' decorator is used to declare which methods of a class are
 meant to service RPCs.  While this decorator is not responsible for handling
 actual remote method invocations, such as handling sockets, handling various
 RPC protocols and checking messages for correctness, it does attach information
 
           if get_remote_method_info(value):
             raise ServiceDefinitionError(
-              'Do not use remote decorator when overloading remote method %s '
+              'Do not use method decorator when overloading remote method %s '
               'on service %s.' %
               (attribute, name))
 

File python/protorpc/remote_test.py

View file
                       repr(remote.ApplicationError('an error')))
 
 
-class RemoteTest(test_util.TestCase):
+class MethodTest(test_util.TestCase):
   """Test remote method decorator."""
 
-  def testRemote(self):
+  def testMethod(self):
     """Test use of remote decorator."""
     self.assertEquals(SimpleRequest,
                       BasicService.remote_method.remote.request_type)
     self.assertTrue(isinstance(BasicService.remote_method.remote.method,
                                types.FunctionType))
 
-  def testRemoteMessageResolution(self):
+  def testMethodMessageResolution(self):
     """Test use of remote decorator to resolve message types by name."""
     class OtherService(remote.Service):
 
     self.assertEquals(SimpleResponse,
                       OtherService.remote_method.remote.response_type)
 
-  def testRemoteMessageResolution_NotFound(self):
+  def testMethodMessageResolution_NotFound(self):
     """Test failure to find message types."""
     class OtherService(remote.Service):
 
     class SubClass(MyService):
 
       def remote_method(self, request):
-        pass
+        response = super(SubClass, self).remote_method(request)
+        response.value = '(%s)' % response.value
+        return response
 
     self.assertEquals({'remote_method': SubClass.remote_method,
                       },
                       SubClass.all_remote_methods())
 
+    instance = SubClass()
+    self.assertEquals('(Hello)',
+                      instance.remote_method(Request(value='Hello')).value)
+    self.assertEquals(Request, SubClass.remote_method.remote.request_type)
+    self.assertEquals(Response, SubClass.remote_method.remote.response_type)
+
   def testOverrideMethodWithRemote(self):
     """Test trying to override a remote method with remote decorator."""
     def do_override():
           pass
 
     self.assertRaisesWithRegexpMatch(remote.ServiceDefinitionError,
-                                     'Do not use remote decorator when '
+                                     'Do not use method decorator when '
                                      'overloading remote method remote_method '
                                      'on service SubClass',
                                      do_override)