Skip to content

Commit

Permalink
fix: watch returns raw_object if detection of returned objects fail (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomplus committed Feb 2, 2022
1 parent 59a6e2a commit ef2fe15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

0 comments on commit ef2fe15

Please sign in to comment.