def test_get_queue_metadata(self):
        with mock.patch.object(self.transport, 'send',
                               autospec=True) as send_method:
            resp = response.Response(None, '{}')
            send_method.return_value = resp

            req = request.Request()
            core.queue_get_metadata(self.transport, req, 'test')
Example #2
0
    def metadata(self, new_meta=None, force_reload=False):
        """Get metadata and return it

        :param new_meta: A dictionary containing
            an updated metadata object. If present
            the queue metadata will be updated in
            remote server. If the new_meta is empty,
            the metadata object will be cleared.
        :type new_meta: `dict`
        :param force_reload: Whether to ignored the
            cached metadata and reload it from the
            server.
        :type force_reload: `bool`

        :returns: The queue metadata.
        """
        req, trans = self.client._request_and_transport()

        # NOTE(jeffrey4l): Ensure that metadata is cleared when the new_meta
        # is a empty dict.
        if new_meta is not None:
            if req.api.is_supported('queue_set_metadata'):
                core.queue_set_metadata(trans, req, self._name, new_meta)
            else:
                core.queue_create(trans, req, self._name, metadata=new_meta)
            self._metadata = new_meta

        # TODO(flaper87): Cache with timeout
        if self._metadata and not force_reload:
            return self._metadata

        self._metadata = core.queue_get_metadata(trans, req, self._name)
        return self._metadata
Example #3
0
    def metadata(self, new_meta=None, force_reload=False):
        """Get metadata and return it

        :param new_meta: A dictionary containing
            an updated metadata object. If present
            the queue metadata will be updated in
            remote server. If the new_meta is empty,
            the metadata object will be cleared.
        :type new_meta: `dict`
        :param force_reload: Whether to ignored the
            cached metadata and reload it from the
            server.
        :type force_reload: `bool`

        :returns: The queue metadata.
        """
        req, trans = self.client._request_and_transport()

        # NOTE(jeffrey4l): Ensure that metadata is cleared when the new_meta
        # is a empty dict.
        if new_meta is not None:
            if req.api.is_supported('queue_set_metadata'):
                core.queue_set_metadata(trans, req, self._name, new_meta)
            else:
                core.queue_create(trans, req, self._name, metadata=new_meta)
            self._metadata = new_meta

        # TODO(flaper87): Cache with timeout
        if self._metadata and not force_reload:
            return self._metadata

        self._metadata = core.queue_get_metadata(trans, req, self._name)
        return self._metadata
Example #4
0
    def metadata(self, new_meta=None, force_reload=False):
        """Get metadata and return it

        :param new_meta: A dictionary containing
            an updated metadata object. If present
            the queue metadata will be updated in
            remote server. If the new_meta is empty,
            the metadata object will be cleared.
        :type new_meta: `dict`
        :param force_reload: Whether to ignored the
            cached metadata and reload it from the
            server.
        :type force_reload: `bool`

        :returns: The queue metadata.
        """
        req, trans = self.client._request_and_transport()

        # NOTE(jeffrey4l): Ensure that metadata is cleared when the new_meta
        # is an empty dict.
        if new_meta is not None:
            if self.client.api_version == 1.1:
                raise RuntimeError("V1.1 doesn't support to set the queue's "
                                   "metadata. Please use V1.0 or V2.")
            core.queue_set_metadata(trans, req, self._name, new_meta)
            self._metadata = new_meta

        # TODO(flaper87): Cache with timeout
        if self._metadata and not force_reload:
            return self._metadata

        if self.client.api_version >= 1.1:
            self._metadata = core.queue_get(trans, req, self._name)
        else:
            self._metadata = core.queue_get_metadata(trans, req, self._name)
        return self._metadata
Example #5
0
    def metadata(self, new_meta=None, force_reload=False):
        """Get metadata and return it

        :param new_meta: A dictionary containing
            an updated metadata object. If present
            the queue metadata will be updated in
            remote server. If the new_meta is empty,
            the metadata object will be cleared.
        :type new_meta: `dict`
        :param force_reload: Whether to ignored the
            cached metadata and reload it from the
            server.
        :type force_reload: `bool`

        :returns: The queue metadata.
        """
        req, trans = self.client._request_and_transport()

        # NOTE(jeffrey4l): Ensure that metadata is cleared when the new_meta
        # is an empty dict.
        if new_meta is not None:
            if self.client.api_version == 1.1:
                raise RuntimeError("V1.1 doesn't support to set the queue's "
                                   "metadata. Please use V1.0 or V2.")
            core.queue_set_metadata(trans, req, self._name, new_meta)
            self._metadata = new_meta

        # TODO(flaper87): Cache with timeout
        if self._metadata and not force_reload:
            return self._metadata

        if self.client.api_version >= 1.1:
            self._metadata = core.queue_get(trans, req, self._name)
        else:
            self._metadata = core.queue_get_metadata(trans, req, self._name)
        return self._metadata