Пример #1
0
    def given_answered_user_relocate(self):
        user_uuid = SOME_USER_UUID
        relocated_channel_id, initiator_channel_id = self.given_bridged_call_stasis(
            callee_uuid=user_uuid)
        line_id = SOME_LINE_ID
        token = self.given_user_token(user_uuid)
        self.confd.set_users(MockUser(uuid=user_uuid, line_ids=[line_id]))
        self.confd.set_lines(
            MockLine(id=line_id,
                     name='recipient_autoanswer@local',
                     protocol='local',
                     context=SOME_CONTEXT))
        calld = self.make_calld(token)
        destination = 'line'
        location = {'line_id': line_id}
        completions = ['api']
        relocate = calld.relocates.create_from_user(initiator_channel_id,
                                                    destination, location,
                                                    completions)

        def all_talking():
            assert_that(relocate['relocated_call'], self.c.is_talking(),
                        'relocated channel not talking')
            assert_that(relocate['initiator_call'], self.c.is_talking(),
                        'initiator channel not talking')
            assert_that(relocate['recipient_call'], self.c.is_talking(),
                        'recipient channel not talking')

        until.assert_(all_talking, timeout=5)

        return relocate, user_uuid
Пример #2
0
    def given_completed_user_relocate(self):
        user_uuid = SOME_USER_UUID
        relocated_channel_id, initiator_channel_id = self.given_bridged_call_stasis(
            callee_uuid=user_uuid)
        line_id = SOME_LINE_ID
        token = self.given_user_token(user_uuid)
        self.confd.set_users(MockUser(uuid=user_uuid, line_ids=[line_id]))
        self.confd.set_lines(
            MockLine(id=line_id,
                     name='recipient_autoanswer@local',
                     protocol='local',
                     context=SOME_CONTEXT))
        calld = self.make_calld(token)
        destination = 'line'
        location = {'line_id': line_id}
        relocate = calld.relocates.create_from_user(initiator_channel_id,
                                                    destination, location)

        until.assert_(
            self.assert_relocate_is_completed,
            relocate['uuid'],
            relocate['relocated_call'],
            relocate['initiator_call'],
            relocate['recipient_call'],
            timeout=5,
        )

        return relocate, user_uuid
    def test_given_http_user_subscription_to_localhost_when_bus_event_then_callback_not_called(
            self, control_subscription, sentinel_subscription):
        # sentinel should not be triggered
        self.bus.publish(
            trigger_event(),
            routing_key=SOME_ROUTING_KEY,
            headers={
                'name': TRIGGER_EVENT_NAME,
                'user_uuid:{uuid}'.format(uuid=ALICE_USER_UUID): True,
            },
        )
        # trigger control webhook
        self.bus.publish(
            event(name=ANOTHER_TRIGGER_EVENT_NAME),
            routing_key=SOME_ROUTING_KEY,
            headers={
                'name': ANOTHER_TRIGGER_EVENT_NAME,
                'user_uuid:{uuid}'.format(uuid=ALICE_USER_UUID): True,
            },
        )

        until.assert_(
            self.make_third_party_verify_callback(request={
                'method': 'GET',
                'path': '/test'
            },
                                                  count=1,
                                                  exact=True),
            timeout=10,
            interval=0.5,
        )
        assert_that(self.sentinel.called(), is_(False))
Пример #4
0
    def given_waiting_relocated_user_relocate(self):
        user_uuid = str(uuid.uuid4())
        relocated_channel_id, initiator_channel_id = self.given_bridged_call_not_stasis(
            callee_uuid=user_uuid,
            caller_variables={'WAIT_BEFORE_STASIS': '60'})
        line_id = SOME_LINE_ID
        token = self.given_user_token(user_uuid)
        self.confd.set_users(MockUser(uuid=user_uuid, line_ids=[line_id]))
        self.confd.set_lines(
            MockLine(id=line_id,
                     name='recipient_autoanswer@local',
                     protocol='local',
                     context=SOME_CONTEXT))
        calld = self.make_calld(token)
        destination = 'line'
        location = {'line_id': line_id}
        relocate = calld.relocates.create_from_user(initiator_channel_id,
                                                    destination, location)

        def relocate_waiting_relocated():
            assert_that(relocated_channel_id, self.c.is_talking(),
                        'relocated channel not talking')
            assert_that(initiator_channel_id, self.c.is_hungup(),
                        'initiator channel is still talking')
            assert_that(relocate['recipient_call'], self.c.is_talking(),
                        'recipient channel not talking')

        until.assert_(relocate_waiting_relocated, timeout=5)

        return relocate, user_uuid
