This repository has been archived by the owner on Oct 3, 2020. It is now read-only.
forked from kelproject/pykube
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remember the streaming response object in watch-queries (#31)
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from pykube import Pod | ||
from pykube.query import Query | ||
|
||
|
||
@pytest.fixture | ||
def api(): | ||
return MagicMock() | ||
|
||
|
||
def test_watch_response_exists(api): | ||
stream = Query(api, Pod).watch() | ||
assert hasattr(stream, 'response') | ||
assert stream.response is None # not yet executed | ||
|
||
|
||
def test_watch_response_is_readonly(api): | ||
stream = Query(api, Pod).watch() | ||
with pytest.raises(AttributeError): | ||
stream.response = object() | ||
|
||
|
||
def test_watch_response_is_set_on_iter(api): | ||
line1 = json.dumps({'type': 'ADDED', 'object': {}}).encode('utf-8') | ||
expected_response = MagicMock() | ||
expected_response.iter_lines.return_value = [line1] | ||
api.get.return_value = expected_response | ||
|
||
stream = Query(api, Pod).watch() | ||
next(iter(stream)) | ||
|
||
assert stream.response is expected_response | ||
|
||
assert api.get.call_count == 1 | ||
assert api.get.call_args_list[0][1]['stream'] is True | ||
assert 'watch=true' in api.get.call_args_list[0][1]['url'] |