Пример #1
0
 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))
Пример #2
0
 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))
Пример #3
0
 def cb(request):
     self.assertEqual(request.getUser(), 'username')
     self.assertEqual(request.getPassword(), 'password')
     msg = TransportUserMessage.from_json(request.content.read())
     self.assertEqual(msg['message_id'], 'abc')
     self.assertEqual(msg['content'], 'hello world')
     self.assertEqual(msg['from_addr'], '+41791234567')
     return 'OK'
Пример #4
0
 def cb(request):
     self.assertEqual(request.getUser(), "username")
     self.assertEqual(request.getPassword(), "password")
     msg = TransportUserMessage.from_json(request.content.read())
     self.assertEqual(msg["message_id"], "abc")
     self.assertEqual(msg["content"], "hello world")
     self.assertEqual(msg["from_addr"], "+41791234567")
     return "OK"
Пример #5
0
 def cb(request):
     self.assertEqual(request.getUser(), 'username')
     self.assertEqual(request.getPassword(), 'password')
     msg = TransportUserMessage.from_json(request.content.read())
     self.assertEqual(msg['message_id'], 'abc')
     self.assertEqual(msg['content'], 'hello world')
     self.assertEqual(msg['from_addr'], '+41791234567')
     return 'OK'
Пример #6
0
    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)
Пример #7
0
 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))
Пример #8
0
 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))
Пример #9
0
    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)
Пример #10
0
    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)
Пример #11
0
    def test_post_inbound_message(self):
        msg_d = self.app_helper.make_dispatch_inbound(
            'in 1', message_id='1', conv=self.conversation)

        req = yield self.push_calls.get()
        posted_json = req.content.read()
        self.assertEqual(
            req.requestHeaders.getRawHeaders('content-type'),
            ['application/json; charset=utf-8'])
        req.finish()
        msg = yield msg_d

        posted_msg = TransportUserMessage.from_json(posted_json)
        self.assertEqual(posted_msg['message_id'], msg['message_id'])
Пример #12
0
    def test_post_inbound_message(self):
        msg_d = self.app_helper.make_dispatch_inbound('in 1',
                                                      message_id='1',
                                                      conv=self.conversation)

        req = yield self.push_calls.get()
        posted_json = req.content.read()
        self.assertEqual(req.requestHeaders.getRawHeaders('content-type'),
                         ['application/json; charset=utf-8'])
        req.finish()
        msg = yield msg_d

        posted_msg = TransportUserMessage.from_json(posted_json)
        self.assertEqual(posted_msg['message_id'], msg['message_id'])
Пример #13
0
 def _respond_with_pending_messages(self, msginfo, message_id, **kw):
     """Gathers pending messages and sends a response including them."""
     outbound_ids = []
     outbound_messages = []
     account_key = self.key_for_account(msginfo.account_id)
     while True:
         msg_json = yield self.redis.lpop(account_key)
         if msg_json is None:
             break
         msg = TransportUserMessage.from_json(msg_json)
         outbound_ids.append(msg["message_id"])
         outbound_messages.append({"to": msg["to_addr"], "message": msg["content"] or ""})
     yield self._send_response(message_id, messages=outbound_messages, **kw)
     for outbound_id in outbound_ids:
         yield self.publish_ack(user_message_id=outbound_id, sent_message_id=outbound_id)
Пример #14
0
 def _respond_with_pending_messages(self, msginfo, message_id, **kw):
     """Gathers pending messages and sends a response including them."""
     outbound_ids = []
     outbound_messages = []
     account_key = self.key_for_account(msginfo.account_id)
     while True:
         msg_json = yield self.redis.lpop(account_key)
         if msg_json is None:
             break
         msg = TransportUserMessage.from_json(msg_json)
         outbound_ids.append(msg['message_id'])
         outbound_messages.append({'to': msg['to_addr'],
                                   'message': msg['content'] or ''})
     yield self._send_response(message_id, messages=outbound_messages, **kw)
     for outbound_id in outbound_ids:
         yield self.publish_ack(user_message_id=outbound_id,
                                sent_message_id=outbound_id)
Пример #15
0
    def test_post_inbound_message(self):
        # Set the URL so stuff is HTTP Posted instead of streamed.
        self.conversation.config['http_api'].update({
            'push_message_url': self.mock_push_server.url,
        })
        yield self.conversation.save()

        msg_d = self.app_helper.make_dispatch_inbound(
            'in 1', message_id='1', conv=self.conversation)

        req = yield self.push_calls.get()
        posted_json_data = req.content.read()
        req.finish()
        msg = yield msg_d

        posted_msg = TransportUserMessage.from_json(posted_json_data)
        self.assertEqual(posted_msg['message_id'], msg['message_id'])
Пример #16
0
    def assertJSONResultEqual(self, json_blob, messages):
        """
        Asserts that the JSON response we're getting back is the same as
        the list of messages provided.

        There are easier ways to do this by comparing bigger JSON blogs
        but then debugging the huge strings would be a pain.
        """
        dictionaries = json.loads(json_blob)
        self.assertEqual(len(dictionaries), len(messages),
                         'Unequal amount of dictionaries and messages')
        for dictionary, message in zip(dictionaries, messages):
            # The json dumping & reloading happening here is required to have
            # the timestamp fields be parsed properly. This is an unfortunate
            # side effect of how how timestamps are currently stored as
            # datetime() instances in the payload instead of plain strings.
            self.assertEqual(
                TransportUserMessage(_process_fields=False, **message.payload),
                TransportUserMessage.from_json(json.dumps(dictionary)))