Пример #5
0
    def test_register_error_then_no_user_created(self):
        args = {
            'username': '******',
            'lastname': 'Denver',
            'email_address': '*****@*****.**',
            'password': '******',
        }

        self.stop_service('smtp')
        assert_that(
            calling(self.client.users.register).with_args(**args),
            raises(requests.HTTPError),
        )
        self.start_service('smtp')

        def user_registered():
            try:
                user = self.client.users.register(**args)
            except Exception as e:
                self.fail(e)

            assert_that(user, has_entries(username='******'))
            self.client.users.delete(user['uuid'])

        until.assert_(user_registered, timeout=3.0)
    def test_given_http_subscription_with_content_type_when_bus_event_then_http_callback_with_content_type(
            self, subscription):

        self.bus.publish(
            trigger_event(),
            routing_key=SOME_ROUTING_KEY,
            headers={'name': TRIGGER_EVENT_NAME},
        )

        until.assert_(
            self.make_third_party_verify_callback(
                request={
                    'method':
                    'POST',
                    'path':
                    '/test',
                    'body':
                    'keỳ: vàlue',
                    'headers': [{
                        'name': 'Content-Type',
                        'values': ['text/yaml; charset=utf-8']
                    }],
                }),
            timeout=10,
            interval=0.5,
        )
    def test_given_one_http_subscription_when_restart_rabbitmq_then_callback_still_triggered(
            self, subscription):

        self.restart_service('rabbitmq')
        ConnectedWaitStrategy().wait(self.make_webhookd(MASTER_TOKEN))

        # FIXME(sileht): BusClient should reconnect automatically
        self.bus = self.make_bus()
        until.true(self.bus.is_up,
                   timeout=5,
                   message='rabbitmq did not come back up')

        self.bus.publish(
            trigger_event(),
            routing_key=SOME_ROUTING_KEY,
            headers={'name': TRIGGER_EVENT_NAME},
        )

        until.assert_(
            self.make_third_party_verify_callback(request={
                'method': 'GET',
                'path': '/test'
            }),
            timeout=10,
            interval=0.5,
        )
Пример #8
0
    def _assert_chat_msg_sent_on_bus(self, message):
        def assert_function():
            assert_that(
                self.events.accumulate(),
                has_items(
                    {
                        'name':
                        'chat_message_event',
                        'origin_uuid':
                        XIVO_UUID,
                        'required_acl':
                        'events.chat.message.{}.{}'.format(
                            XIVO_UUID, message.to),
                        'data': {
                            'alias': message.alias,
                            'to': [XIVO_UUID, message.to],
                            'from': [XIVO_UUID, self.token_user_uuid],
                            'msg': message.content,
                        }
                    },
                    has_entry('name', 'chat_message_received'),
                    has_entry('name', 'chat_message_sent'),
                ))

        until.assert_(assert_function, tries=5)
    def test_given_one_http_subscription_when_update_events_then_callback_triggered_on_the_right_event(
            self, subscription):
        webhookd = self.make_webhookd(MASTER_TOKEN)
        old_trigger_name = TRIGGER_EVENT_NAME

        subscription['events'] = [ANOTHER_TRIGGER_EVENT_NAME]
        webhookd.subscriptions.update(subscription['uuid'], subscription)
        self.ensure_webhookd_consume_uuid(subscription['uuid'])

        self.bus.publish(
            event(name=old_trigger_name),
            routing_key=SOME_ROUTING_KEY,
            headers={'name': old_trigger_name},
        )
        self.bus.publish(
            event(name=ANOTHER_TRIGGER_EVENT_NAME),
            routing_key=SOME_ROUTING_KEY,
            headers={'name': ANOTHER_TRIGGER_EVENT_NAME},
        )

        until.assert_(
            self.make_third_party_verify_callback(request={
                'method': 'GET',
                'path': '/test'
            },
                                                  count=1,
                                                  exact=True),
            timeout=10,
            interval=0.5,
        )
    def test_given_two_http_subscriptions_when_update_config_then_callback_triggered_with_new_config(
            self, subscription, _):
        webhookd = self.make_webhookd(MASTER_TOKEN)

        subscription['config']['url'] = 'http://third-party-http:1080/new-url'
        webhookd.subscriptions.update(subscription['uuid'], subscription)
        self.ensure_webhookd_consume_uuid(subscription['uuid'])

        self.bus.publish(
            trigger_event(),
            routing_key=SOME_ROUTING_KEY,
            headers={'name': TRIGGER_EVENT_NAME},
        )

        until.assert_(
            self.make_third_party_verify_callback(request={
                'method': 'GET',
                'path': '/new-url'
            }),
            timeout=10,
            interval=0.5,
        )
        until.assert_(
            self.make_third_party_verify_callback(request={
                'method': 'GET',
                'path': '/test'
            },
                                                  count=1,
                                                  exact=True),
            timeout=10,
            interval=0.5,
        )
    def test_given_one_http_subscription_when_bus_event_then_one_http_callback(
            self, subscription):

        self.bus.publish(
            trigger_event(),
            routing_key=SOME_ROUTING_KEY,
            headers={'name': TRIGGER_EVENT_NAME},
        )

        until.assert_(
            self.make_third_party_verify_callback(request={
                'method': 'GET',
                'path': '/test'
            },
                                                  count=1,
                                                  exact=True),
            timeout=10,
            interval=0.5,
        )

        webhookd = self.make_webhookd(MASTER_TOKEN)
        logs = webhookd.subscriptions.get_logs(subscription["uuid"])
        assert_that(logs['total'], equal_to(1))
        assert_that(logs['items'],
                    contains(has_entries(status="success", attempts=1)))
