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


Python message.TransportUserMessage类代码示例

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


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

示例1: test_inbound_resume_continue

 def test_inbound_resume_continue(self):
     url = "%s%s?%s" % (
         self.transport_url,
         self.config['web_path'],
         urlencode({
             'ussdSessionId': 123,
             'msisdn': 555,
             'provider': 'web',
             'request': 1,
         })
     )
     d = http_request(url, '', method='GET')
     msg, = yield self.wait_for_dispatched_messages(1)
     payload = msg.payload
     self.assertEqual(payload['transport_name'], self.transport_name)
     self.assertEqual(payload['transport_type'], "ussd")
     self.assertEqual(payload['transport_metadata'],
                      {"session_id": "123"})
     self.assertEqual(payload['session_event'],
                      TransportUserMessage.SESSION_RESUME)
     self.assertEqual(payload['from_addr'], '555')
     self.assertEqual(payload['to_addr'], '')
     self.assertEqual(payload['content'], '1')
     tum = TransportUserMessage(**payload)
     rep = tum.reply("OK")
     self.dispatch(rep)
     response = yield d
     correct_response = '<request>\n\t<headertext>OK</headertext>\n\t' \
             '<options>\n\t\t<option command="1" order="1" ' \
             'callback="http://localhost/foo" display="False" >' \
             '</option>\n\t</options>\n</request>'
     self.assertEqual(response, correct_response)
开发者ID:BantouTelecom,项目名称:vumi,代码行数:32,代码来源:test_vodacom_messaging.py

示例2: test_inbound_resume_close

 def test_inbound_resume_close(self):
     args = "/?ussdSessionId=123&msisdn=555&provider=web&request=1"
     url = "%s%s?%s" % (
         self.transport_url,
         self.config['web_path'],
         urlencode({
             'ussdSessionId': 123,
             'msisdn': 555,
             'provider': 'web',
             'request': 1,
         })
     )
     d = http_request(url, '', method='GET')
     msg, = yield self.wait_for_dispatched_messages(1)
     payload = msg.payload
     self.assertEqual(payload['transport_name'], self.transport_name)
     self.assertEqual(payload['transport_type'], "ussd")
     self.assertEqual(payload['transport_metadata'],
                      {"session_id": "123"})
     self.assertEqual(payload['session_event'],
                      TransportUserMessage.SESSION_RESUME)
     self.assertEqual(payload['from_addr'], '555')
     self.assertEqual(payload['to_addr'], '')
     self.assertEqual(payload['content'], '1')
     tum = TransportUserMessage(**payload)
     rep = tum.reply("OK", False)
     self.dispatch(rep)
     response = yield d
     correct_response = '<request>\n\t<headertext>OK' + \
                         '</headertext>\n</request>'
     self.assertEqual(response, correct_response)
开发者ID:mangroveorg,项目名称:vumi,代码行数:31,代码来源:test_vodacom_messaging.py

示例3: make_request

    def make_request(self, session_type, session_id, reply=None,
                     continue_session=True, expect_msg=True,
                     defer_response=False, **kw):
        url_suffix = "session/%s/%s" % (session_id, session_type)
        method = self.SESSION_HTTP_METHOD.get(session_type, "POST")
        request_data = self.DEFAULT_SESSION_DATA[session_type].copy()
        request_data.update(kw)
        deferred_req = http_request(self.worker_url + url_suffix,
                                    json.dumps(request_data), method=method)
        if not expect_msg:
            msg = None
        else:
            [msg] = yield self.broker.wait_messages("vumi",
                                                    "test_infobip.inbound",
                                                    1)
            self.broker.clear_messages("vumi", "test_infobip.inbound")
            msg = TransportUserMessage(**msg.payload)
            if reply is not None:
                reply_msg = msg.reply(reply, continue_session=continue_session)
                self.broker.publish_message("vumi", "test_infobip.outbound",
                                         reply_msg)

        if defer_response:
            response = deferred_req
        else:
            response = yield deferred_req
        returnValue((msg, response))
开发者ID:BantouTelecom,项目名称:vumi,代码行数:27,代码来源:test_infobip.py

示例4: test_send_reply_message

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

示例5: test_send_message_storing

    def test_send_message_storing(self):
        """Inbound messages should be stored in the InboundMessageStore"""
        msg = TransportUserMessage.send(to_addr="+1234", content="testcontent")
        yield self.worker.consume_user_message(msg)

        redis = self.worker.redis
        key = "%s:inbound_messages:%s" % (self.worker.config["transport_name"], msg["message_id"])
        msg_json = yield redis.hget(key, "message")
        self.assertEqual(TransportUserMessage.from_json(msg_json), msg)
开发者ID:westerncapelabs,项目名称:junebug,代码行数:9,代码来源:test_workers.py

示例6: test_store_vumi_message

 def test_store_vumi_message(self):
     '''Stores the vumi message.'''
     store = yield self.create_store()
     vumi_msg = TransportUserMessage.send(to_addr='+213', content='foo')
     yield store.store_vumi_message('channel_id', vumi_msg)
     msg = yield self.redis.hget(
         'channel_id:inbound_messages:%s' % vumi_msg.get('message_id'),
         'message')
     self.assertEqual(vumi_msg, TransportUserMessage.from_json(msg))
开发者ID:westerncapelabs,项目名称:junebug,代码行数:9,代码来源:test_stores.py

