10000 unit test for metadata intialize · googleapis/google-cloud-python@4f16bdb · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f16bdb

Browse files
committed
unit test for metadata intialize
doc comment improvements
1 parent 56b57e3 commit 4f16bdb

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

api_core/google/api_core/bidi.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ class BidiRpc(object):
147147
148148
initial_request = example_pb2.StreamingRpcRequest(
149149
setting='example')
150-
rpc = BidiRpc(stub.StreamingRpc, initial_request=initial_request)
150+
rpc = BidiRpc(
151+
stub.StreamingRpc,
152+
initial_request=initial_request,
153+
metadata=[('name', 'value')]
154+
)
151155
152156
rpc.open()
153157
@@ -165,14 +169,14 @@ class BidiRpc(object):
165169
Callable[None, protobuf.Message]]): The initial request to
166170
yield. This is useful if an initial request is needed to start the
167171
stream.
168-
rpc_metadata Sequence[Tuple(str, str)]: RPC metadata to include in
172+
metadata (Sequence[Tuple(str, str)]): RPC metadata to include in
169173
the request.
170174
"""
171175

172-
def __init__(self, start_rpc, initial_request=None, rpc_metadata=None):
176+
def __init__(self, start_rpc, initial_request=None, metadata=None):
173177
self._start_rpc = start_rpc
174178
self._initial_request = initial_request
175-
self._rpc_metadata = rpc_metadata
179+
self._rpc_metadata = metadata
176180
self._request_queue = queue.Queue()
177181
self._request_generator = None
178182
self._is_active = False
@@ -291,10 +295,14 @@ def should_recover(exc):
291295
initial_request = example_pb2.StreamingRpcRequest(
292296
setting='example')
293297
294-
rpc = ResumeableBidiRpc(
298+
metadata = [('header_name', 'value')]
299+
300+
rpc = ResumableBidiRpc(
295301
stub.StreamingRpc,
302+
should_recover=should_recover,
296303
initial_request=initial_request,
297-
should_recover=should_recover)
304+
metadata=metadata
305+
)
298306
299307
rpc.open()
300308
@@ -313,13 +321,12 @@ def should_recover(exc):
313321
should_recover (Callable[[Exception], bool]): A function that returns
314322
True if th 8000 e stream should be recovered. This will be called
315323
whenever an error is encountered on the stream.
316-
def _rpc_metadata(self):
317-
rpc_metadata Sequence[Tuple(str, str)]: RPC metadata to include in
324+
metadata Sequence[Tuple(str, str)]: RPC metadata to include in
318325
the request.
319326
"""
320327

321-
def __init__(self, start_rpc, should_recover, initial_request=None, rpc_metadata=None):
322-
super(ResumableBidiRpc, self).__init__(start_rpc, initial_request, rpc_metadata)
328+
def __init__(self, start_rpc, should_recover, initial_request=None, metadata=None):
329+
super(ResumableBidiRpc, self).__init__(start_rpc, initial_request, metadata)
323330
self._should_recover = should_recover
324331
self._operational_lock = threading.RLock()
325332
self._finalized = False

api_core/tests/unit/test_bidi.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ def test_done_callbacks(self):
173173

174174
callback.assert_called_once_with(mock.sentinel.future)
175175

176+
def test_metadata(self):
177+
rpc, call = make_rpc()
178+
bidi_rpc = bidi.BidiRpc(rpc, metadata=mock.sentinel.A)
179+
assert bidi_rpc._rpc_metadata == mock.sentinel.A
180+
181+
bidi_rpc.open()
182+
assert bidi_rpc.call == call
183+
assert bidi_rpc.call.metadata == mock.sentinel.A
184+
176185
def test_open(self):
177186
rpc, call = make_rpc()
178187
bidi_rpc = bidi.BidiRpc(rpc)

0 commit comments

Comments
 (0)
0