コード例 #1
0
    def test_handle_new_channel(self, get_extension_from_channel):
        get_extension_from_channel.return_value = sentinel.source_exten
        event = self._mk_new_channel_event()

        self.call_receiver.handle_new_channel(event)

        self.call_storage.new_call.assert_called_once_with(
            UNIQUEID, '', _Channel(sentinel.source_exten, sentinel.channel),
            _Channel(Extension('', '', True), ''))
コード例 #2
0
ファイル: test_manager.py プロジェクト: alexis-via/xivo-ctid
    def test_when_hangup_then_hangup_destination(self):
        call = Call(
            _Channel(sentinel.source_exten, sentinel.source_channel),
            _Channel(sentinel.destination_exten, sentinel.destination_channel),
        )

        self.manager.hangup(call)

        self._ami.hangup.assert_called_once_with(sentinel.source_channel)
コード例 #3
0
ファイル: test_manager.py プロジェクト: gorocacher/xivo-ctid
    def test_when_hangup_then_hangup_destination(self):
        call = Call(
            _Channel(sentinel.source_exten, sentinel.source_channel),
            _Channel(sentinel.destination_exten, sentinel.destination_channel),
        )

        self.manager.hangup(call)

        self._ami.hangup.assert_called_once_with(sentinel.source_channel)
コード例 #4
0
    def _internal_helper(self, source_internal, destination_internal,
                         expected):
        source = _Channel(Mock(Call, is_internal=source_internal),
                          sentinel.channel_name)
        destination = _Channel(Mock(Call, is_internal=destination_internal),
                               sentinel.channel_name)

        call = Call(source, destination)

        assert_that(call.is_internal, equal_to(expected))
コード例 #5
0
ファイル: test_receiver.py プロジェクト: gorocacher/xivo-ctid
    def test_handle_new_channel(self, get_extension_from_channel):
        get_extension_from_channel.return_value = sentinel.source_exten
        event = self._mk_new_channel_event()

        self.call_receiver.handle_new_channel(event)

        self.call_storage.new_call.assert_called_once_with(
            UNIQUEID,
            '',
            _Channel(sentinel.source_exten, sentinel.channel),
            _Channel(Extension('', '', True), '')
        )
コード例 #6
0
    def test_route_device_in_use_outgoing_external(self):
        is_internal = False
        extension = Extension(number=NUMBER, context=CONTEXT, is_internal=is_internal)
        expected_is_internal = is_internal
        expected_direction = CallDirection.outgoing
        status = EndpointStatus.talking
        source_channel = _Channel(extension, sentinel.source_channel)
        destination_channel = _Channel(Mock(Extension), sentinel.destination_channel)
        calls = [Call(source_channel, destination_channel)]
        event = EndpointEvent(extension, status, calls)

        self.router.route(AGENT_ID, event)

        self.status_manager.device_in_use.assert_called_once_with(AGENT_ID, expected_direction, expected_is_internal)
コード例 #7
0
ファイル: test_storage.py プロジェクト: gorocacher/xivo-ctid
    def _create_call(self, uniqueid=None,
                     destuniqueid=None,
                     source_exten=Mock(Extension),
                     destination_exten=Mock(Extension), source_channel=sentinel.source_channel,
                     destination_channel=sentinel.destination_channel):
        source = _Channel(source_exten, source_channel)
        destination = _Channel(destination_exten, destination_channel)

        self.storage.new_call(uniqueid, destuniqueid, source, destination)

        self.call_notifier.reset_mock()
        self.endpoint_notifier.reset_mock()

        return Call(source, destination)
コード例 #8
0
ファイル: receiver.py プロジェクト: alexis-via/xivo-ctid
    def handle_new_channel(self, event):
        try:
            channel = event['Channel']
            unique_id = event['Uniqueid']
            source_exten = helper.get_extension_from_channel(channel)
        except (InvalidChannelError, KeyError):
            logger.debug('ignoring %s', event)
            return

        self._call_storage.new_call(
            unique_id,
            '',
            _Channel(source_exten, channel),
            _Channel(Extension('', '', True), ''),
        )
コード例 #9
0
ファイル: receiver.py プロジェクト: alexis-via/xivo-ctid
 def _add_channel(self, channel_source, channel_destination, uniqueid,
                  destination_uniqueid):
     try:
         extension_source = helper.get_extension_from_channel(
             channel_source)
         extension_destination = helper.get_extension_from_channel(
             channel_destination)
     except (InvalidChannelError) as e:
         logger.error(e)
     else:
         self._call_storage.new_call(
             uniqueid,
             destination_uniqueid,
             _Channel(extension_source, channel_source),
             _Channel(extension_destination, channel_destination),
         )
