Skip to content

Commit

Permalink
Merge pull request #118 from romkazor/master
Browse files Browse the repository at this point in the history
Improvements and tests
  • Loading branch information
gawel authored Mar 15, 2024
2 parents ba90798 + 00df647 commit d0df36b
Show file tree
Hide file tree
Showing 4 changed files with 44 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
10 changes: 10 additions & 0 deletions tests/fixtures/login_md5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Asterisk Call Manager/7.0.3
Action: Challenge
AuthType: MD5
ActionID: action/transaction_uid/1/1

Response: Success
Challenge: 145769581
ActionID: action/transaction_uid/1/1


9 changes: 9 additions & 0 deletions tests/test_manager_with_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ async def test_login_failed(manager):
assert manager.login(manager.authenticated_future) is False


@pytest.mark.asyncio
async def test_login_md5(manager):
manager = manager(username='xx', secret='xx', auth_type='md5', stream='login_md5.yaml')
challenge = await manager.auth_challenge_future
assert len(challenge.challenge) == 9
assert challenge.success is True
assert manager.login(manager.auth_challenge_future) is True


def test_logoff(manager):
manager = manager(stream='logoff.yaml')
future = manager.send_action({'Action': 'logoff'})
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 d0df36b

Please sign in to comment.