Exemplo n.º 1
0
    def test_subscribe_all_logged_agents(self, get_extension_from_agent_id,
                                         get_logged_agent_ids):
        agent_id_1 = 13
        agent_id_2 = 72
        status_1 = EndpointStatus.talking
        status_2 = EndpointStatus.available
        agent_extension_1 = Extension('3543', 'my_context', is_internal=True)
        agent_extension_2 = Extension('6353', 'my_context', is_internal=True)
        calls_1 = [Mock(Call)]
        calls_2 = [Mock(Call), Mock(Call)]
        event_1 = EndpointEvent(agent_extension_1, status_1, calls_1)
        event_2 = EndpointEvent(agent_extension_2, status_2, calls_2)
        get_logged_agent_ids.return_value = [agent_id_1, agent_id_2]
        self.call_storage.get_status_for_extension.side_effect = [
            status_1, status_2
        ]
        self.call_storage.find_all_calls_for_extension.side_effect = [
            calls_1, calls_2
        ]
        get_extension_from_agent_id.side_effect = [
            (agent_extension_1.number, agent_extension_1.context),
            (agent_extension_2.number, agent_extension_2.context)
        ]

        self.adapter.subscribe_all_logged_agents()

        self.assertEquals(
            self.endpoint_notifier.subscribe_to_status_changes.call_count, 2)
        self.endpoint_notifier.subscribe_to_status_changes.assert_any_call(
            agent_extension_1, self.adapter.handle_endpoint_event)
        self.endpoint_notifier.subscribe_to_status_changes.assert_any_call(
            agent_extension_2, self.adapter.handle_endpoint_event)
        self.assertEquals(self.router.route.call_count, 2)
        self.router.route.assert_any_call(agent_id_1, event_1)
        self.router.route.assert_any_call(agent_id_2, event_2)
Exemplo n.º 2
0
    def test_same_extension_in_different_context(self):
        first_extension = Extension(number='1234',
                                    context='my_context',
                                    is_internal=True)
        second_extension = Extension(number='1234',
                                     context='other_context',
                                     is_internal=True)

        first_extension_calls = [
            self._create_call(sentinel.uid1, source_exten=first_extension)
        ]
        second_extension_calls = [
            self._create_call(sentinel.uid2, source_exten=second_extension)
        ]
        first_expected_event = EndpointEvent(first_extension, RINGING,
                                             first_extension_calls)
        second_expected_event = EndpointEvent(second_extension, RINGING,
                                              second_extension_calls)

        self.storage.update_endpoint_status(first_extension, RINGING)
        self.storage.update_endpoint_status(second_extension, RINGING)

        assert_that(
            self.endpoint_notifier.notify.call_args_list,
            contains_inanyorder(call(first_expected_event),
                                call(second_expected_event)))
Exemplo n.º 3
0
 def _new_subscription(self, extension, agent_id):
     self._agent_extensions[agent_id] = extension
     self._endpoint_notifier.subscribe_to_status_changes(extension, self.handle_endpoint_event)
     endpoint_status = self._call_storage.get_status_for_extension(extension)
     calls = self._call_storage.find_all_calls_for_extension(extension)
     event = EndpointEvent(extension, endpoint_status, calls)
     self._status_router.route(agent_id, event)
Exemplo n.º 4
0
    def test_route_device_not_in_use(self):
        status = EndpointStatus.available
        calls = []
        event = EndpointEvent(EXTENSION, status, calls)

        self.router.route(AGENT_ID, event)

        self.status_manager.device_not_in_use.assert_called_once_with(AGENT_ID)
Exemplo n.º 5
0
    def test_handle_endpoint_event(self, get_agent_id_from_extension):
        status = EndpointStatus.talking
        calls = [Mock(Call)]
        event = EndpointEvent(EXTENSION, status, calls)
        get_agent_id_from_extension.return_value = AGENT_ID

        self.adapter.handle_endpoint_event(event)

        get_agent_id_from_extension.assert_called_once_with(NUMBER, CONTEXT)
        self.router.route.assert_called_once_with(AGENT_ID, event)
