Skip to content

Commit

Permalink
Add tests of unmarshaling literals to watch.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jiahuif committed Oct 23, 2019
1 parent a2d1024 commit ac4781e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions watch/watch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def test_watch_resource_version_set(self):
'{"type": "ADDED", "object": {"metadata": {"name": "test3",'
'"resourceVersion": "3"}, "spec": {}, "status": {}}}\n'
]

# return nothing on the first call and values on the second
# this emulates a watch from a rv that returns nothing in the first k8s
# watch reset and values later
Expand Down Expand Up @@ -250,6 +251,24 @@ def test_unmarshal_with_custom_object(self):
self.assertEqual("1", event['object']['metadata']['resourceVersion'])
self.assertEqual("1", w.resource_version)

# ref: gh-982
def test_unmarshal_with_object_literal(self):
from json import dumps
w = Watch()
simple_object = {'hello': 'world', 'object': {}}
object_literal = dumps(simple_object)
event = w.unmarshal_event(object_literal, 'str')
self.assertTrue(isinstance(event, str))
self.assertEqual(object_literal, event)

# ref: gh-983
def test_unmarshal_with_int_literal(self):
w = Watch()
int_literal = '1145141919'
event = w.unmarshal_event(int_literal, 'str')
self.assertTrue(isinstance(event, str))
self.assertEqual(int_literal, event)

def test_watch_with_exception(self):
fake_resp = Mock()
fake_resp.close = Mock()
Expand Down

0 comments on commit ac4781e

Please sign in to comment.