Skip to content

Commit c225ea3

Browse files
committed
Add FakeStreamUnaryCall to ease mocking
1 parent e8da66c commit c225ea3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

google/api_core/grpc_helpers_async.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,24 @@ def __init__(self, response=object()):
250250
def __await__(self):
251251
response = yield from self._future.__await__()
252252
return response
253+
254+
255+
class FakeStreamUnaryCall(_WrappedStreamUnaryCall):
256+
"""Fake implementation for stream-unary RPCs.
257+
258+
It is a dummy object for response message. Supply the intended response
259+
upon the initialization, and the coroutine will return the exact response
260+
message.
261+
"""
262+
263+
def __init__(self, response=object()):
264+
self.response = response
265+
self._future = asyncio.get_event_loop().create_future()
266+
self._future.set_result(self.response)
267+
268+
def __await__(self):
269+
response = yield from self._future.__await__()
270+
return response
271+
272+
async def wait_for_connection(self):
273+
pass

0 commit comments

Comments
 (0)