Пример #12
0
    def setUp(self):
        super().setUp()
        self.tenant_uuid = SUB_TENANT
        self.tenant_name = 'mytenant'
        bus_port = self.service_port(5672, 'rabbitmq')
        bus = BusClient.from_connection_fields(host='localhost', port=bus_port)
        until.true(bus.is_up, timeout=5)

        bus_url = 'amqp://{username}:{password}@{host}:{port}//'.format(
            username='******',
            password='******',
            host='localhost',
            port=bus_port)
        connection = kombu.Connection(bus_url)
        connection.connect()
        marshaler = Marshaler('the-xivo-uuid')
        exchange = kombu.Exchange('xivo', type='topic')
        producer = kombu.Producer(connection,
                                  exchange=exchange,
                                  auto_declare=True)
        self.publisher = Publisher(producer, marshaler)
        self.mock_auth_client = MockAuthClient('localhost',
                                               self.service_port(9497, 'auth'))

        def wait_for_dird_bus_connection():
            response = self.client.status.get()
            assert_that(response, has_entries(bus_consumer={'status': 'ok'}))

        until.assert_(wait_for_dird_bus_connection, timeout=6)
Пример #13
0
    def test_refresh_token_created_event(self, user):
        routing_key = 'auth.users.{uuid}.tokens.*.created'.format(**user)
        msg_accumulator = self.new_message_accumulator(routing_key)

        client_id = 'mytestapp'
        self._post_token(
            'foo',
            'bar',
            session_type='Mobile',
            access_type='offline',
            client_id=client_id,
        )

        def bus_received_msg():
            assert_that(
                msg_accumulator.accumulate(),
                contains(
                    has_entries(
                        data={
                            'client_id': client_id,
                            'user_uuid': user['uuid'],
                            'tenant_uuid': user['tenant_uuid'],
                            'mobile': True,
                        })),
            )

        until.assert_(bus_received_msg, tries=10, interval=0.25)
Пример #14
0
    def test_given_stasis_channels_a_b_when_b_relocate_to_mobile_and_answer_then_a_talks_with_mobile(
            self):
        user_uuid = SOME_USER_UUID
        line_id = 12
        self.confd.set_users(
            MockUser(uuid=user_uuid,
                     line_ids=[line_id],
                     mobile='recipient_autoanswer'))
        self.confd.set_lines(MockLine(id=line_id, context='local'))
        token = self.given_user_token(user_uuid)
        relocated_channel_id, initiator_channel_id = self.given_bridged_call_stasis(
            callee_uuid=user_uuid)
        calld = self.make_calld(token)

        relocate = calld.relocates.create_from_user(initiator_channel_id,
                                                    'mobile')

        until.assert_(
            self.assert_relocate_is_completed,
            relocate['uuid'],
            relocated_channel_id,
            initiator_channel_id,
            relocate['recipient_call'],
            timeout=5,
        )
    def test_given_one_http_subscription_with_no_body_when_bus_event_then_http_callback_with_default_body(
            self, subscription):

        self.bus.publish(
            trigger_event(data={'keý': 'vàlue'}),
            routing_key=SOME_ROUTING_KEY,
            headers={'name': TRIGGER_EVENT_NAME},
        )

        until.assert_(
            self.make_third_party_verify_callback(
                request={
                    'method':
                    'GET',
                    'path':
                    '/test',
                    'body':
                    '{"ke\\u00fd": "v\\u00e0lue"}',
                    'headers': [{
                        'name': 'Content-Type',
                        'values': ['application/json; charset=utf-8'],
                    }],
                }),
            timeout=10,
            interval=0.5,
        )
