예제 #1
0
    def test_channel_status(self):
        properties = self.create_channel_properties()
        channel = yield self.create_channel(
            self.service, self.redis, TelnetServerTransport, id='channel-id')

        self.assertEqual((yield channel.status()), conjoin(properties, {
            'status': {},
            'id': 'channel-id',
            'config': conjoin(properties['config'], {
                'transport_name': channel.id
            })
        }))
예제 #2
0
    def test_channel_status_empty(self):
        properties = self.create_channel_properties()
        channel = yield self.create_channel(
            self.service, self.redis, id='channel-id')

        self.assertEqual((yield channel.status()), conjoin(properties, {
            'status': self.generate_status(),
            'id': 'channel-id',
            'config': conjoin(properties['config'], {
                'transport_name': channel.id
            })
        }))
예제 #3
0
    def test_save_channel(self):
        properties = self.create_channel_properties()
        channel = yield self.create_channel(
            self.service, self.redis, TelnetServerTransport)

        props = yield self.redis.get('%s:properties' % channel.id)
        self.assertEqual(json.loads(props), conjoin(properties, {
            'config': conjoin(
                properties['config'], {'transport_name': channel.id})
        }))

        channel_list = yield self.redis.get('channels')
        self.assertEqual(channel_list, set([channel.id]))
예제 #4
0
    def test_save_channel(self):
        properties = self.create_channel_properties()
        channel = yield self.create_channel(
            self.service, self.redis)

        props = yield self.redis.get('%s:properties' % channel.id)
        self.assertEqual(json.loads(props), conjoin(properties, {
            'config': conjoin(
                properties['config'], {'transport_name': channel.id})
        }))

        channel_list = yield self.redis.get('channels')
        self.assertEqual(channel_list, set([channel.id]))
예제 #5
0
파일: test_utils.py 프로젝트: todun/junebug
    def test_conjoin(self):
        a = {
            'foo': 21,
            'bar': 23,
        }

        b = {
            'bar': 'baz',
            'quux': 'corge',
        }

        self.assertEqual(conjoin(a, b), {
            'foo': 21,
            'bar': 'baz',
            'quux': 'corge',
        })

        self.assertEqual(a, {
            'foo': 21,
            'bar': 23,
        })

        self.assertEqual(b, {
            'bar': 'baz',
            'quux': 'corge',
        })
예제 #6
0
    def test_update_channel_config(self):
        properties = self.create_channel_properties()

        channel = yield self.create_channel(
            self.service, self.redis, TelnetServerTransport)

        update = yield channel.update({'foo': 'bar'})

        self.assertEqual(update, conjoin(properties, {
            'foo': 'bar',
            'status': {},
            'id': channel.id,
            'config': conjoin(properties['config'], {
                'transport_name': channel.id
            })
        }))
예제 #7
0
    def get_worker(self, config=None):
        """Get a new MessageForwardingWorker with the provided config"""
        if config is None:
            config = {}

        app_helper = ApplicationHelper(MessageForwardingWorker)
        yield app_helper.setup()
        self.addCleanup(app_helper.cleanup)

        persistencehelper = PersistenceHelper()
        yield persistencehelper.setup()
        self.addCleanup(persistencehelper.cleanup)

        config = conjoin(
            persistencehelper.mk_config(
                {
                    "transport_name": "testtransport",
                    "mo_message_url": self.url.decode("utf-8"),
                    "inbound_ttl": 60,
                    "outbound_ttl": 60 * 60 * 24 * 2,
                }
            ),
            config,
        )

        worker = yield app_helper.get_application(config)
        returnValue(worker)
예제 #8
0
    def test_update_channel_config(self):
        properties = self.create_channel_properties()

        channel = yield self.create_channel(
            self.service, self.redis)

        update = yield channel.update({'foo': 'bar'})

        self.assertEqual(update, conjoin(properties, {
            'foo': 'bar',
            'status': self.generate_status(),
            'id': channel.id,
            'config': conjoin(properties['config'], {
                'transport_name': channel.id
            })
        }))
