예제 #1
0
def test_message_info():
    body = bytes(shortuuid.uuid(), "utf-8")

    info = {
        "headers": {
            "foo": b"bar"
        },
        "content_type": "application/json",
        "content_encoding": "text",
        "delivery_mode": DeliveryMode.PERSISTENT.value,
        "priority": 0,
        "correlation_id": "1",
        "reply_to": "test",
        "expiration": 1.5,
        "message_id": shortuuid.uuid(),
        "timestamp": datetime.utcfromtimestamp(int(time.time())),
        "type": "0",
        "user_id": "guest",
        "app_id": "test",
        "body_size": len(body),
    }

    msg = Message(
        body=body,
        headers={"foo": b"bar"},
        content_type="application/json",
        content_encoding="text",
        delivery_mode=DeliveryMode.PERSISTENT,
        priority=0,
        correlation_id=1,
        reply_to="test",
        expiration=1.5,
        message_id=info["message_id"],
        timestamp=info["timestamp"],
        type="0",
        user_id="guest",
        app_id="test",
    )

    assert info == msg.info()
예제 #2
0
    def test_message_info(self):
        body = bytes(shortuuid.uuid(), 'utf-8')

        info = {
            'headers': {
                "foo": "bar"
            },
            'content_type': "application/json",
            'content_encoding': "text",
            'delivery_mode': DeliveryMode.PERSISTENT.value,
            'priority': 0,
            'correlation_id': b'1',
            'reply_to': 'test',
            'expiration': 1.5,
            'message_id': shortuuid.uuid(),
            'timestamp': int(time.time()),
            'type': '0',
            'user_id': 'guest',
            'app_id': 'test',
            'body_size': len(body)
        }

        msg = Message(body=body,
                      headers={'foo': 'bar'},
                      content_type='application/json',
                      content_encoding='text',
                      delivery_mode=DeliveryMode.PERSISTENT,
                      priority=0,
                      correlation_id=1,
                      reply_to='test',
                      expiration=1.5,
                      message_id=info['message_id'],
                      timestamp=info['timestamp'],
                      type='0',
                      user_id='guest',
                      app_id='test')

        self.assertDictEqual(info, msg.info())
예제 #3
0
    def test_send_message(self, mock_motor_client):
        app = AsyncApp('test_app', heartbeat_interval=111)

        app.ampq_exchange_obj = mock.MagicMock()
        app.ampq_exchange_obj.publish = AsyncMock()
        app.ampq_exchange_obj.publish.mock.return_value = pamqp.specification.Basic.Ack(
        )

        msg = {'msg': 'test'}
        _run(app.send_message('test.test', msg))

        _pikamsg = Message(pickle.dumps(msg),
                           delivery_mode=DeliveryMode.PERSISTENT)

        self.assertEqual(
            app.ampq_exchange_obj.publish.mock.call_args[0][0].info(),
            _pikamsg.info())
        self.assertEqual(app.ampq_exchange_obj.publish.mock.call_args[1],
                         {'routing_key': 'test.test'})

        # Delivery error
        app.ampq_exchange_obj.publish.mock.return_value = None
        self.assertRaises(AsyncAppDeliveryError, _run,
                          app.send_message('test.test', msg))