Пример #16
0
    def test_given_mobile_call_when_relocate_to_line_then_relocate_completed(
            self):
        mobile_channel, other_channel, mobile_user_uuid = self.given_mobile_call(
        )
        token = self.given_user_token(mobile_user_uuid)
        line_id = SOME_LINE_ID
        calld = self.make_calld(token)
        self.confd.set_users(
            MockUser(uuid=mobile_user_uuid, line_ids=[line_id]))
        self.confd.set_lines(
            MockLine(id=line_id,
                     name='recipient_autoanswer@local',
                     protocol='local',
                     context=SOME_CONTEXT))
        destination = 'line'
        location = {'line_id': line_id}

        relocate = calld.relocates.create_from_user(mobile_channel,
                                                    destination, location)

        until.assert_(
            self.assert_relocate_is_completed,
            relocate['uuid'],
            relocate['relocated_call'],
            relocate['initiator_call'],
            relocate['recipient_call'],
            timeout=5,
        )
    def test_given_http_subscription_with_body_template_when_bus_event_then_callback_with_body_templated(
            self, subscription):

        self.bus.publish(
            trigger_event(data={'variable': 'value'}),
            routing_key=SOME_ROUTING_KEY,
            headers={'name': TRIGGER_EVENT_NAME},
        )

        until.assert_(
            self.make_third_party_verify_callback(request={
                'method': 'GET',
                'path': '/test',
                'body': 'trigger value'
            }),
            timeout=10,
            interval=0.5,
        )

        webhookd = self.make_webhookd(MASTER_TOKEN)
        logs = webhookd.subscriptions.get_logs(subscription["uuid"])
        assert_that(logs['total'], equal_to(1))
        assert_that(
            logs['items'],
            contains(
                has_entries(
                    status="success",
                    detail=has_entries(request_body='trigger value'),
                    attempts=1,
                )),
        )
Пример #18
0
    def _assert_chat_msg_sent_on_bus(self):
        def assert_function():
            destination = [
                self.chat_msg.to_xivo_uuid or XIVO_UUID, self.chat_msg.to
            ]
            assert_that(
                self.events.accumulate(),
                has_items(
                    {
                        'name':
                        'chat_message_event',
                        'origin_uuid':
                        XIVO_UUID,
                        'required_acl':
                        'events.chat.message.{}.{}'.format(*destination),
                        'data': {
                            'alias': self.chat_msg.alias,
                            'to': destination,
                            'from': [XIVO_UUID, self.chat_msg.from_],
                            'msg': self.chat_msg.content,
                        }
                    },
                    has_entry('name', 'chat_message_received'),
                    has_entry('name', 'chat_message_sent'),
                ))

        until.assert_(assert_function, tries=5)
Пример #19
0
    def test_create(self, user):
        routing_key = 'auth.users.{}.external.foo.created'.format(user['uuid'])
        msg_accumulator = self.new_message_accumulator(routing_key)

        result = self.client.external.create('foo', user['uuid'],
                                             self.original_data)
        assert_that(result, has_entries(**self.original_data))

        def bus_received_msg():
            assert_that(
                msg_accumulator.accumulate(),
                contains(
                    has_entries(data=dict(user_uuid=user['uuid'],
                                          external_auth_name='foo'))),
            )

        until.assert_(bus_received_msg, tries=10, interval=0.25)

        data = self.client.external.get('foo', user['uuid'])
        assert_that(data, has_entries(**self.original_data))

        base.assert_http_error(404, self.client.external.create, 'notfoo',
                               user['uuid'], self.original_data)
        base.assert_http_error(404, self.client.external.create, 'foo',
                               UNKNOWN_UUID, self.original_data)
Пример #20
0
    def test_given_dialed_from_when_originator_hangs_up_then_user_stops_ringing(self):
        call_id = 'call-id'
        new_call_id = 'new-call-id'
        self.ari.set_channels(MockChannel(id=call_id),
                              MockChannel(id=new_call_id, ))
        self.ari.set_channel_variable({new_call_id: {'XIVO_USERUUID': 'user-uuid'}})
        self.ari.set_global_variables({'XIVO_CHANNELS_{}'.format(call_id): json.dumps({'app': 'my-app',
                                                                                       'app_instance': 'sw1',
                                                                                       'state': 'ringing'})})
        self.confd.set_users(MockUser(uuid='user-uuid'))
        self.confd.set_lines(MockLine(id='line-id', name='line-name', protocol='sip'))
        self.confd.set_user_lines({'user-uuid': [MockUserLine('line-id')]})
        self.ari.set_originates(MockChannel(id=new_call_id))

        self.ctid_ng.connect_user(call_id, 'user-uuid')

        self.stasis.event_hangup(call_id)

        def assert_function():
            assert_that(self.ari.requests(), has_entry('requests', has_items(has_entries({
                'method': 'DELETE',
                'path': '/ari/channels/{call_id}'.format(call_id=new_call_id),
            }))))

        until.assert_(assert_function, tries=5)
