Beispiel #1
0
    def test_wait_for_answer_false(self):
        '''If the wait_for_answer config field is False, then we shouldn't wait
        for a ChannelAnswer event before playing media.'''
        self.worker = yield self.create_worker({'wait_for_answer': False})
        factory = yield self.esl_helper.mk_server()
        factory.add_fixture(
            EslCommand("api originate /sofia/gateway/yogisip"
                       " 100 XML default elcid +1234 60"),
            FixtureApiResponse("+OK uuid-1234"))

        msg = self.tx_helper.make_outbound('foobar',
                                           '12345',
                                           '54321',
                                           session_event='new')

        yield self.tx_helper.dispatch_outbound(msg)

        client = yield self.esl_helper.mk_client(self.worker, 'uuid-1234')

        # We are not sending a ChannelAnswer event, but we expect a sendmsg
        # command to be sent anyway, because wait_for_answer is False

        cmd = yield client.queue.get()
        self.assertEqual(
            cmd,
            EslCommand.from_dict({
                'type': 'sendmsg',
                'name': 'playback',
                'arg': "say:'foobar . '",
            }))

        [ack] = yield self.tx_helper.wait_for_dispatched_events(1)
        self.assertEqual(ack['event_type'], 'ack')
        self.assertEqual(ack['sent_message_id'], msg['message_id'])
Beispiel #2
0
    def test_use_our_generated_uuid_if_in_originate_command(self):
        '''If our generated uuid is in the resulting originate command, we
        should use that uuid instead of the one provided by freeswitch.'''
        self.worker = yield self.create_worker({
            'originate_parameters': {
                'call_url': '{{origination_uuid={uuid}}}sofia/gateway/yogisip',
                'exten': '100',
                'cid_name': 'elcid',
                'cid_num': '+1234',
            },
        })

        def static_id():
            return 'test-uuid-1234'

        self.worker.generate_message_id = static_id

        factory = yield self.esl_helper.mk_server()
        factory.add_fixture(
            EslCommand(
                "api originate {origination_uuid=test-uuid-1234}sofia/gateway/"
                "yogisip 100 XML default elcid +1234 60"),
            FixtureApiResponse("+OK wrong-uuid-1234"))

        uuid = yield self.worker.dial_outbound("+4321")
        self.assertEqual(uuid, 'test-uuid-1234')