예제 #9
0
    def get_worker(self, config=None):
        '''Get a new MessageForwardingWorker with the provided config'''
        if config is None:
            config = {}

        self.app_helper = ApplicationHelper(MessageForwardingWorker)
        yield self.app_helper.setup()
        self.addCleanup(self.app_helper.cleanup)

        persistencehelper = PersistenceHelper()
        yield persistencehelper.setup()
        self.addCleanup(persistencehelper.cleanup)

        config = conjoin(
            persistencehelper.mk_config({
                'transport_name':
                'testtransport',
                'mo_message_url':
                self.url.decode('utf-8'),
                'inbound_ttl':
                60,
                'outbound_ttl':
                60 * 60 * 24 * 2,
                'metric_window':
                1.0,
            }), config)

        worker = yield self.app_helper.get_application(config)
        returnValue(worker)
예제 #10
0
    def test_conjoin(self):
        a = {
            'foo': 21,
            'bar': 23,
        }

        b = {
            'bar': 'baz',
            'quux': 'corge',
        }

        self.assertEqual(conjoin(a, b), {
            'foo': 21,
            'bar': 'baz',
            'quux': 'corge',
        })

        self.assertEqual(a, {
            'foo': 21,
            'bar': 23,
        })

        self.assertEqual(b, {
            'bar': 'baz',
            'quux': 'corge',
        })
예제 #11
0
    def test_send_reply_message(self):
        '''send_reply_message should place the correct reply message on the
        correct queue'''
        channel = yield self.create_channel(self.service,
                                            self.redis,
                                            id='channel-id')

        in_msg = TransportUserMessage(from_addr='+2789',
                                      to_addr='+1234',
                                      transport_name='channel-id',
                                      transport_type='_',
                                      transport_metadata={'foo': 'bar'})

        yield self.api.inbounds.store_vumi_message('channel-id', in_msg)

        msg = yield channel.send_reply_message(
            self.message_sender, self.outbounds, self.inbounds, {
                'reply_to': in_msg['message_id'],
                'content': 'testcontent',
            })

        expected = in_msg.reply(content='testcontent')
        expected = conjoin(api_from_message(expected), {
            'timestamp': msg['timestamp'],
            'message_id': msg['message_id']
        })

        self.assertEqual(msg, expected)

        [dispatched] = self.get_dispatched_messages('channel-id.outbound')
        self.assertEqual(msg['message_id'], dispatched['message_id'])
        self.assertEqual(api_from_message(dispatched), expected)
예제 #12
0
    def test_send_reply_message(self):
        '''send_reply_message should place the correct reply message on the
        correct queue'''
        yield self.create_channel(
            self.service, self.redis, TelnetServerTransport, id='channel-id')

        in_msg = TransportUserMessage(
            from_addr='+2789',
            to_addr='+1234',
            transport_name='channel-id',
            transport_type='_',
            transport_metadata={'foo': 'bar'})

        yield self.api.inbounds.store_vumi_message('channel-id', in_msg)

        msg = yield Channel.send_reply_message(
            'channel-id', self.message_sender, self.outbounds, self.inbounds, {
                'reply_to': in_msg['message_id'],
                'content': 'testcontent',
            })

        expected = in_msg.reply(content='testcontent')
        expected = conjoin(api_from_message(expected), {
            'timestamp': msg['timestamp'],
            'message_id': msg['message_id']
        })

        self.assertEqual(msg, expected)

        [dispatched] = self.get_dispatched_messages('channel-id.outbound')
        self.assertEqual(msg['message_id'], dispatched['message_id'])
        self.assertEqual(api_from_message(dispatched), expected)
예제 #13
0
    def test_create_channel(self):
        properties = self.create_channel_properties()
        resp = yield self.post('/channels/', properties)

        yield self.assert_response(
            resp, http.OK, 'channel created',
            conjoin(properties, {'status': {}}),
            ignore=['id'])