Пример #21
0
    def test_given_one_http_subscription_with_no_body_when_bus_event_then_http_callback_with_default_body(
            self, subscription):
        third_party = self.make_third_party()
        bus = self.make_bus()

        bus.publish(trigger_event(data={'keý': 'vàlue'}),
                    routing_key=SOME_ROUTING_KEY,
                    headers={'name': TRIGGER_EVENT_NAME})

        def callback_received():
            try:
                third_party.verify(
                    request={
                        'method':
                        'GET',
                        'path':
                        '/test',
                        'body':
                        '{"ke\\u00fd": "v\\u00e0lue"}',
                        'headers': [{
                            'name': 'Content-Type',
                            'values': ['application/json']
                        }],
                    })
            except Exception:
                raise AssertionError()

        until.assert_(callback_received, tries=10, interval=0.5)
Пример #22
0
    def test_given_two_http_subscription_when_one_deleted_then_one_http_callback(
            self, subscription, subscription_to_remove):
        bus = self.make_bus()
        third_party = self.make_third_party()
        webhookd = self.make_webhookd(VALID_TOKEN)

        webhookd.subscriptions.delete(subscription_to_remove['uuid'])
        time.sleep(1)  # wait for the subscription to be removed
        bus.publish(trigger_event(),
                    routing_key=SOME_ROUTING_KEY,
                    headers={'name': TRIGGER_EVENT_NAME})

        def callback_received_once():
            try:
                third_party.verify(
                    request={
                        'method': 'GET',
                        'path': '/test',
                    },
                    count=1,
                    exact=True,
                )
            except Exception:
                raise AssertionError()

        until.assert_(callback_received_once, tries=10, interval=0.5)
Пример #23
0
    def test_when_channel_resumed_then_bus_event(self):
        call_id = new_call_id()
        self.ari.set_channels(MockChannel(id=call_id))
        self.ari.set_channel_variable({call_id: {'XIVO_ON_HOLD': ''}})
        events = self.bus.accumulator(routing_key='calls.hold.deleted')

        self.bus.send_ami_unhold_event(call_id)

        def assert_function():
            assert_that(
                self.amid.requests()['requests'],
                has_item(
                    has_entries({
                        'method':
                        'POST',
                        'path':
                        '/1.0/action/Setvar',
                        'json':
                        has_entries({
                            'Channel': call_id,
                            'Variable': 'XIVO_ON_HOLD',
                            'Value': ''
                        }),
                    })))
            assert_that(
                events.accumulate(),
                has_item(
                    has_entries({
                        'name': 'call_resumed',
                        'origin_uuid': XIVO_UUID,
                        'data': has_entries({'call_id': call_id})
                    })))

        until.assert_(assert_function, tries=5)
Пример #24
0
    def test_external_oauth2(self, user):
        routing_key = 'auth.users.{}.external.foo.authorized'.format(
            user['uuid'])
        msg_accumulator = self.new_message_accumulator(routing_key)
        token = 'a-token'
        result = self.client.external.create('foo', user['uuid'],
                                             self.original_data)
        time.sleep(1)  # wazo-auth needs some time to connect its websocket
        self.authorize_oauth2('foo', result['state'], token)

        def oauth2_is_done():
            try:
                return self.client.external.get('foo', user['uuid'])
            except requests.HTTPError:
                return False

        data = until.true(oauth2_is_done, timeout=5, interval=0.25)

        assert_that(data, has_entries(access_token=token))

        def bus_received_msg():
            assert_that(
                msg_accumulator.accumulate(),
                contains(
                    has_entries(data=dict(user_uuid=user['uuid'],
                                          external_auth_name='foo'))))

        until.assert_(bus_received_msg, tries=10, interval=0.25)
