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

Commit

Permalink
Adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar committed May 12, 2019
1 parent 44ff1ed commit c5e87f7
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions watch/watch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from mock import Mock, call

from kubernetes import client

from .watch import Watch


Expand Down Expand Up @@ -275,6 +277,31 @@ def test_watch_with_exception(self):
fake_resp.close.assert_called_once()
fake_resp.release_conn.assert_called_once()

def test_watch_with_error_event(self):
fake_resp = Mock()
fake_resp.close = Mock()
fake_resp.release_conn = Mock()
fake_resp.read_chunked = Mock(
return_value=[
'{"type": "ERROR", "object": {"code": 410, '
'"reason": "Gone", "message": "error message"}}\n'])

fake_api = Mock()
fake_api.get_thing = Mock(return_value=fake_resp)

w = Watch()
try:
for _ in w.stream(fake_api.get_thing):
self.fail(self, "Should fail with ApiException.")
except client.rest.ApiException:
pass

fake_api.get_thing.assert_called_once_with(
_preload_content=False, watch=True)
fake_resp.read_chunked.assert_called_once_with(decode_content=False)
fake_resp.close.assert_called_once()
fake_resp.release_conn.assert_called_once()


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

0 comments on commit c5e87f7

Please sign in to comment.