Пример #1
0
 def read_blob(self, ctx, blob_key):
     with timing.log_latency("build request"):
         req = data_provider_pb2.ReadBlobRequest()
         req.blob_key = blob_key
     with timing.log_latency("list(_stub.ReadBlob)"):
         with _translate_grpc_error():
             responses = list(self._stub.ReadBlob(req))
     with timing.log_latency("build result"):
         return b"".join(res.data for res in responses)
Пример #2
0
    def test_read_blob(self):
        responses = [
            data_provider_pb2.ReadBlobResponse(data=b"hello wo"),
            data_provider_pb2.ReadBlobResponse(data=b"rld"),
        ]
        self.stub.ReadBlob.return_value = responses

        actual = self.provider.read_blob(self.ctx, blob_key="myblob")
        expected = b"hello world"
        self.assertEqual(actual, expected)

        req = data_provider_pb2.ReadBlobRequest()
        req.blob_key = "myblob"
        self.stub.ReadBlob.assert_called_once_with(req)