当前位置: 首页>>代码示例>>Python>>正文


Python channel.Channel类代码示例

本文整理汇总了Python中junebug.channel.Channel的典型用法代码示例。如果您正苦于以下问题:Python Channel类的具体用法?Python Channel怎么用?Python Channel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Channel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_send_message

    def test_send_message(self):
        '''Sending a message should place the message on the queue for the
        channel'''
        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/messages/', {
            'to': '+1234', 'content': 'foo', 'from': None})
        yield self.assert_response(
            resp, http.OK, 'message sent', {
                'to': '+1234',
                'channel_id': 'test-channel',
                'from': None,
                'reply_to': None,
                'channel_data': {},
                'content': 'foo',
            }, ignore=['timestamp', 'message_id'])

        [message] = self.get_dispatched_messages('test-channel.outbound')
        message_id = (yield resp.json())['result']['message_id']
        self.assertEqual(message['message_id'], message_id)

        event_url = yield self.api.outbounds.load_event_url(
            'test-channel', message['message_id'])
        self.assertEqual(event_url, None)
开发者ID:westerncapelabs,项目名称:junebug,代码行数:28,代码来源:test_api.py

示例2: test_send_message_event_url

    def test_send_message_event_url(self):
        '''Sending a message with a specified event url should store the event
        url for sending events in the future'''
        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/messages/', {
            'to': '+1234', 'content': 'foo', 'from': None,
            'event_url': 'http://test.org'})
        yield self.assert_response(
            resp, http.OK, 'message sent', {
                'to': '+1234',
                'channel_id': 'test-channel',
                'from': None,
                'reply_to': None,
                'channel_data': {},
                'content': 'foo',
            }, ignore=['timestamp', 'message_id'])

        event_url = yield self.api.outbounds.load_event_url(
            'test-channel', (yield resp.json())['result']['message_id'])
        self.assertEqual(event_url, 'http://test.org')
开发者ID:westerncapelabs,项目名称:junebug,代码行数:25,代码来源:test_api.py

示例3: create_channel

    def create_channel(
            self, service, redis, transport_class=None,
            properties=default_channel_properties, id=None, config=None,
            plugins=[]):
        '''Creates and starts, and saves a channel, with a
        TelnetServerTransport transport'''
        self.patch(junebug.logging_service, 'LogFile', DummyLogFile)
        if transport_class is None:
            transport_class = 'vumi.transports.telnet.TelnetServerTransport'

        properties = deepcopy(properties)
        logpath = self.mktemp()
        if config is None:
            config = yield self.create_channel_config(
                channels={
                    properties['type']: transport_class
                },
                logging_path=logpath)

        channel = Channel(
            redis, config, properties, id=id, plugins=plugins)
        yield channel.start(self.service)

        properties['config']['transport_name'] = channel.id

        yield channel.save()
        self.addCleanup(channel.stop)
        returnValue(channel)
开发者ID:BantouTelecom,项目名称:junebug,代码行数:28,代码来源:helpers.py

示例4: test_delete_channel

    def test_delete_channel(self):
        config = yield self.create_channel_config()
        properties = self.create_channel_properties()
        channel = Channel(self.redis, config, properties, 'test-channel')
        yield channel.save()
        yield channel.start(self.service)

        self.assertTrue('test-channel' in self.service.namedServices)
        properties = yield self.redis.get('test-channel:properties')
        self.assertNotEqual(properties, None)

        resp = yield self.delete('/channels/test-channel')
        yield self.assert_response(resp, http.OK, 'channel deleted', {})

        self.assertFalse('test-channel' in self.service.namedServices)
        properties = yield self.redis.get('test-channel:properties')
        self.assertEqual(properties, None)

        resp = yield self.delete('/channels/test-channel')
        yield self.assert_response(
            resp, http.NOT_FOUND, 'channel not found', {
                'errors': [{
                    'message': '',
                    'type': 'ChannelNotFound',
                }]
            })

        self.assertFalse('test-channel' in self.service.namedServices)
        properties = yield self.redis.get('test-channel:properties')
        self.assertEqual(properties, None)
开发者ID:westerncapelabs,项目名称:junebug,代码行数:30,代码来源:test_api.py

示例5: send_message

    def send_message(self, request, body, channel_id):
        '''Send an outbound (mobile terminated) message'''
        if 'to' not in body and 'reply_to' not in body:
            raise ApiUsageError(
                'Either "to" or "reply_to" must be specified')

        if 'to' in body and 'reply_to' in body:
            raise ApiUsageError(
                'Only one of "to" and "reply_to" may be specified')

        if 'from' in body and 'reply_to' in body:
            raise ApiUsageError(
                'Only one of "from" and "reply_to" may be specified')

        try:
            self.service.getServiceNamed(channel_id)
        except KeyError:
            raise ChannelNotFound()

        if 'to' in body:
            msg = yield Channel.send_message(
                channel_id, self.message_sender, self.outbounds, body)
        else:
            msg = yield Channel.send_reply_message(
                channel_id, self.message_sender, self.outbounds,
                self.inbounds, body)

        returnValue(response(request, 'message sent', msg))
开发者ID:westerncapelabs,项目名称:junebug,代码行数:28,代码来源:api.py

示例6: create_channel

 def create_channel(self, request, body):
     '''Create a channel'''
     channel = Channel(
         self.redis, self.config, body)
     yield channel.save()
     yield channel.start(self.service)
     returnValue(response(
         request, 'channel created', (yield channel.status())))
开发者ID:westerncapelabs,项目名称:junebug,代码行数:8,代码来源:api.py