Пример #17
0
    def assertJSONResultEqual(self, json_blob, messages):
        """
        Asserts that the JSON response we're getting back is the same as
        the list of messages provided.

        There are easier ways to do this by comparing bigger JSON blogs
        but then debugging the huge strings would be a pain.
        """
        dictionaries = json.loads(json_blob)
        self.assertEqual(len(dictionaries), len(messages),
            'Unequal amount of dictionaries and messages')
        for dictionary, message in zip(dictionaries, messages):
            # The json dumping & reloading happening here is required to have
            # the timestamp fields be parsed properly. This is an unfortunate
            # side effect of how how timestamps are currently stored as
            # datetime() instances in the payload instead of plain strings.
            self.assertEqual(
                TransportUserMessage(_process_fields=False, **message.payload),
                TransportUserMessage.from_json(json.dumps(dictionary)))
Пример #18
0
    def test_post_inbound_message(self):
        # Set the URL so stuff is HTTP Posted instead of streamed.
        self.conversation.config['http_api'].update({
            'push_message_url':
            self.mock_push_server.url,
        })
        yield self.conversation.save()

        msg_d = self.app_helper.make_dispatch_inbound('in 1',
                                                      message_id='1',
                                                      conv=self.conversation)

        req = yield self.push_calls.get()
        posted_json_data = req.content.read()
        req.finish()
        msg = yield msg_d

        posted_msg = TransportUserMessage.from_json(posted_json_data)
        self.assertEqual(posted_msg['message_id'], msg['message_id'])
Пример #19
0
    def send_outbound(self, phone):
        queue_key = self.r_key(self.redis_outbound_queue)
        sent_messages = []
        while self.r_server.llen(queue_key):
            json_data = self.r_server.lpop(queue_key)
            message = TransportUserMessage.from_json(json_data)
            log.msg('Sending SMS to %s' % (message['to_addr'],))

            # keep track of which Gammu messages were sent out for
            # what Vumi message
            gammu_messages = {}
            try:
                for gammu_message in self.construct_gammu_messages(message):
                    overrides = {
                        'Number': message['to_addr'],
                        # Send using the Phone's known SMSC
                        'SMSC': {
                            'Location': 1
                        },
                        # this will create submit message with request
                        # for delivery report
                        'Type': 'Status_Report',
                    }
                    gammu_message.update(overrides)

                    # keep the message reference for delivery reports
                    send_sms_response = yield deferToThread(phone.SendSMS,
                                                            gammu_message)
                    gammu_messages[send_sms_response] = gammu_message

                    # multiparts result in multiple acks
                    yield self.publish_ack(
                        user_message_id=message['message_id'],
                        sent_message_id=send_sms_response)

                # collect for audit trail
                sent_messages.append((message, gammu_messages))
            except gammu.GSMError, e:
                failure = Failure(e)
                self.send_failure(message, failure.value,
                    failure.getTraceback())
Пример #20
0
 def cb(request):
     msg = TransportUserMessage.from_json(request.content.read())
     self.assertEqual(msg['content'], 'hello world')
     self.assertEqual(msg['from_addr'], '+41791234567')
     return 'OK'
Пример #21
0
 def _load_message(self, message_id):
     d = self.redis.get(self._msg_key(message_id))
     d.addCallback(lambda r: r and TransportUserMessage.from_json(r))
     return d
Пример #22
0
 def cb(request):
     msg = TransportUserMessage.from_json(request.content.read())
     self.assertEqual(msg["content"], u"h\xc6llo")
     return "OK"
Пример #23
0
 def get_cached_message(self, message_id):
     d = self.redis.get(message_key(message_id))
     d.addCallback(lambda json_data: (
         TransportUserMessage.from_json(json_data)
         if json_data else None))
     return d
Пример #24
0
 def cb(request):
     msg = TransportUserMessage.from_json(request.content.read())
     self.assertEqual(msg['content'], u'h\xc6llo')
     return 'OK'
Пример #25
0
 def cb(request):
     msg = TransportUserMessage.from_json(request.content.read())
     self.assertEqual(msg['content'], 'hello world')
     self.assertEqual(msg['from_addr'], '+41791234567')
     return 'OK'
Пример #26
0
 def cb(request):
     msg = TransportUserMessage.from_json(request.content.read())
     self.assertEqual(msg['content'], u'h\xc6llo')
     return 'OK'
Пример #27
0
 def get_cached_message(self, message_id):
     d = self.redis.get(message_key(message_id))
     d.addCallback(lambda json_data: (
         TransportUserMessage.from_json(json_data)
         if json_data else None))
     return d
Пример #28
0
 def cb(request):
     msg = TransportUserMessage.from_json(request.content.read())
     self.assertEqual(msg["content"], "hello world")
     self.assertEqual(msg["from_addr"], "+41791234567")
     return "OK"