[fix] Handle cases when there no app start on a comm

parent c8f203ad
......@@ -26,6 +26,7 @@ from xivo_dao.alchemy import dbconnection
from xivo_dao.alchemy.cel import CEL
from xivo_dao.helpers.cel_channel import CELChannel
from xivo_dao.helpers.cel_exception import CELException
from sqlalchemy import desc
logger = logging.getLogger(__name__)
......@@ -37,13 +38,15 @@ class CELDAO(object):
def caller_id_by_unique_id(self, unique_id):
cel_events = (self._session.query(CEL.cid_name, CEL.cid_num)
.filter(CEL.eventtype == 'APP_START')
.filter(CEL.eventtype.in_(['APP_START', 'CHAN_START']))
.filter(CEL.uniqueid == unique_id)
if not cel_events:
if cel_events is None:
raise CELException('no such CEL event with uniqueid %s' % unique_id)
cid_name, cid_num = cel_events[0]
cid_name, cid_num = cel_events
return '"%s" <%s>' % (cid_name, cid_num)
def channel_by_unique_id(self, unique_id):
......@@ -98,6 +98,14 @@ class TestCELDAO(unittest.TestCase):
self.assertEqual('"name2" <num2>', self._celdao.caller_id_by_unique_id('2'))
def test_caller_id_by_unique_id_when_unique_id_is_present_no_app_start(self):
_new_cel(eventtype='CHAN_START', cid_name='name1', cid_num='num1',
self.assertEqual('"name1" <num1>', self._celdao.caller_id_by_unique_id('1'))
def test_caller_id_by_unique_id_when_unique_id_is_missing(self):
_new_cel(eventtype='CHAN_START', cid_name='name1', cid_num='num1',
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment