Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: watch returns raw_object if detection of returned objects fail #177

Merged
merged 1 commit into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kubernetes_asyncio/watch/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def unmarshal_event(self, data: str, response_type):

# If possible, compile the JSON response into a Python native response
# type, eg `V1Namespace` or `V1Pod`,`ExtensionsV1beta1Deployment`, ...
if response_type is not None:
if response_type:
js['object'] = self._api_client.deserialize(
response=SimpleNamespace(data=json.dumps(js['raw_object'])),
response_type=response_type
Expand Down
12 changes: 11 additions & 1 deletion kubernetes_asyncio/watch/watch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,24 @@ def test_unmarshal_with_float_object(self):
self.assertTrue(isinstance(event['object'], float))
self.assertEqual(1, event['raw_object'])

def test_unmarshal_with_no_return_type(self):
def test_unmarshal_without_return_type(self):
w = Watch()
event = w.unmarshal_event(
'{"type": "ADDED", "object": ["test1"]}', None)
self.assertEqual("ADDED", event['type'])
self.assertEqual(["test1"], event['object'])
self.assertEqual(["test1"], event['raw_object'])

def test_unmarshal_with_empty_return_type(self):
# empty string as a return_type is a default value
# if watch can't detect object by function's name
w = Watch()
event = w.unmarshal_event(
'{"type": "ADDED", "object": ["test1"]}', '')
self.assertEqual("ADDED", event['type'])
self.assertEqual(["test1"], event['object'])
self.assertEqual(["test1"], event['raw_object'])

async def test_unmarshall_k8s_error_response(self):
"""Never parse messages of type ERROR.

Expand Down