Пример #25
0
    def test_given_one_http_subscription_when_update_events_then_callback_triggered_on_the_right_event(
            self, subscription):
        bus = self.make_bus()
        third_party = self.make_third_party()
        webhookd = self.make_webhookd(VALID_TOKEN)
        old_trigger_name = TRIGGER_EVENT_NAME

        subscription['events'] = [ANOTHER_TRIGGER_EVENT_NAME]
        webhookd.subscriptions.update(subscription['uuid'], subscription)
        time.sleep(1)  # wait for the subscription to be updated

        bus.publish(event(name=old_trigger_name),
                    routing_key=SOME_ROUTING_KEY,
                    headers={'name': old_trigger_name})
        bus.publish(event(name=ANOTHER_TRIGGER_EVENT_NAME),
                    routing_key=SOME_ROUTING_KEY,
                    headers={'name': ANOTHER_TRIGGER_EVENT_NAME})

        def callback_received():
            try:
                third_party.verify(request={
                    'method': 'GET',
                    'path': '/test',
                },
                                   count=1,
                                   exact=True)
            except Exception:
                raise AssertionError()

        until.assert_(callback_received, tries=10, interval=0.5)
Пример #26
0
    def test_when_channel_created_then_bus_event(self):
        call_id = new_call_id()
        self.ari.set_channels(MockChannel(id=call_id,
                                          connected_line_number=''))
        self.ari.set_channel_variable({
            call_id: {
                'XIVO_BASE_EXTEN': '*10',
                'CHANNEL(channeltype)': 'PJSIP',
                'CHANNEL(pjsip,call-id)': 'a-sip-call-id',
            },
        })
        events = self.bus.accumulator(routing_key='calls.call.created')

        self.bus.send_ami_newchannel_event(call_id)

        def assert_function():
            assert_that(
                events.accumulate(),
                has_item(
                    has_entries({
                        'name':
                        'call_created',
                        'origin_uuid':
                        XIVO_UUID,
                        'data':
                        has_entries({
                            'call_id': call_id,
                            'dialed_extension': '*10',
                            'peer_caller_id_number': '*10',
                            'sip_call_id': 'a-sip-call-id',
                        })
                    })))

        until.assert_(assert_function, tries=5)
Пример #27
0
    def test_when_channel_ended_with_sip_call_id_then_bus_event(self):
        call_id = new_call_id()
        sip_call_id = 'foobar'
        events = self.bus.accumulator(routing_key='calls.call.ended')

        self.bus.send_ami_hangup_event(call_id,
                                       base_exten='*10',
                                       sip_call_id=sip_call_id)

        def assert_function():
            assert_that(
                events.accumulate(),
                has_item(
                    has_entries({
                        'name':
                        'call_ended',
                        'origin_uuid':
                        XIVO_UUID,
                        'data':
                        has_entries({
                            'call_id': call_id,
                            'dialed_extension': '*10',
                            'sip_call_id': sip_call_id,
                        })
                    })))

        until.assert_(assert_function, tries=5)
Пример #28
0
    def test_send_fax_pdf(self):
        calld = self.make_calld()

        with open(os.path.join(ASSET_ROOT, 'fax', 'fax.pdf'),
                  'rb') as fax_file:
            fax_content = fax_file.read()

        fax = calld.faxes.send(fax_content,
                               context='recipient',
                               extension='recipient-fax',
                               caller_id='fax wait')

        assert_that(
            fax,
            has_entries({
                'id': is_not(empty()),
                'context': 'recipient',
                'extension': 'recipient-fax',
                'caller_id': 'fax wait',
            }))

        def one_fax_channel():
            assert_that(self._fax_channels(), has_length(1))

        until.assert_(one_fax_channel, timeout=3)
Пример #29
0
    def test_send_fax_pdf_from_user(self):
        user_uuid = 'some-user-id'
        context = 'user-context'
        token = 'my-user-token'
        self.auth.set_token(
            MockUserToken(token, user_uuid=user_uuid, tenant_uuid='my-tenant'))
        self.confd.set_users(
            MockUser(uuid=user_uuid, line_ids=['some-line-id']))
        self.confd.set_lines(
            MockLine(id='some-line-id',
                     name='line-name',
                     protocol='pjsip',
                     context=context))

        calld = self.make_calld(token)
        with open(os.path.join(ASSET_ROOT, 'fax', 'fax.pdf'),
                  'rb') as fax_file:
            fax_content = fax_file.read()

        try:
            calld.faxes.send_from_user(fax_content,
                                       extension='recipient-fax',
                                       caller_id='fax wait')
        except Exception as e:
            raise AssertionError(
                'Sending fax raised an exception: {}'.format(e))

        def one_fax_channel():
            assert_that(self._fax_channels(), has_length(1))

        until.assert_(one_fax_channel, timeout=3)
