-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize getdict Message method always return dict
- Loading branch information
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) |