예제 #14
0
파일: test_api.py 프로젝트: grigi/junebug
    def test_create_channel(self):
        properties = self.create_channel_properties()
        resp = yield self.post('/channels/', properties)

        yield self.assert_response(resp,
                                   http.OK,
                                   'channel created',
                                   conjoin(properties,
                                           {'status': self.generate_status()}),
                                   ignore=['id'])
예제 #15
0
    def get_router_worker(self, config=None):
        if config is None:
            config = {}

        config = conjoin(
            self.persistencehelper.mk_config(
                self.DEFAULT_ROUTER_WORKER_CONFIG), config)

        FromAddressRouter._create_worker = self.workerhelper.get_worker
        worker = yield self.workerhelper.get_worker(FromAddressRouter, config)
        returnValue(worker)
예제 #16
0
    def get_router_worker(self, config=None):
        if config is None:
            config = {}

        config = conjoin(
            self.persistencehelper.mk_config(
                self.DEFAULT_ROUTER_WORKER_CONFIG),
            config)

        TestRouter._create_worker = self.workerhelper.get_worker
        worker = yield self.workerhelper.get_worker(TestRouter, config)
        returnValue(worker)
예제 #17
0
    def test_create_channel_transport(self):
        properties = self.create_channel_properties()
        resp = yield self.post('/channels/', properties)

        # Check that the transport is created with the correct config
        id = (yield resp.json())['result']['id']
        transport = self.service.namedServices[id]

        self.assertEqual(transport.parent, self.service)

        self.assertEqual(transport.config, conjoin(properties['config'], {
            'transport_name': id,
        }))
예제 #18
0
    def test_get_channel(self):
        properties = self.create_channel_properties()
        config = yield self.create_channel_config()
        redis = yield self.get_redis()
        channel = Channel(redis, config, properties, u'test-channel')
        yield channel.save()
        yield channel.start(self.service)
        resp = yield self.get('/channels/test-channel')

        yield self.assert_response(
            resp, http.OK, 'channel found', conjoin(properties, {
                'status': {},
                'id': 'test-channel',
            }))
예제 #19
0
파일: test_api.py 프로젝트: grigi/junebug
    def test_get_channel(self):
        properties = self.create_channel_properties()
        config = yield self.create_channel_config()
        redis = yield self.get_redis()
        channel = Channel(redis, config, properties, id=u'test-channel')
        yield channel.save()
        yield channel.start(self.service)
        resp = yield self.get('/channels/test-channel')

        yield self.assert_response(
            resp, http.OK, 'channel found',
            conjoin(properties, {
                'status': self.generate_status(),
                'id': 'test-channel',
            }))
예제 #20
0
    def test_modify_channel_config_change(self):
        redis = yield self.get_redis()
        properties = self.create_channel_properties()
        config = yield self.create_channel_config()

        channel = Channel(redis, config, properties, 'test-channel')
        yield channel.save()
        yield channel.start(self.service)

        properties['config']['name'] = 'bar'
        resp = yield self.post('/channels/test-channel', properties)

        yield self.assert_response(
            resp, http.OK, 'channel updated', conjoin(properties, {
                'status': {},
                'id': 'test-channel',
            }))
예제 #21
0
파일: test_api.py 프로젝트: grigi/junebug
    def test_create_channel_transport(self):
        properties = self.create_channel_properties()
        resp = yield self.post('/channels/', properties)

        # Check that the transport is created with the correct config
        id = (yield resp.json())['result']['id']
        transport = self.service.namedServices[id]

        self.assertEqual(transport.parent, self.service)

        self.assertEqual(
            transport.config,
            conjoin(properties['config'], {
                'transport_name': id,
                'worker_name': id,
                'publish_status': True,
            }))