示例7: create_channel

 def create_channel(self, request, body):
     '''Create a channel'''
     channel = Channel(
         self.redis, self.config, body, self.plugins)
     yield channel.start(self.service)
     yield channel.save()
     returnValue(response(
         request, 'channel created', (yield channel.status()),
         code=http.CREATED))
开发者ID:praekelt,项目名称:junebug,代码行数:9,代码来源:api.py

示例8: create_channel

    def create_channel(self, request, body):
        '''Create a channel'''
        if not (body.get('mo_url') or body.get('amqp_queue')):
            raise ApiUsageError(
                'One or both of "mo_url" and "amqp_queue" must be specified')

        channel = Channel(
            self.redis, self.config, body, self.plugins)
        yield channel.save()
        yield channel.start(self.service)
        returnValue(response(
            request, 'channel created', (yield channel.status())))
开发者ID:BantouTelecom,项目名称:junebug,代码行数:12,代码来源:api.py

示例9: test_get_all_channels

    def test_get_all_channels(self):
        channels = yield Channel.get_all(self.redis)
        self.assertEqual(channels, set())

        channel1 = yield self.create_channel(
            self.service, self.redis, TelnetServerTransport)
        channels = yield Channel.get_all(self.redis)
        self.assertEqual(channels, set([channel1.id]))

        channel2 = yield self.create_channel(
            self.service, self.redis, TelnetServerTransport)
        channels = yield Channel.get_all(self.redis)
        self.assertEqual(channels, set([channel1.id, channel2.id]))
开发者ID:westerncapelabs,项目名称:junebug,代码行数:13,代码来源:test_channel.py

示例10: test_get_channel

    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',
            }))
开发者ID:westerncapelabs,项目名称:junebug,代码行数:14,代码来源:test_api.py

示例11: create_channel

 def create_channel(
         self, service, redis, transport_class,
         properties=default_channel_properties, id=None):
     '''Creates and starts, and saves a channel, with a
     TelnetServerTransport transport'''
     properties = deepcopy(properties)
     config = yield self.create_channel_config()
     channel = Channel(
         redis, config, properties, id=id)
     properties['config']['transport_name'] = channel.id
     yield channel.start(self.service)
     yield channel.save()
     self.addCleanup(channel.stop)
     returnValue(channel)
开发者ID:westerncapelabs,项目名称:junebug,代码行数:14,代码来源:helpers.py

示例12: test_send_message_message_rate

    def test_send_message_message_rate(self):
        '''Sending a message should increment the message rate counter'''
        clock = yield self.patch_message_rate_clock()
        channel = Channel(
            (yield self.get_redis()), (yield self.create_channel_config()),
            self.create_channel_properties(), id='test-channel')
        yield channel.save()
        yield channel.start(self.service)

        yield self.post('/channels/test-channel/messages/', {
            'to': '+1234', 'content': 'foo', 'from': None})
        clock.advance(channel.config.metric_window)

        rate = yield self.api.message_rate.get_messages_per_second(
            'test-channel', 'outbound', channel.config.metric_window)
        self.assertEqual(rate, 1.0 / channel.config.metric_window)
开发者ID:BantouTelecom,项目名称:junebug,代码行数:16,代码来源:test_api.py

示例13: setup

    def setup(self, redis=None, message_sender=None):
        if redis is None:
            redis = yield TxRedisManager.from_config(self.redis_config)

        if message_sender is None:
            message_sender = MessageSender(
                'amqp-spec-0-8.xml', self.amqp_config)

        self.redis = redis
        self.message_sender = message_sender
        self.message_sender.setServiceParent(self.service)

        self.inbounds = InboundMessageStore(
            self.redis, self.config.inbound_message_ttl)

        self.outbounds = OutboundMessageStore(
            self.redis, self.config.outbound_message_ttl)

        self.message_rate = MessageRateStore(self.redis)

        self.plugins = []
        for plugin_config in self.config.plugins:
            cls = load_class_by_string(plugin_config['type'])
            plugin = cls()
            yield plugin.start_plugin(plugin_config, self.config)
            self.plugins.append(plugin)

        yield Channel.start_all_channels(
            self.redis, self.config, self.service, self.plugins)
开发者ID:BantouTelecom,项目名称:junebug,代码行数:29,代码来源:api.py

示例14: send_message

    def send_message(self, request, body, channel_id):
        '''Send an outbound (mobile terminated) message'''
        if 'to' not in body and 'reply_to' not in body:
            raise ApiUsageError(
                'Either "to" or "reply_to" must be specified')

        if 'to' in body and 'reply_to' in body:
            raise ApiUsageError(
                'Only one of "to" and "reply_to" may be specified')

        if 'from' in body and 'reply_to' in body:
            raise ApiUsageError(
                'Only one of "from" and "reply_to" may be specified')

        channel = yield Channel.from_id(
            self.redis, self.config, channel_id, self.service, self.plugins)

        if 'to' in body:
            msg = yield channel.send_message(
                self.message_sender, self.outbounds, body)
        else:
            msg = yield channel.send_reply_message(
                self.message_sender, self.outbounds, self.inbounds, body)

        yield self.message_rate.increment(
            channel_id, 'outbound', self.config.metric_window)

        returnValue(response(request, 'message sent', msg))
开发者ID:BantouTelecom,项目名称:junebug,代码行数:28,代码来源:api.py

示例15: test_send_reply_message_event_url

    def test_send_reply_message_event_url(self):
        '''Sending a message with a specified event url should store the event
        url for sending events in the future'''
        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',
                'event_url': 'http://test.org',
            })

        event_url = yield self.outbounds.load_event_url(
            'channel-id', msg['message_id'])

        self.assertEqual(event_url, 'http://test.org')
开发者ID:westerncapelabs,项目名称:junebug,代码行数:26,代码来源:test_channel.py


注:本文中的junebug.channel.Channel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。