Exemple #1
0
    def new_call(self, uniqueid, destination_uniqueid, source, destination):
        self.end_call(uniqueid)
        self.end_call(destination_uniqueid)

        self._calls[uniqueid] = Call(source, destination)
        event = CallEvent(uniqueid=uniqueid,
                          source=source.extension,
                          destination=destination.extension,
                          status=CallStatus.ringing)
        self._call_notifier.notify(event)
Exemple #2
0
    def test_new_call_calls_end_call_and_notify_with_the_fresh_info(self):
        call_event = CallEvent(sentinel.uniqueid, SOURCE.extension,
                               DESTINATION.extension, CallStatus.ringing)
        self.storage.end_call = Mock()

        self.storage.new_call(sentinel.uniqueid, sentinel.dest_uniqueid,
                              SOURCE, DESTINATION)

        self.storage.end_call.assert_any_call(sentinel.uniqueid)
        self.storage.end_call.assert_any_call(sentinel.dest_uniqueid)
        assert_that(self.storage.end_call.call_count, equal_to(2))
        self.call_notifier.notify.assert_called_once_with(call_event)
Exemple #3
0
    def test_end_call_started_once_ended_twice(self):
        expected_event = CallEvent(UNIQUEID, self.source_exten,
                                   self.destination_exten, CallStatus.hangup)
        self._create_call(UNIQUEID,
                          source_exten=self.source_exten,
                          destination_exten=self.destination_exten)

        self.storage.end_call(UNIQUEID)
        self.storage.end_call(UNIQUEID)

        assert_that(self.call_notifier.notify.call_args_list,
                    contains(call(expected_event)))
Exemple #4
0
    def end_call(self, uniqueid):
        if uniqueid not in self._calls:
            return

        source_channel = self._calls[uniqueid].source
        destination_channel = self._calls[uniqueid].destination
        event = CallEvent(uniqueid=uniqueid,
                          source=source_channel.extension,
                          destination=destination_channel.extension,
                          status=CallStatus.hangup)
        self._call_notifier.notify(event)
        self._calls.pop(uniqueid)
    def test_notify(self):
        uniqueid = '2938749837.34'
        source = Mock(number=NUMBER, context=CONTEXT)
        destination = Mock(number=NUMBER, context=CONTEXT)
        status = CallStatus.ringing
        event = CallEvent(uniqueid, source, destination, status)

        self.notifier.notify(event)

        self.assertEquals(self.pubsub.publish.call_count, 2)
        self.pubsub.publish.assert_any_call(('calls_outgoing', source), event)
        self.pubsub.publish.assert_any_call(('calls_incoming', destination),
                                            event)