예제 #22
0
파일: test_api.py 프로젝트: grigi/junebug
    def test_modify_channel_config_change(self):
        redis = yield self.get_redis()
        properties = self.create_channel_properties()
        config = yield self.create_channel_config()

        channel = Channel(redis, config, properties, id='test-channel')
        yield channel.save()
        yield channel.start(self.service)

        properties['config']['name'] = 'bar'
        resp = yield self.post('/channels/test-channel', properties)

        yield self.assert_response(
            resp, http.OK, 'channel updated',
            conjoin(properties, {
                'status': self.generate_status(),
                'id': 'test-channel',
            }))
예제 #23
0
    def test_modify_channel_no_config_change(self):
        properties = self.create_channel_properties()
        config = yield self.create_channel_config()
        redis = yield self.get_redis()

        channel = Channel(redis, config, properties, 'test-channel')
        yield channel.save()
        yield channel.start(self.service)

        resp = yield self.post(
            '/channels/test-channel', {'metadata': {'foo': 'bar'}})

        yield self.assert_response(
            resp, http.OK, 'channel updated', conjoin(properties, {
                'status': {},
                'id': 'test-channel',
                'metadata': {'foo': 'bar'},
            }))
예제 #24
0
    def get_worker(self, config=None):
        '''Get a new ChannelStatusWorker with the provided config'''
        if config is None:
            config = {}

        app_helper = ApplicationHelper(ChannelStatusWorker)
        yield app_helper.setup()
        self.addCleanup(app_helper.cleanup)

        persistencehelper = PersistenceHelper()
        yield persistencehelper.setup()
        self.addCleanup(persistencehelper.cleanup)

        config = conjoin(persistencehelper.mk_config({
            'channel_id': 'testchannel',
        }), config)

        worker = yield app_helper.get_application(config)
        returnValue(worker)
예제 #25
0
    def get_worker(self, config=None):
        '''Get a new ChannelStatusWorker with the provided config'''
        if config is None:
            config = {}

        app_helper = ApplicationHelper(ChannelStatusWorker)
        yield app_helper.setup()
        self.addCleanup(app_helper.cleanup)

        persistencehelper = PersistenceHelper()
        yield persistencehelper.setup()
        self.addCleanup(persistencehelper.cleanup)

        config = conjoin(persistencehelper.mk_config({
            'channel_id': 'testchannel',
        }), config)

        worker = yield app_helper.get_application(config)
        returnValue(worker)
예제 #26
0
    def get_worker(self, config=None):
        '''Get a new MessageForwardingWorker with the provided config'''
        if config is None:
            config = {}

        self.app_helper = ApplicationHelper(MessageForwardingWorker)
        yield self.app_helper.setup()
        self.addCleanup(self.app_helper.cleanup)

        persistencehelper = PersistenceHelper()
        yield persistencehelper.setup()
        self.addCleanup(persistencehelper.cleanup)

        config = conjoin(persistencehelper.mk_config({
            'transport_name': 'testtransport',
            'mo_message_url': self.url.decode('utf-8'),
            'inbound_ttl': 60,
            'outbound_ttl': 60 * 60 * 24 * 2,
            'metric_window': 1.0,
        }), config)

        worker = yield self.app_helper.get_application(config)
        returnValue(worker)
예제 #27
0
파일: test_api.py 프로젝트: grigi/junebug
    def test_modify_channel_no_config_change(self):
        properties = self.create_channel_properties()
        config = yield self.create_channel_config()
        redis = yield self.get_redis()

        channel = Channel(redis, config, properties, id='test-channel')
        yield channel.save()
        yield channel.start(self.service)

        resp = yield self.post('/channels/test-channel',
                               {'metadata': {
                                   'foo': 'bar'
                               }})

        yield self.assert_response(
            resp, http.OK, 'channel updated',
            conjoin(
                properties, {
                    'status': self.generate_status(),
                    'id': 'test-channel',
                    'metadata': {
                        'foo': 'bar'
                    },
                }))