Skip to content

Commit

Permalink
Optimize getdict Message method always return dict
Browse files Browse the repository at this point in the history
  • Loading branch information
romkazor committed Mar 15, 2024
1 parent c9008f4 commit 00df647
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions panoramisk/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ def getdict(self, key):
sip:[email protected]:4242
"""
values = self.get(key, None)
if not isinstance(values, list):
raise TypeError("{0} must be a list. got {1}".format(key, values))
result = utils.CaseInsensitiveDict()
if not isinstance(values, list):
result[key] = values
return result
for item in values:
k, v = item.split('=', 1)
result[k] = v
Expand Down
22 changes: 22 additions & 0 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,25 @@ def test_content(message):
--- blah ---
''')
assert m.content == '--- blah ---'


@pytest.mark.parametrize('msg', [
Message(
{
'Response': 'Success',
'ChanVariable': ['FROM_DID=', 'SIPURI=sip:[email protected]:4242'],
}
),
Message(
{
'Response': 'Success',
'ChanVariable': 'var',
}
)
]
)
def test_getdict(msg):
assert isinstance(msg.getdict('chanvariable'), utils.CaseInsensitiveDict)
for k, v in msg.getdict('chanvariable').items():
assert isinstance(k, str)
assert isinstance(v, str)

0 comments on commit 00df647

Please sign in to comment.