Пример #30
0
    def test_given_dialed_from_when_answer_then_the_two_are_talking(self):
        call_id = new_call_id()
        new_call_id_ = new_call_id()
        self.ari.set_channels(MockChannel(id=call_id), MockChannel(id=new_call_id_))
        self.ari.set_global_variables({'XIVO_CHANNELS_{}'.format(call_id): json.dumps({'state': 'ringing',
                                                                                       'app': STASIS_APP_NAME,
                                                                                       'app_instance': STASIS_APP_INSTANCE_NAME})})

        self.stasis.event_answer_connect(from_=call_id, new_call_id=new_call_id_)

        def assert_function():
            assert_that(self.ari.requests(), has_entry('requests', has_items(has_entries({
                'method': 'POST',
                'path': '/ari/channels/{channel_id}/answer'.format(channel_id=call_id),
            }), has_entries({
                'method': 'POST',
                'path': '/ari/channels/{channel_id}/answer'.format(channel_id=new_call_id_),
            }), has_entries({
                'method': 'POST',
                'path': '/ari/bridges/bridge-id/addChannel',
                'query': [['channel', call_id]],
            }), has_entries({
                'method': 'POST',
                'path': '/ari/bridges/bridge-id/addChannel',
                'query': [['channel', new_call_id_]],
            }), has_entries({
                'method': 'POST',
                'path': '/ari/bridges',
                'query': [['type', 'mixing']],
            }))))

        until.assert_(assert_function, tries=5)
Пример #31
0
    def test_given_http_subscription_with_content_type_when_bus_event_then_http_callback_with_content_type(
            self, subscription):
        third_party = self.make_third_party()
        bus = self.make_bus()

        bus.publish(trigger_event(),
                    routing_key=SOME_ROUTING_KEY,
                    headers={'name': TRIGGER_EVENT_NAME})

        def callback_received():
            try:
                third_party.verify(
                    request={
                        'method':
                        'POST',
                        'path':
                        '/test',
                        'body':
                        'keỳ: vàlue',
                        'headers': [{
                            'name': 'Content-Type',
                            'values': ['text/yaml']
                        }],
                    })
            except Exception:
                raise AssertionError()

        until.assert_(callback_received, tries=10, interval=0.5)
Пример #32
0
    def test_given_http_subscription_with_url_template_when_bus_event_then_callback_with_url_templated(
            self, subscription):
        third_party = self.make_third_party()
        bus = self.make_bus()

        bus.publish(trigger_event(data={
            'variable': 'value',
            'another_variable': 'another_value'
        }),
                    routing_key=SOME_ROUTING_KEY,
                    headers={'name': TRIGGER_EVENT_NAME})

        def callback_received():
            try:
                third_party.verify(
                    request={
                        'method':
                        'GET',
                        'path':
                        '/test/value',
                        'queryStringParameters': [{
                            'name': 'variable',
                            'value': 'value'
                        }, {
                            'name': 'another_variable',
                            'value': 'another_value'
                        }]
                    })
            except Exception:
                raise AssertionError()

        until.assert_(callback_received, tries=10, interval=0.5)
Пример #33
0
    def test_when_asterisk_restart_then_ctid_ng_reconnects(self):
        until.assert_(self._ctid_ng_is_connected, tries=3)

        self.restart_service('ari')

        assert_that(self.service_logs(), contains_string("ARI connection error"))

        until.assert_(self._ctid_ng_is_connected, tries=3)
Пример #34
0
    def test_when_channel_ends_then_stat_channel_ended(self):
        channel_id = 'channel-id'
        self.bus.listen_events(routing_key='collectd.channels', exchange='collectd')

        self.bus.send_ami_hangup_event(channel_id=channel_id)

        def assert_function():
            expected_message = 'PUTVAL [^/]+/channels-global/counter-ended .* N:1'
            assert_that(self.bus.events(), has_item(matches_regexp(expected_message)))

        until.assert_(assert_function, tries=5)
Пример #35
0
 def _assert_presence_msg_sent_on_bus(self):
     def assert_function():
         assert_that(self.bus.events(), has_item(equal_to({
             'name': 'user_status_update',
             'origin_uuid': XIVO_UUID,
             'required_acl': 'events.statuses.users',
             'data': {
                 'user_uuid': self.token_user_uuid,
                 'status': 'available',
             }
         })))
     until.assert_(assert_function, tries=5)