示例7: test_send_message_storing

    def test_send_message_storing(self):
        '''Inbound messages should be stored in the InboundMessageStore'''
        msg = TransportUserMessage.send(to_addr='+1234', content='testcontent')
        yield self.worker.consume_user_message(msg)

        redis = self.worker.redis
        key = '%s:inbound_messages:%s' % (
            self.worker.config['transport_name'], msg['message_id'])
        msg_json = yield redis.hget(key, 'message')
        self.assertEqual(TransportUserMessage.from_json(msg_json), msg)
开发者ID:BantouTelecom,项目名称:junebug,代码行数:10,代码来源:test_workers.py

示例8: test_inbound

 def test_inbound(self):
     d = http_request(self.worker_url + "foo", '', method='GET')
     msg, = yield self.broker.wait_messages("vumi",
         "test_ok_transport.inbound", 1)
     payload = msg.payload
     tum = TransportUserMessage(**payload)
     rep = tum.reply("OK")
     self.broker.publish_message("vumi", "test_ok_transport.outbound",
             rep)
     response = yield d
     self.assertEqual(response, 'OK')
开发者ID:BantouTelecom,项目名称:vumi,代码行数:11,代码来源:test_httprpc.py

示例9: test_message_sender_send_multiple_messages

    def test_message_sender_send_multiple_messages(self):
        '''The message sender should send all messages to their correct queues
        when send_message is called multiple times'''
        msg1 = TransportUserMessage.send(
            to_addr='+1234', content='test1', transport_name='testtransport')
        yield self.message_sender.send_message(
            msg1, routing_key='testtransport')
        msg2 = TransportUserMessage.send(
            to_addr='+1234', content='test2', transport_name='testtransport')
        yield self.message_sender.send_message(
            msg2, routing_key='testtransport')

        [rec_msg1, rec_msg2] = self.get_dispatched_messages('testtransport')
        self.assertEqual(rec_msg1, msg1)
        self.assertEqual(rec_msg2, msg2)
开发者ID:BantouTelecom,项目名称:junebug,代码行数:15,代码来源:test_amqp.py

示例10: test_sending_messages

    def test_sending_messages(self):
        yield self.get_configured_transport()
        msg = self.tx_helper.make_outbound(
            "outbound", session_event=TransportUserMessage.SESSION_CLOSE)
        d = self.tx_helper.dispatch_outbound(msg)
        req = yield self.get_next_request()
        received_msg = json.loads(req.content.read())
        self.assertEqual(received_msg, {
            'content': msg['content'],
            'in_reply_to': None,
            'to_addr': msg['to_addr'],
            'message_id': msg['message_id'],
            'session_event': TransportUserMessage.SESSION_CLOSE,
            'helper_metadata': {},
        })

        remote_id = TransportUserMessage.generate_id()
        reply = msg.copy()
        reply['message_id'] = remote_id
        req.write(reply.to_json().encode('utf-8'))
        req.finish()
        yield d

        [ack] = yield self.tx_helper.wait_for_dispatched_events(1)
        self.assertEqual(ack['user_message_id'], msg['message_id'])
        self.assertEqual(ack['sent_message_id'], remote_id)
开发者ID:Nagato23,项目名称:vumi,代码行数:26,代码来源:test_vumi_bridge.py

示例11: send_to

 def send_to(self, to_addr, content, tag='default', **kw):
     if tag not in self.SEND_TO_TAGS:
         raise ValueError("Tag %r not defined in SEND_TO_TAGS" % (tag,))
     options = copy.deepcopy(self.send_to_options[tag])
     options.update(kw)
     msg = TransportUserMessage.send(to_addr, content, **options)
     return self._publish_message(msg)
开发者ID:BantouTelecom,项目名称:vumi,代码行数:7,代码来源:base.py

示例12: test_send_to

 def test_send_to(self):
     sent_msg = yield self.worker.send_to('+12345', "Hi!")
     sends = self.recv()
     expecteds = [TransportUserMessage.send('+12345', "Hi!",
             transport_name='default_transport')]
     self.assert_msgs_match(sends, expecteds)
     self.assert_msgs_match(sends, [sent_msg])
开发者ID:BantouTelecom,项目名称:vumi,代码行数:7,代码来源:test_base.py

示例13: test_send_to

 def test_send_to(self):
     sent_msg = yield self.send_to('+12345', "Hi!")
     sends = self.app_helper.get_dispatched_outbound()
     expecteds = [TransportUserMessage.send('+12345', "Hi!",
             transport_name='default_transport')]
     self.assert_msgs_match(sends, expecteds)
     self.assert_msgs_match(sends, [sent_msg])
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:7,代码来源:test_base.py

示例14: send_message

 def send_message(self, sender, outbounds, msg):
     '''Sends a message.'''
     event_url = msg.get('event_url')
     msg = message_from_api(self.id, msg)
     msg = TransportUserMessage.send(**msg)
     msg = yield self._send_message(sender, outbounds, event_url, msg)
     returnValue(api_from_message(msg))
开发者ID:BantouTelecom,项目名称:junebug,代码行数:7,代码来源:channel.py

示例15: load_vumi_message

 def load_vumi_message(self, channel_id, message_id):
     '''Retrieves the stored vumi message, given its unique id'''
     key = self.get_key(channel_id, message_id)
     msg_json = yield self.load_property(key, 'message')
     if msg_json is None:
         returnValue(None)
     returnValue(TransportUserMessage.from_json(msg_json))
开发者ID:BantouTelecom,项目名称:junebug,代码行数:7,代码来源:stores.py


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