コード例 #10
0
 def test_equality(self):
     assert_that(
         _Channel(sentinel.exten, sentinel.channel),
         all_of(
             equal_to(_Channel(sentinel.exten, sentinel.channel)),
             is_not(
                 equal_to(_Channel(sentinel.other_exten,
                                   sentinel.channel))),
             is_not(
                 equal_to(_Channel(sentinel.exten,
                                   sentinel.other_channel))),
             is_not(
                 equal_to(
                     _Channel(sentinel.other_exten,
                              sentinel.other_channel))),
         ))
コード例 #11
0
ファイル: test_storage.py プロジェクト: alexis-via/xivo-ctid
    def _create_call(self,
                     uniqueid=None,
                     destuniqueid=None,
                     source_exten=Mock(Extension),
                     destination_exten=Mock(Extension),
                     source_channel=sentinel.source_channel,
                     destination_channel=sentinel.destination_channel):
        source = _Channel(source_exten, source_channel)
        destination = _Channel(destination_exten, destination_channel)

        self.storage.new_call(uniqueid, destuniqueid, source, destination)

        self.call_notifier.reset_mock()
        self.endpoint_notifier.reset_mock()

        return Call(source, destination)
コード例 #12
0
ファイル: test_receiver.py プロジェクト: alexis-via/xivo-ctid
    def test_handle_dial_begin(self, get_extension_from_channel):
        ami_event = self._mk_dial_begin_event()
        extens = {
            sentinel.channel_source: sentinel.source,
            sentinel.channel_destination: sentinel.destination,
        }
        get_extension_from_channel.side_effect = lambda channel: extens[channel]

        self.call_receiver.handle_dial(ami_event)

        self.call_storage.new_call.assert_called_once_with(
            UNIQUEID,
            DEST_UNIQUEID,
            _Channel(sentinel.source, sentinel.channel_source),
            _Channel(sentinel.destination, sentinel.channel_destination),
        )
コード例 #13
0
    def test_channel_simple_attributes(self):
        channel = _Channel(sentinel.exten, sentinel.channel_name)

        assert_that(
            channel,
            all_of(
                has_property('extension', sentinel.exten),
                has_property('_channel', sentinel.channel_name),
            ))
コード例 #14
0
    def test_route_device_in_use_outgoing_external(self):
        is_internal = False
        extension = Extension(number=NUMBER,
                              context=CONTEXT,
                              is_internal=is_internal)
        expected_is_internal = is_internal
        expected_direction = CallDirection.outgoing
        status = EndpointStatus.talking
        source_channel = _Channel(extension, sentinel.source_channel)
        destination_channel = _Channel(Mock(Extension),
                                       sentinel.destination_channel)
        calls = [Call(source_channel, destination_channel)]
        event = EndpointEvent(extension, status, calls)

        self.router.route(AGENT_ID, event)

        self.status_manager.device_in_use.assert_called_once_with(
            AGENT_ID, expected_direction, expected_is_internal)
コード例 #15
0
ファイル: test_receiver.py プロジェクト: alexis-via/xivo-ctid
    def test_that_bridge_add_a_new_call(self, get_extension_from_channel):
        source_channel = 'SCCP/1002'
        destination_channel = 'SIP/abc'
        exten1 = Mock(Extension)
        exten2 = Mock(Extension)
        channel1 = _Channel(exten1, source_channel)
        channel2 = _Channel(exten2, destination_channel)
        get_extension_from_channel.side_effect = (
            lambda c: exten1 if c == source_channel else exten2)

        ami_event = self._mk_bridge_event(
            destination_channel=destination_channel,
            source_channel=source_channel,
        )

        self.call_receiver.handle_bridge(ami_event)

        self.call_storage.new_call.assert_called_once_with(
            UNIQUEID, DEST_UNIQUEID, channel1, channel2)
コード例 #16
0
ファイル: test_storage.py プロジェクト: alexis-via/xivo-ctid
    def test_when_channel_1_is_local(self):
        self.storage._calls = {
            u'1395685236.26':
            Call(
                _Channel(Extension('1009', 'default', True),
                         'SIP/1uzh6d-0000000e'),
                _Channel(Extension('', '', True),
                         'Local/102@default-00000006;1'),
            ),
            u'1395685237.28':
            Call(
                _Channel(Extension('', '', True),
                         'Local/102@default-00000006;2'),
                _Channel(Extension('1002', 'default', True),
                         'SIP/8o5zja-0000000f'),
            ),
        }

        self.storage.merge_local_channels('Local/102@default-00000006;')

        expected = {
            u'1395685237.28':
            Call(
                _Channel(Extension('1009', 'default', True),
                         'SIP/1uzh6d-0000000e'),
                _Channel(Extension('1002', 'default', True),
                         'SIP/8o5zja-0000000f'),
            ),
        }

        assert_that(self.storage._calls, equal_to(expected))
