8000 Add tests to object serialization · codegician/twilio-python@9c15ca2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c15ca2

Browse files
committed
Add tests to object serialization
1 parent d87a690 commit 9c15ca2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

tests/unit/base/test_serialize.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,18 @@ def test_list(self):
107107
]
108108
actual = serialize.prefixed_collapsible_map(value, 'Prefix')
109109
self.assertEqual({}, actual)
110+
111+
112+
class ObjectTestCase(unittest.TestCase):
113+
def test_object(self):
114+
actual = serialize.object({'twilio': 'rocks'})
115+
self.assertEqual('{"twilio": "rocks"}', actual)
116+
117+
def test_list(self):
118+
actual = serialize.object(['twilio', 'rocks'])
119+
self.assertEqual('["twilio", "rocks"]', actual)
120+
121+
def test_does_not_change_other_types(self):
122+
actual = serialize.object('{"attribute":"value"}')
123+
self.assertEqual('{"attribute":"value"}', actual)
124+

twilio/base/serialize.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import json
23

34
from twilio.base import values
45

@@ -54,7 +55,7 @@ def flatten_dict(d, result={}, prv_keys=[]):
5455
return {}
5556

5657

57-
def json(obj):
58+
def object(obj):
5859
"""
5960
Return a jsonified string represenation of obj if obj is jsonifiable else
6061
return obj untouched

0 commit comments

Comments
 (0)
0