Exemplo n.º 6
0
    def test_route_device_in_use_no_calls(self):
        status = EndpointStatus.talking
        calls = []
        event = EndpointEvent(EXTENSION, status, calls)
        expected_direction = CallDirection.outgoing
        expected_is_internal = True

        self.router.route(AGENT_ID, event)

        self.status_manager.device_in_use.assert_called_once_with(
            AGENT_ID, expected_direction, expected_is_internal)
Exemplo n.º 7
0
    def test_handle_endpoint_event_with_no_agent(self,
                                                 get_agent_id_from_extension):
        status = EndpointStatus.talking

        get_agent_id_from_extension.side_effect = LookupError()

        calls = [Mock(Call)]
        event = EndpointEvent(EXTENSION, status, calls)
        self._subscribe_to_event_for_agent(AGENT_ID, EXTENSION)

        self.adapter.handle_endpoint_event(event)

        self.assertEquals(self.router.route.call_count, 0)
        self.endpoint_notifier.unsubscribe_from_status_changes.assert_called_once_with(
            EXTENSION, self.adapter.handle_endpoint_event)
Exemplo n.º 8
0
    def test_subscribe_to_agent_events(self, get_extension_from_agent_id):
        status = EndpointStatus.talking
        calls = [Mock(Call)]
        extension = Extension(NUMBER, CONTEXT, is_internal=True)

        get_extension_from_agent_id.return_value = (NUMBER, CONTEXT)
        self.call_storage.get_status_for_extension.return_value = status
        self.call_storage.find_all_calls_for_extension.return_value = calls
        expected_event = EndpointEvent(extension, status, calls)

        self.adapter.subscribe_to_agent_events(AGENT_ID)

        get_extension_from_agent_id.assert_called_once_with(AGENT_ID)
        self.endpoint_notifier.subscribe_to_status_changes.assert_called_once_with(
            extension, self.adapter.handle_endpoint_event)
        self.router.route.assert_called_once_with(AGENT_ID, expected_event)
Exemplo n.º 9
0
    def test_subscribe_all_logged_agents_with_one_agent_then_unsubscribe(self, get_extension_from_agent_id, get_logged_agent_ids):
        status = EndpointStatus.talking
        calls = [Mock(Call)]
        agent_extension = Extension('3543', 'my_context', is_internal=True)
        get_logged_agent_ids.return_value = [AGENT_ID]
        self.call_storage.get_status_for_extension.return_value = status
        self.call_storage.find_all_calls_for_extension.return_value = calls
        event = EndpointEvent(agent_extension, status, calls)
        get_extension_from_agent_id.return_value = (agent_extension.number, agent_extension.context)

        self.adapter.subscribe_all_logged_agents()
        self.adapter.unsubscribe_from_agent_events(AGENT_ID)

        self.endpoint_notifier.subscribe_to_status_changes.assert_called_once_with(agent_extension, self.adapter.handle_endpoint_event)
        self.endpoint_notifier.unsubscribe_from_status_changes.assert_called_once_with(agent_extension, self.adapter.handle_endpoint_event)
        self.router.route.assert_called_once_with(AGENT_ID, event)
Exemplo n.º 10
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)
Exemplo n.º 11
0
 def setUp(self):
     super(TestEndpointStatus, self).setUp()
     self.calls = [self._create_call(source_exten=EXTENSION)]
     self.ringing_event = EndpointEvent(EXTENSION, RINGING, self.calls)
     self.available_event = EndpointEvent(EXTENSION, AVAILABLE, self.calls)
Exemplo n.º 12
0
 def _notify_endpoint(self, extension, status):
     calls = self.find_all_calls_for_extension(extension)
     event = EndpointEvent(extension, status, calls)
     self._endpoint_notifier.notify(event)