Пример #36
0
    def test_when_new_stasis_channel_then_stat_call_start(self):
        call_id = new_call_id()
        self.ari.set_channels(MockChannel(id=call_id))
        self.bus.listen_events(routing_key='collectd.calls', exchange='collectd')

        self.stasis.event_stasis_start(channel_id=call_id)

        def assert_function():
            expected_message = 'PUTVAL [^/]+/calls-{app}.{app_instance}/counter-start .* N:1'
            expected_message = expected_message.format(app=STASIS_APP_NAME,
                                                       app_instance=STASIS_APP_INSTANCE_NAME)
            assert_that(self.bus.events(), has_item(matches_regexp(expected_message)))

        until.assert_(assert_function, tries=5)
Пример #37
0
    def test_given_connected_when_stasis_channel_destroyed_then_do_not_stat_abandoned_call(self):
        call_id = new_call_id()
        self.ari.set_channels(MockChannel(id=call_id))
        self.bus.listen_events(routing_key='collectd.calls', exchange='collectd')

        self.stasis.event_stasis_start(channel_id=call_id)
        self.stasis.event_channel_destroyed(channel_id=call_id,
                                            connected_number='another-number')

        def assert_function():
            expected_message = 'PUTVAL [^/]+/calls-{app}.{app_instance}/counter-abandoned .* N:1'
            expected_message = expected_message.format(app=STASIS_APP_NAME,
                                                       app_instance=STASIS_APP_INSTANCE_NAME)
            assert_that(self.bus.events(), not_(has_item(matches_regexp(expected_message))))

        until.assert_(assert_function, tries=3)
Пример #38
0
    def test_given_ctid_ng_restarts_during_call_when_stasis_channel_destroyed_then_stat_call_end(self):
        call_id = new_call_id()
        self.ari.set_channels(MockChannel(id=call_id))
        self.bus.listen_events(routing_key='collectd.calls', exchange='collectd')
        self.stasis.event_stasis_start(channel_id=call_id)

        self.restart_service('ctid-ng')
        until.true(self.ari.websockets, tries=5)  # wait for xivo-ctid-ng to come back up
        self.stasis.event_channel_destroyed(channel_id=call_id)

        def assert_ctid_ng_sent_end_call_stat():
            expected_message = 'PUTVAL [^/]+/calls-{app}.{app_instance}/counter-end .* N:1'
            expected_message = expected_message.format(app=STASIS_APP_NAME,
                                                       app_instance=STASIS_APP_INSTANCE_NAME)
            assert_that(self.bus.events(), has_item(matches_regexp(expected_message)))

        until.assert_(assert_ctid_ng_sent_end_call_stat, tries=5)
Пример #39
0
    def test_when_stasis_channel_destroyed_then_stat_call_duration(self):
        call_id = new_call_id()
        self.ari.set_channels(MockChannel(id=call_id))
        self.bus.listen_events(routing_key='collectd.calls', exchange='collectd')

        self.stasis.event_stasis_start(channel_id=call_id)
        self.stasis.event_channel_destroyed(channel_id=call_id,
                                            creation_time='2016-02-01T15:00:00.000-0500',
                                            timestamp='2016-02-01T16:00:00.000-0500')

        def assert_function():
            expected_message = 'PUTVAL [^/]+/calls-{app}.{app_instance}/gauge-duration .* N:3600'
            expected_message = expected_message.format(app=STASIS_APP_NAME,
                                                       app_instance=STASIS_APP_INSTANCE_NAME)
            assert_that(self.bus.events(), has_item(matches_regexp(expected_message)))

        until.assert_(assert_function, tries=5)
Пример #40
0
    def test_given_rabbitmq_restarts_during_call_when_stasis_channel_destroyed_then_stat_call_end(self):
        call_id = new_call_id()
        self.ari.set_channels(MockChannel(id=call_id))
        self.stasis.event_stasis_start(channel_id=call_id)

        self.restart_service('rabbitmq')
        until.true(self.bus.is_up, tries=int(os.environ.get('INTEGRATION_TEST_TIMEOUT', 30)))  # wait for rabbitmq to come back up

        self.bus.listen_events(routing_key='collectd.calls', exchange='collectd')
        self.stasis.event_channel_destroyed(channel_id=call_id)

        def assert_ctid_ng_sent_end_call_stat():
            expected_message = 'PUTVAL [^/]+/calls-{app}.{app_instance}/counter-end .* N:1'
            expected_message = expected_message.format(app=STASIS_APP_NAME,
                                                       app_instance=STASIS_APP_INSTANCE_NAME)
            assert_that(self.bus.events(), has_item(matches_regexp(expected_message)))

        until.assert_(assert_ctid_ng_sent_end_call_stat, tries=5)