Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit c5e87f7

Browse files
committed
Adding tests.
1 parent 44ff1ed commit c5e87f7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: watch/watch_test.py

+27
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
from mock import Mock, call
2020

21+
from kubernetes import client
22+
2123
from .watch import Watch
2224

2325

@@ -275,6 +277,31 @@ def test_watch_with_exception(self):
275277
fake_resp.close.assert_called_once()
276278
fake_resp.release_conn.assert_called_once()
277279

280+
def test_watch_with_error_event(self):
281+
fake_resp = Mock()
282+
fake_resp.close = Mock()
283+
fake_resp.release_conn = Mock()
284+
fake_resp.read_chunked = Mock(
285+
return_value=[
286+
'{"type": "ERROR", "object": {"code": 410, '
287+
'"reason": "Gone", "message": "error message"}}\n'])
288+
289+
fake_api = Mock()
290+
fake_api.get_thing = Mock(return_value=fake_resp)
291+
292+
w = Watch()
293+
try:
294+
for _ in w.stream(fake_api.get_thing):
295+
self.fail(self, "Should fail with ApiException.")
296+
except client.rest.ApiException:
297+
pass
298+
299+
fake_api.get_thing.assert_called_once_with(
300+
_preload_content=False, watch=True)
301+
fake_resp.read_chunked.assert_called_once_with(decode_content=False)
302+
fake_resp.close.assert_called_once()
303+
fake_resp.release_conn.assert_called_once()
304+
278305

279306
if __name__ == '__main__':
280307
unittest.main()

0 commit comments

Comments
 (0)