コード例 #17
0
ファイル: test_storage.py プロジェクト: gorocacher/xivo-ctid
    def test_when_channel_1_is_local(self):
        self.storage._calls = {
            u'1395685236.26': Call(
                _Channel(Extension('1009', 'default', True), 'SIP/1uzh6d-0000000e'),
                _Channel(Extension('', '', True), 'Local/102@default-00000006;1'),
            ),
            u'1395685237.28': Call(
                _Channel(Extension('', '', True), 'Local/102@default-00000006;2'),
                _Channel(Extension('1002', 'default', True), 'SIP/8o5zja-0000000f'),
            ),
        }

        self.storage.merge_local_channels('Local/102@default-00000006;')

        expected = {
            u'1395685237.28': Call(
                _Channel(Extension('1009', 'default', True), 'SIP/1uzh6d-0000000e'),
                _Channel(Extension('1002', 'default', True), 'SIP/8o5zja-0000000f'),
            ),
        }

        assert_that(self.storage._calls, equal_to(expected))
コード例 #18
0
ファイル: test_storage.py プロジェクト: alexis-via/xivo-ctid
from mock import sentinel, call
from xivo.asterisk.extension import Extension
from xivo_cti.model.endpoint_event import EndpointEvent
from xivo_cti.model.endpoint_status import EndpointStatus
from xivo_cti.model.call_event import CallEvent
from xivo_cti.model.call_status import CallStatus
from xivo_cti.services.call.call_notifier import CallNotifier
from xivo_cti.services.call.endpoint_notifier import EndpointNotifier
from xivo_cti.services.call.storage import Call
from xivo_cti.services.call.call import _Channel
from xivo_cti.services.call.storage import CallStorage

NUMBER = '1234'
CONTEXT = 'ze_context'
EXTENSION = Extension(NUMBER, CONTEXT, is_internal=True)
SOURCE = _Channel(Extension('2398', 'ze_context', is_internal=True),
                  sentinel.source_channel)
DESTINATION = _Channel(Extension('3297', 'ze_context', is_internal=True),
                       sentinel.destination)
UNIQUEID = '8976549874.84'
DEST_UNIQUEID = '6666549874.84'

AVAILABLE = EndpointStatus.available
RINGING = EndpointStatus.ringing


class _BaseTestCase(unittest.TestCase):
    def setUp(self):
        self.endpoint_notifier = Mock(EndpointNotifier)
        self.call_notifier = Mock(CallNotifier)
        self.storage = CallStorage(self.endpoint_notifier, self.call_notifier)
コード例 #19
0
 def test_repr(self):
     e = Extension('1001', 'default', True)
     assert_that(repr(_Channel(e, 'mychannel')),
                 equal_to('<_Channel 1001@default>'))
コード例 #20
0
ファイル: test_storage.py プロジェクト: gorocacher/xivo-ctid
from mock import sentinel, call
from xivo.asterisk.extension import Extension
from xivo_cti.model.endpoint_event import EndpointEvent
from xivo_cti.model.endpoint_status import EndpointStatus
from xivo_cti.model.call_event import CallEvent
from xivo_cti.model.call_status import CallStatus
from xivo_cti.services.call.call_notifier import CallNotifier
from xivo_cti.services.call.endpoint_notifier import EndpointNotifier
from xivo_cti.services.call.storage import Call
from xivo_cti.services.call.call import _Channel
from xivo_cti.services.call.storage import CallStorage

NUMBER = '1234'
CONTEXT = 'ze_context'
EXTENSION = Extension(NUMBER, CONTEXT, is_internal=True)
SOURCE = _Channel(Extension('2398', 'ze_context', is_internal=True), sentinel.source_channel)
DESTINATION = _Channel(Extension('3297', 'ze_context', is_internal=True), sentinel.destination)
UNIQUEID = '8976549874.84'
DEST_UNIQUEID = '6666549874.84'

AVAILABLE = EndpointStatus.available
RINGING = EndpointStatus.ringing


class _BaseTestCase(unittest.TestCase):

    def setUp(self):
        self.endpoint_notifier = Mock(EndpointNotifier)
        self.call_notifier = Mock(CallNotifier)
        self.storage = CallStorage(self.endpoint_notifier, self.call_notifier)