def test_one_to_one(self):
     server = self.create_server(self._Servicer())
     server.start()
     try:
         client = self.create_client()
         response = client.GetOneToOne(
             test_pb2.TestRequest(message='message0'))
         self.assertEqual(test_pb2.TestResponse, type(response))
         self.assertEqual('response: message0', response.message)
     finally:
         server.stop(None)
 def test_stream_to_one(self):
     server = self.create_server(self._Servicer())
     server.start()
     try:
         client = self.create_client()
         response = client.GetStreamToOne(
             (test_pb2.TestRequest(message='message{}'.format(i))
              for i in range(3)))
         self.assertEqual(test_pb2.TestResponse, type(response))
         self.assertEqual('response: message0, message1, message2',
                          response.message)
     finally:
         server.stop(None)
 def test_one_to_stream(self):
     server = self.create_server(self._Servicer())
     server.start()
     try:
         client = self.create_client()
         responses = list(
             client.GetOneToStream(
                 test_pb2.TestRequest(message='message0')))
         self.assertEqual(3, len(responses))
         for i, response in enumerate(responses):
             self.assertEqual(test_pb2.TestResponse, type(response))
             self.assertEqual('response {}: message0'.format(i),
                              response.message)
     finally:
         server.stop(None)
    def test_stream_to_stream(self):
        server = self.create_server(self._Servicer())
        server.start()

        responses = []
        try:
            client = self.create_client()
            responses.extend(
                client.GetStreamToStream(
                    (test_pb2.TestRequest(message='message{}'.format(i))
                     for i in range(3))))
            self.assertEqual(3, len(responses))
            for i, response in enumerate(responses):
                self.assertEqual(test_pb2.TestResponse, type(response))
                self.assertEqual('response: message{}'.format(i),
                                 response.message)
        finally:
            server.stop(None)
Beispiel #5
0
    def test_message_transformation(self):
        def _transform_message(m: test_pb2.TestRequest) -> test_pb2.TestRequest:
            return test_pb2.TestRequest(message='TRANSFORMED {}'.format(m.message))

        server = self.create_server(self._Servicer())
        server.set_grpc_observable(
            server.grpc_pipe(
                operators.map(_transform_message),
                method_name='/rxgrpc.test.TestService/GetOneToOne'),
            method_name='/rxgrpc.test.TestService/GetOneToOne'
        )
        server.start()
        try:
            client = self.create_client()
            response = client.GetOneToOne(test_pb2.TestRequest(message='message0'))
            self.assertEqual(test_pb2.TestResponse, type(response))
            self.assertEqual('response: TRANSFORMED message0', response.message)
        finally:
            server.stop(None)
    def test_message_transformation_stream(self):
        def _filter_message(m: test_pb2.TestRequest) -> test_pb2.TestRequest:
            return bool(int(m.message[-1]) % 2)

        server = self.create_server(self._Servicer())
        server.set_grpc_observable(
            server.grpc_pipe(
                operators.filter(_filter_message),
                method_name='/rxgrpc.test.TestService/GetStreamToOne'),
            method_name='/rxgrpc.test.TestService/GetStreamToOne')
        server.start()
        try:
            client = self.create_client()
            response = client.GetStreamToOne(
                (test_pb2.TestRequest(message='message{}'.format(i))
                 for i in range(4)))
            self.assertEqual(test_pb2.TestResponse, type(response))
            self.assertEqual('response: message1, message3', response.message)
        finally:
            server.stop(None)
 def _transform_message(
         m: test_pb2.TestRequest) -> test_pb2.TestRequest:
     return test_pb2.TestRequest(
         message='TRANSFORMED {}'.format(m.message))