diff --git a/kubernetes_asyncio/watch/watch.py b/kubernetes_asyncio/watch/watch.py index d44e2d08d..209dc26f1 100644 --- a/kubernetes_asyncio/watch/watch.py +++ b/kubernetes_asyncio/watch/watch.py @@ -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 diff --git a/kubernetes_asyncio/watch/watch_test.py b/kubernetes_asyncio/watch/watch_test.py index 1cac48322..23b1827ec 100644 --- a/kubernetes_asyncio/watch/watch_test.py +++ b/kubernetes_asyncio/watch/watch_test.py @@ -135,7 +135,7 @@ 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) @@ -143,6 +143,16 @@ def test_unmarshal_with_no_return_type(self): 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.