Beispiel #3
0
    def test_speech_url_list(self):
        [reg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
        self.tx_helper.clear_dispatched_inbound()
        urls = [
            'http://example.com/speech_url_test1.ogg',
            'http://example.com/speech_url_test2.ogg'
        ]

        msg = yield self.tx_helper.make_dispatch_reply(
            reg,
            'speech url test',
            helper_metadata={'voice': {
                'speech_url': urls,
            }})

        cmd = yield self.client.queue.get()
        urllist = 'file_string://%s' % '!'.join(urls)
        self.assertEqual(
            cmd,
            EslCommand.from_dict({
                'type': 'sendmsg',
                'name': 'playback',
                'arg': urllist,
            }))

        [ack] = yield self.tx_helper.get_dispatched_events()
        self.assertEqual(ack['user_message_id'], msg['message_id'])
        self.assertEqual(ack['sent_message_id'], msg['message_id'])
        self.assertEqual(ack['event_type'], 'ack')
Beispiel #4
0
    def test_client_disconnect_without_answer(self):
        self.worker = yield self.create_worker()
        factory = yield self.esl_helper.mk_server()
        factory.add_fixture(
            EslCommand("api originate /sofia/gateway/yogisip"
                       " 100 XML default elcid +1234 60"),
            FixtureApiResponse("+OK uuid-1234"))

        msg = self.tx_helper.make_outbound('foobar',
                                           '12345',
                                           '54321',
                                           session_event='new')

        client = yield self.esl_helper.mk_client(self.worker, 'uuid-1234')

        with LogCatcher(log_level=logging.WARN) as lc:
            yield self.tx_helper.dispatch_outbound(msg)

        self.assertEqual(lc.messages(), [])

        events = yield self.tx_helper.get_dispatched_events()
        self.assertEqual(events, [])

        client.sendDisconnectEvent()

        [nack] = yield self.tx_helper.wait_for_dispatched_events(1)
        self.assertEqual(nack['event_type'], 'nack')
        self.assertEqual(nack['nack_reason'], 'Unanswered Call')
        self.assertEqual(nack['user_message_id'], msg['message_id'])
Beispiel #5
0
    def test_speech_url_string(self):
        [reg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
        self.tx_helper.clear_dispatched_inbound()

        msg = yield self.tx_helper.make_dispatch_reply(
            reg,
            'speech url test',
            helper_metadata={
                'voice': {
                    'speech_url': 'http://example.com/speech_url_test.ogg'
                }
            })

        cmd = yield self.client.queue.get()
        self.assertEqual(
            cmd,
            EslCommand.from_dict({
                'type':
                'sendmsg',
                'name':
                'playback',
                'arg':
                'http://example.com/speech_url_test.ogg',
            }))

        [ack] = yield self.tx_helper.get_dispatched_events()
        self.assertEqual(ack['user_message_id'], msg['message_id'])
        self.assertEqual(ack['sent_message_id'], msg['message_id'])
Beispiel #6
0
    def test_create_call(self):
        self.worker = yield self.create_worker()
        factory = yield self.esl_helper.mk_server()
        factory.add_fixture(
            EslCommand("api originate /sofia/gateway/yogisip"
                       " 100 XML default elcid +1234 60"),
            FixtureApiResponse("+OK uuid-1234"))

        msg = self.tx_helper.make_outbound('foobar',
                                           '12345',
                                           '54321',
                                           session_event='new')

        with LogCatcher(log_level=logging.WARN) as lc:
            yield self.tx_helper.dispatch_outbound(msg)
        self.assertEqual(lc.messages(), [])

        client = yield self.esl_helper.mk_client(self.worker, 'uuid-1234')
        # We need to wait for the client to be registered on the worker
        r = yield self.wait_for_client_registration(self.worker, 'uuid-1234')
        self.assertTrue(r)

        events = yield self.tx_helper.get_dispatched_events()
        self.assertEqual(events, [])

        client.sendChannelAnswerEvent()
        r = yield self.wait_for_call_answer(self.worker, 'uuid-1234')
        self.assertTrue(r)

        cmd = yield client.queue.get()
        self.assertEqual(
            cmd,
            EslCommand.from_dict({
                'type': 'sendmsg',
                'name': 'playback',
                'arg': "say:'foobar . '",
            }))

        [ack] = yield self.tx_helper.wait_for_dispatched_events(1)
        self.assertEqual(ack['event_type'], 'ack')
        self.assertEqual(ack['sent_message_id'], msg['message_id'])
Beispiel #7
0
    def test_simplemessage(self):
        [reg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
        msg = yield self.tx_helper.make_dispatch_reply(reg, "voice test")

        cmd = yield self.client.queue.get()
        self.assertEqual(
            cmd,
            EslCommand.from_dict({
                'type': 'sendmsg',
                'name': 'playback',
                'arg': "say:'voice test . '",
            }))

        [ack] = yield self.tx_helper.get_dispatched_events()
        self.assertEqual(ack['user_message_id'], msg['message_id'])
        self.assertEqual(ack['sent_message_id'], msg['message_id'])
Beispiel #8
0
    def test_use_freeswitch_uuid_if_not_in_originate_command(self):
        '''If the generated uuid is not in the resulting originate command, we
        should use the uuid from freeswitch instead.import'''
        self.worker = yield self.create_worker()

        def static_id():
            return 'wrong-uuid-1234'

        self.worker.generate_message_id = static_id

        factory = yield self.esl_helper.mk_server()
        factory.add_fixture(
            EslCommand("api originate /sofia/gateway/"
                       "yogisip 100 XML default elcid +1234 60"),
            FixtureApiResponse("+OK correct-uuid-1234"))

        uuid = yield self.worker.dial_outbound("+4321")
        self.assertEqual(uuid, 'correct-uuid-1234')
Beispiel #9
0
 def assert_get_digits_command(self, cmd, msg, **kwargs):
     params = {
         'minimum': 1,
         'maximum': 1,
         'timeout': 3000,
         'terminator': "''",
         'tries': 1,
         'msg': msg,
     }
     params.update(kwargs)
     self.assertEqual(
         cmd,
         EslCommand.from_dict({
             'type':
             'sendmsg',
             'name':
             'play_and_get_digits',
             "arg": ("%(minimum)d %(maximum)d %(tries)d %(timeout)d "
                     "%(terminator)s %(msg)s silence_stream://1") % params,
         }))
Beispiel #10
0
    def test_create_call_outbound_using_msisdn(self):
        """
        If we originate a call using an msisdn, then when sending subsequent
        messages to that call, we should be able to use the msisdn as the to
        address, rather than the call uuid.
        """
        self.worker = yield self.create_worker()
        factory = yield self.esl_helper.mk_server()
        factory.add_fixture(
            EslCommand("api originate /sofia/gateway/yogisip"
                       " 100 XML default elcid +1234 60"),
            FixtureApiResponse("+OK uuid-1234"))

        msg = self.tx_helper.make_outbound('foobar',
                                           '12345',
                                           '54321',
                                           session_event='new')
        yield self.tx_helper.dispatch_outbound(msg)
        # Freeswitch connect
        client = yield self.esl_helper.mk_client(self.worker, 'uuid-1234')
        yield self.wait_for_client_registration(self.worker, 'uuid-1234')
        # Client answers call
        client.sendChannelAnswerEvent()
        yield self.wait_for_call_answer(self.worker, 'uuid-1234')

        [ack] = yield self.tx_helper.wait_for_dispatched_events(1)
        self.assertEqual(ack['event_type'], 'ack')
        self.assertEqual(ack['user_message_id'], msg['message_id'])

        self.tx_helper.clear_dispatched_events()
        msg = self.tx_helper.make_outbound('foobar',
                                           '12345',
                                           '54321',
                                           session_event='close')
        yield self.tx_helper.dispatch_outbound(msg)

        [ack] = yield self.tx_helper.wait_for_dispatched_events(1)
        self.assertEqual(ack['event_type'], 'ack')
        self.assertEqual(ack['user_message_id'], msg['message_id'])
Beispiel #11
0
    def test_create_call_replies_msisdn(self):
        """
        If we originate a call with an outbound msisdn, all inbound replies
        to that call should have the same msisdn as the from address, not
        the uuid of the call session.
        """
        self.worker = yield self.create_worker()
        factory = yield self.esl_helper.mk_server()
        factory.add_fixture(
            EslCommand("api originate /sofia/gateway/yogisip"
                       " 100 XML default elcid +1234 60"),
            FixtureApiResponse("+OK uuid-1234"))

        msg = self.tx_helper.make_outbound('foobar',
                                           '12345',
                                           '54321',
                                           session_event='new')
        yield self.tx_helper.dispatch_outbound(msg)

        # Freeswitch connect
        client = yield self.esl_helper.mk_client(self.worker, 'uuid-1234')
        yield self.wait_for_client_registration(self.worker, 'uuid-1234')
        # Client answers call
        client.sendChannelAnswerEvent()
        yield self.wait_for_call_answer(self.worker, 'uuid-1234')

        # Client types digit
        client.sendDtmfEvent(4)
        [inbound] = yield self.tx_helper.wait_for_dispatched_inbound(1)
        self.assertEqual(inbound['from_addr'], '54321')

        # Client hangs up
        self.tx_helper.clear_dispatched_inbound()
        client.sendChannelHangupCompleteEvent(7)
        [inbound] = yield self.tx_helper.wait_for_dispatched_inbound(1)
        self.assertEqual(inbound['from_addr'], '54321')

        # Make sure that we don't keep the mapping after hangup
        self.assertEqual(len(self.worker._msisdn_mapping), 0)
Beispiel #12
0
    def test_connect_error(self):
        self.worker = yield self.create_worker()
        factory = yield self.esl_helper.mk_server(fail_connect=True,
                                                  uuid=lambda: 'uuid-1234')
        factory.add_fixture(
            EslCommand("api originate /sofia/gateway/yogisip"
                       " 100 XML default elcid +1234 60"),
            FixtureApiResponse("+ERROR Bad horse."))

        msg = self.tx_helper.make_outbound('foobar',
                                           '12345',
                                           '54321',
                                           session_event='new')
        with LogCatcher(message='Could not make call') as lc:
            yield self.tx_helper.dispatch_outbound(msg)
        self.assertEqual(lc.messages(), [
            "Could not make call to client u'54321': +ERROR Bad horse.",
        ])
        [nack] = yield self.tx_helper.get_dispatched_events()
        self.assertEqual(nack['user_message_id'], msg['message_id'])
        self.assertEqual(
            nack['nack_reason'],
            "Could not make call to client u'54321': +ERROR Bad horse.")
Beispiel #13
0
    def test_multidigitcapture(self):
        [reg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
        self.tx_helper.clear_dispatched_inbound()

        yield self.tx_helper.make_dispatch_reply(
            reg, 'voice test', helper_metadata={'voice': {
                'wait_for': '#'
            }})

        cmd = yield self.client.queue.get()
        self.assertEqual(
            cmd,
            EslCommand.from_dict({
                'type': 'sendmsg',
                'name': 'playback',
                'arg': "say:'voice test . '",
            }))

        self.client.sendDtmfEvent('5')
        self.client.sendDtmfEvent('7')
        self.client.sendDtmfEvent('2')
        self.client.sendDtmfEvent('#')
        [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
        self.assertEqual(msg['content'], '572')
Beispiel #14
0
 def assert_and_reply(self, expected, response):
     cmd = yield self.tr.cmds.get()
     expected_cmd = EslCommand.from_dict(expected)
     self.assertEqual(cmd, expected_cmd)
     self.send_command_reply(response)