8000 Add tests for prefixed_collapsible_map serialization · saroshfarhan/twilio-python@9efecbc · GitHub
[go: up one dir, main page]

Skip to content

Commit 9efecbc

Browse files
committed
Add tests for prefixed_collapsible_map serialization
1 parent e6cf719 commit 9efecbc

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

tests/integration/notifications/v1/service/test_binding.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from tests.integration import IntegrationTestCase
1010
from tests.integration.holodeck import Request
11+
from twilio import serialize
1112
from twilio.exceptions import TwilioException
1213
from twilio.http.response import Response
1314

tests/integration/notifications/v1/test_credential.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from tests.integration import IntegrationTestCase
1010
from tests.integration.holodeck import Request
11+
from twilio import serialize
1112
from twilio.exceptions import TwilioException
1213
from twilio.http.response import Response
1314

tests/unit/rest/test_serialize.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,54 @@ def test_date(self):
5757
def test_str(self):
5858
actual = serialize.iso8601_datetime('2015-01-02T03:04:05Z')
5959
self.assertEqual('2015-01-02T03:04:05Z', actual)
60+
61+
62+
class PrefixedCollapsibleMapTestCase(unittest.TestCase):
63+
64+
def test_unset(self):
65+
value = values.unset
66+
actual = serialize.prefixed_collapsible_map(value, 'Prefix')
67+
self.assertEqual({}, actual)
68+
69+
def test_single_key(self):
70+
value = {
71+
'foo': 'bar'
72+
}
73+
actual = serialize.prefixed_collapsible_map(value, 'Prefix')
74+
self.assertEqual({
75+
'Prefix.foo': 'bar'
76+
}, actual)
77+
78+
def test_nested_key(self):
79+
value = {
80+
'foo': {
81+
'bar': 'baz'
82+
}
83+
}
84+
actual = serialize.prefixed_collapsible_map(value, 'Prefix')
85+
self.assertEqual({
86+
'Prefix.foo.bar': 'baz'
87+
}, actual)
88+
89+
def test_multiple_keys(self):
90+
value = {
91+
'watson': {
92+
'language': 'en',
93+
'alice': 'bob'
94+
},
95+
'foo': 'bar'
96+
}
97+
actual = serialize.prefixed_collapsible_map(value, 'Prefix')
98+
self.assertEqual({
99+
'Prefix.watson.language': 'en',
100+
'Prefix.watson.alice': 'bob',
101+
'Prefix.foo': 'bar'
102+
}, actual)
103+
104+
def test_list(self):
105+
value = [
106+
'foo',
107+
'bar'
108+
]
109+
actual = serialize.prefixed_collapsible_map(value, 'Prefix')
110+
self.assertEqual({}, actual)

twilio/serialize.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def prefixed_collapsible_map(m, prefix):
3535
"""
3636
Return a dict of params corresponding to those in m with the added prefix
3737
"""
38-
3938
if m == values.unset:
4039
return {}
4140

0 commit comments

Comments
 (0)
0