def setUp(self): super().setUp() until.true(self.bus_is_up, tries=10) bus_port = self.service_port(5672, 'rabbitmq') self.bus = BusClient.from_connection_fields(host='127.0.0.1', port=bus_port) self.bus.downstream_exchange_declare('wazo-headers', 'headers')
def test_stasis_amqp_channel_events_headers(ari): bus_client = BusClient.from_connection_fields( port=AssetLauncher.service_port(5672, 'rabbitmq'), exchange_type='headers', ) accumulator = bus_client.accumulator(headers={ 'category': 'stasis', 'name': 'Dial', 'x-match': 'all', }) ari.channels.originate(endpoint='local/3000@default', extension='1000', context='default') def event_received(): events = accumulator.accumulate(with_headers=True) print(events) assert_that(events, has_item(has_entries( headers=has_entries( category='stasis', name='Dial', ), message=has_entries( name='Dial', data=has_entries( type='Dial', dialstring='3000@default', ), ), ))) until.assert_(event_received, timeout=5)
def test_stasis_amqp_events_bad_routing(ari): real_app = 'A' parasite_app = 'B' ari.amqp.stasisSubscribe(applicationName=real_app) ari.amqp.stasisSubscribe(applicationName=parasite_app) bus_client = BusClient.from_connection_fields( port=AssetLauncher.service_port(5672, 'rabbitmq'), exchange_type='headers', ) assert bus_client.is_up() accumulator = bus_client.accumulator(headers={ 'category': 'stasis', 'application_name': parasite_app, 'x-match': 'all', }) ari.channels.originate(endpoint='local/3000@default', app=real_app.lower()) def event_received(): assert_that(accumulator.accumulate(), empty()) until.assert_(event_received, timeout=5)
def test_stasis_amqp_channel_events_disabled(ari): ari.amqp.stasisSubscribe(applicationName='myapp') bus_client = BusClient.from_connection_fields( port=AssetLauncher.service_port(5672, 'rabbitmq'), exchange_type='headers', ) channel_accumulator = bus_client.accumulator(headers={ 'category': 'ami', 'name': 'Dial', 'x-match': 'all', }) app_accumulator = bus_client.accumulator(headers={ 'category': 'stasis', 'application_name': 'myapp', 'x-match': 'all', }) ari.channels.originate(endpoint='local/3000@default', app='myapp') def event_received(): events = app_accumulator.accumulate(with_headers=True) assert_that(events, only_contains( has_entries( headers=has_entries(application_name='myapp', category='stasis'), ), )) until.assert_(event_received, timeout=5) events = channel_accumulator.accumulate(with_headers=True) assert_that(events, empty())
def test_stasis_amqp_events_headers(ari): real_app = 'A' parasite_app = 'B' ari.amqp.stasisSubscribe(applicationName=real_app) ari.amqp.stasisSubscribe(applicationName=parasite_app) assert_that(ari.applications.list(), has_item(has_entry('name', real_app))) assert_that(ari.applications.list(), has_item(has_entry('name', parasite_app))) bus_client = BusClient.from_connection_fields( port=AssetLauncher.service_port(5672, 'rabbitmq'), exchange_type='headers', ) assert bus_client.is_up() accumulator = bus_client.accumulator(headers={ 'category': 'stasis', 'application_name': real_app, 'x-match': 'all', }) parasite_accumulator = bus_client.accumulator(headers={ 'category': 'stasis', 'application_name': parasite_app, 'x-match': 'all', }) ari.channels.originate(endpoint='local/3000@default', app=real_app) ari.channels.originate(endpoint='local/3000@default', app=parasite_app) def event_received(): events = accumulator.accumulate(with_headers=True) assert_that(events, only_contains( has_entries( headers=has_entries(application_name=real_app, category='stasis'), message=has_entries(data=has_entries(application=real_app)), ), )) assert_that(parasite_accumulator.accumulate(), only_contains( has_entries(data=has_entries(application=is_not(real_app))), )) until.assert_(event_received, timeout=5) def event_received(): assert_that(accumulator.accumulate(), only_contains( has_entries(data=has_entries(application=real_app)) )) assert_that(parasite_accumulator.accumulate(), only_contains( has_entries(data=has_entries(application=is_not(real_app))) )) until.assert_(event_received, timeout=5)
def setUp(self): bus_port = self.service_port(5672, 'rabbitmq') self.bus = BusClient.from_connection_fields(host='127.0.0.1', port=bus_port) sysconfd_port = self.service_port(8668, 'sysconfd') self.sysconfd = SysconfdClient( '127.0.0.1', sysconfd_port, prefix='', https=False, )
def setUp(self): super().setUp() self.tenant_uuid = SUB_TENANT self.tenant_name = 'mytenant' bus_port = self.service_port(5672, 'rabbitmq') self.bus = BusClient.from_connection_fields(host='127.0.0.1', port=bus_port) self.bus.downstream_exchange_declare('wazo-headers', 'headers') self.mock_auth_client = MockAuthClient( '127.0.0.1', 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)
def test_stasis_amqp_events_bad_routing(ari): real_app = 'A' parasite_app = 'B' ari.amqp.stasisSubscribe(applicationName=real_app) ari.amqp.stasisSubscribe(applicationName=parasite_app) bus_client = BusClient.from_connection_fields(port=AssetLauncher.service_port(5672, 'rabbitmq')) assert bus_client.is_up() events = bus_client.accumulator("stasis.app." + parasite_app.lower()) ari.channels.originate(endpoint='local/3000@default', app=real_app.lower()) def event_received(events, app): assert_that(events.accumulate(), empty()) until.assert_(event_received, events, subscribe_args[app_name_key], timeout=5)
def test_stasis_amqp_events_topic(ari): real_app = 'A' parasite_app = 'B' ari.amqp.stasisSubscribe(applicationName=real_app) ari.amqp.stasisSubscribe(applicationName=parasite_app) assert_that(ari.applications.list(), has_item(has_entry('name', real_app))) assert_that(ari.applications.list(), has_item(has_entry('name', parasite_app))) bus_client = BusClient.from_connection_fields( port=AssetLauncher.service_port(5672, 'rabbitmq'), ) assert bus_client.is_up() accumulator = bus_client.accumulator('stasis.app.a') parasite_accumulator = bus_client.accumulator('stasis.app.b') ari.channels.originate(endpoint='local/3000@default', app=real_app) ari.channels.originate(endpoint='local/3000@default', app=parasite_app) def event_received(): events = accumulator.accumulate() assert_that(events, only_contains( has_entries(data=has_entries(application=real_app)), )) assert_that(parasite_accumulator.accumulate(), only_contains( has_entries(data=has_entries(application=is_not(real_app))), )) until.assert_(event_received, timeout=5) def event_received(): assert_that(accumulator.accumulate(), only_contains( has_entries(data=has_entries(application=real_app)) )) assert_that(parasite_accumulator.accumulate(), only_contains( has_entries(data=has_entries(application=is_not(real_app))) )) until.assert_(event_received, timeout=5)
def test_stasis_amqp_events(ari): real_app = 'A' parasite_app = 'B' ari.amqp.stasisSubscribe(applicationName=real_app) ari.amqp.stasisSubscribe(applicationName=parasite_app) assert_that(ari.applications.list(), has_item(has_entry('name', real_app))) assert_that(ari.applications.list(), has_item(has_entry('name', parasite_app))) bus_client = BusClient.from_connection_fields(port=AssetLauncher.service_port(5672, 'rabbitmq')) assert bus_client.is_up() events = bus_client.accumulator("stasis.app." + real_app.lower()) parasite_events = bus_client.accumulator("stasis.app." + parasite_app.lower()) ari.channels.originate(endpoint='local/3000@default', app=real_app) ari.channels.originate(endpoint='local/3000@default', app=parasite_app) def event_received(events, app): assert_that(events.accumulate(), only_contains( has_entry('application', app) )) assert_that(parasite_events.accumulate(), only_contains( has_entry('application', is_not(app)) )) until.assert_(event_received, events, real_app, timeout=5) def event_received(events, app): assert_that(events.accumulate(), only_contains( has_entry('application', app) )) assert_that(parasite_events.accumulate(), only_contains( has_entry('application', is_not(app)) )) until.assert_(event_received, events, real_app, timeout=5)
def test_stasis_amqp_channel_events_topic(ari): bus_client = BusClient.from_connection_fields( port=AssetLauncher.service_port(5672, 'rabbitmq'), ) accumulator = bus_client.accumulator('stasis.channel.dial') ari.channels.originate(endpoint='local/3000@default', extension='1000', context='default') def event_received(): events = accumulator.accumulate() assert_that(events, has_item( has_entries( name='Dial', data=has_entries( type='Dial', dialstring='3000@default', ), ), )) until.assert_(event_received, timeout=5)
def test_that_adding_favorite_produces_bus_event(self): bus_port = self.service_port(5672, 'rabbitmq') bus = BusClient.from_connection_fields(host='127.0.0.1', port=bus_port) until.true(bus.is_up, tries=5) bus.downstream_exchange_declare('wazo-headers', 'headers') bus_events = bus.accumulator('directory.*.favorite.*') def favorite_bus_event_received(name): assert_that( bus_events.accumulate(with_headers=True), has_item( has_entries( message=has_entry('name', name), headers=has_entry('tenant_uuid', MAIN_TENANT), )), ) with self.personal({'firstname': 'Alice'}) as alice: with self.favorite('personal', alice['id']): until.assert_(favorite_bus_event_received, 'favorite_added', tries=2) until.assert_(favorite_bus_event_received, 'favorite_deleted', tries=2)
def create_bus(cls): port = cls.service_port(5672, 'rabbitmq') client = BusClient.from_connection_fields(host='127.0.0.1', port=port) return client
def make_bus_client(cls): try: port = cls.service_port(5672, 'rabbitmq') except (NoSuchService, NoSuchPort): return WrongClient('rabbitmq') return BusClient.from_connection_fields(host='127.0.0.1', port=port)