예제 #1
0
 def test_send_message(self):
     self.verify_create(self.proxy.send_message,
                        _message.Messages,
                        method_kwargs={
                            'queue': 'qid',
                            'body': 'b1',
                            'attributes': {
                                'p1': 'v1'
                            }
                        },
                        expected_kwargs={
                            'queue_id':
                            'qid',
                            'messages': [{
                                'attributes': {
                                    'p1': 'v1'
                                },
                                'body': 'b1'
                            }],
                            'return_id':
                            True
                        },
                        method_result=_message.Message(id='1'),
                        expected_result=_message.Messages(
                            messages=[_message.Message(id='1')]))
예제 #2
0
 def test_send_messages_msg(self):
     self.verify_create(self.proxy.send_messages,
                        _message.Messages,
                        method_kwargs={
                            'queue':
                            'qid',
                            'messages': [
                                _message.Message(body='b1',
                                                 attributes={
                                                     'attribute1': 'value1',
                                                     'attribute2': 'value2'
                                                 })
                            ]
                        },
                        expected_kwargs={
                            'queue_id':
                            'qid',
                            'messages': [{
                                'body': 'b1',
                                'attributes': {
                                    'attribute1': 'value1',
                                    'attribute2': 'value2'
                                }
                            }],
                            'return_id':
                            False
                        })
예제 #3
0
    def test_basic(self):
        sot = message.Message()

        self.assertEqual('/queues/%(queue_id)s/groups/%(group_id)s/messages',
                         sot.base_path)
        self.assertEqual('message', sot.resource_key)
        self.assertTrue(sot.allow_list)

        self.assertDictEqual(
            {
                'ack_wait': 'ack_wait',
                'limit': 'limit',
                'marker': 'marker',
                'max_msgs': 'max_msgs',
                'time_wait': 'time_wait'
            }, sot._query_mapping._mapping)
예제 #4
0
    def send_message(self, queue, return_id=True, body=None, **attrs):
        """Send single message into a given queue

        :param queue: The queue id or an instance of
            :class:`~otcextensions.sdk.dms.v1.queue.Queue`
        :param bool return_id: Whether response should contain message id
        :param body: A str/json object representing message body
        :param dict attr: Additional message attributes
        :returns: Messages holder instance
            :class:`otcextensions.sdk.dms.v1.message.Message`
        """
        queue_obj = self._get_resource(_queue.Queue, queue)
        msg = _message.Message(body=body, **attrs)

        return self._create(
            _message.Messages,
            base_path='/queues/%(queue_id)s/messages',
            queue_id=queue_obj.id,
            messages=[msg.to_dict(computed=False, ignore_none=True)],
            return_id=return_id).messages[0]
예제 #5
0
    def send_messages(self, queue, messages, return_id=False, **kwargs):
        """Send messages for a given queue

        :param queue: The queue id or an instance of
            :class:`~otcextensions.sdk.dms.v1.queue.Queue`
        :param list messages: A list of message dictionaries
        :returns: Messages holder instance
            :class:`otcextensions.sdk.dms.v1.message.Messages`
        """
        queue_obj = self._get_resource(_queue.Queue, queue)
        messages_list = list()
        for msg in messages:
            if not isinstance(msg, _message.Message):
                obj = _message.Message(**msg)
            else:
                obj = msg
            messages_list.append(obj.to_dict(computed=False, ignore_none=True))

        return self._create(_message.Messages,
                            base_path='/queues/%(queue_id)s/messages',
                            queue_id=queue_obj.id,
                            messages=messages_list,
                            return_id=return_id)
 def test_send_message(self):
     value = _message.Message(id='1')
     self._verify('openstack.proxy.Proxy._create',
                  self.proxy.send_message,
                  method_kwargs={
                      'queue': 'qid',
                      'body': 'b1',
                      'attributes': {
                          'p1': 'v1'
                      }
                  },
                  expected_kwargs={
                      'queue_id': 'qid',
                      'messages': [{
                          'attributes': {
                              'p1': 'v1'
                          },
                          'body': 'b1'
                      }],
                      'return_id': True
                  },
                  method_result=value,
                  expected_result=_message.Messages(messages=[value]),
                  expected_args=[_message.Messages])
예제 #7
0
    def test_make_it(self):

        sot = message.Message()
        self.assertIsNone(sot.queue_id)