Example #1
0
 def mkmsg_dialogueworker_control(self,
                                  action,
                                  dialogue_obj_id=None,
                                  phone_number=None):
     return Message(action=action,
                    dialogue_obj_id=dialogue_obj_id,
                    phone_number=phone_number)
Example #2
0
 def test_validate(self):
     f = VumiMessage(Message)
     msg = Message()
     f.validate(msg)
     self.assertRaises(ValidationError, f.validate,
                       u'this is not a vumi message')
     self.assertRaises(ValidationError, f.validate, None)
Example #3
0
 def test_callback_on_disconnect(self):
     req = yield self.mock_server.queue.get()
     req.write('%s\n' % (Message(foo='bar').to_json().encode('utf-8'), ))
     req.finish()
     message = yield self.messages_received.get()
     self.assertEqual(message['foo'], 'bar')
     reason = yield self.disconnects_received.get()
     # this is the error message we get when a ResponseDone is raised
     # which happens when the remote server closes the connection.
     self.assertEqual(reason, 'Response body fully received')
Example #4
0
 def test_message_cache(self):
     msg = Message(a=5)
     self.assertEqual(msg.cache, {})
     msg.cache["thing"] = "dont_store_me"
     self.assertEqual(msg.cache, {
         "thing": "dont_store_me",
     })
     self.assertEqual(msg[Message._CACHE_ATTRIBUTE], {
         "thing": "dont_store_me",
     })
Example #5
0
 def mkmsg_multiworker_control(self,
                               message_type='add_worker',
                               worker_name='m4h',
                               worker_class=None,
                               config=None):
     if config == None:
         config = []
     return Message(message_type=message_type,
                    worker_name=worker_name,
                    worker_class=worker_class,
                    config=config)
Example #6
0
    def test_start_publisher(self):
        """The publisher should publish"""
        worker = get_stubbed_worker(Worker)
        publisher = yield worker.publish_to('test.routing.key')
        self.assertEquals(publisher.routing_key, 'test.routing.key')
        publisher.publish_message(Message(key="value"))
        [published_msg] = publisher.channel.broker.get_dispatched(
            'vumi', 'test.routing.key')

        self.assertEquals(published_msg.body, '{"key": "value"}')
        self.assertEquals(published_msg.properties, {'delivery mode': 2})
Example #7
0
    def test_consume(self):
        """The consume helper should direct all incoming messages matching the
        specified routing_key, queue_name & exchange to the given callback"""

        message = fake_amq_message({"key": "value"})
        worker = get_stubbed_worker(Worker)

        # buffer to check messages consumed
        log = [Message.from_json(message.content.body)]
        # consume all messages on the given routing key and append
        # them to the log
        worker.consume('test.routing.key', lambda msg: log.append(msg))
        # if all works well then the consume method should funnel the test
        # message straight to the callback, the callback will apend it to the
        # log and we can test it.
        worker._amqp_client.broker.basic_publish('vumi', 'test.routing.key',
                                                 message.content)
        self.assertEquals(log, [Message(key="value")])
Example #8
0
    def test_consume(self):
        """The consume helper should direct all incoming messages matching the
        specified routing_key, queue_name & exchange to the given callback"""

        message = fake_amq_message({"key": "value"})
        worker = yield self.worker_helper.get_worker(Worker, {}, start=False)

        # buffer to check messages consumed
        log = []
        # consume all messages on the given routing key and append
        # them to the log
        yield worker.consume('test.routing.key', lambda msg: log.append(msg))
        # if all works well then the consume method should funnel the test
        # message straight to the callback, the callback will apend it to the
        # log and we can test it.
        self.worker_helper.broker.basic_publish('vumi', 'test.routing.key',
                                                message.content)
        yield self.worker_helper.broker.wait_delivery()
        self.assertEquals(log, [Message(key="value")])
Example #9
0
 def test_message_equality(self):
     self.assertEqual(Message(a=5), Message(a=5))
     self.assertNotEqual(Message(a=5), Message(b=5))
     self.assertNotEqual(Message(a=5), Message(a=6))
     self.assertNotEqual(Message(a=5), {'a': 5})
Example #10
0
 def test_message_contains(self):
     self.assertTrue('a' in Message(a=5))
     self.assertFalse('a' in Message(b=5))