
The idea here is to be declarative i.e. specify *what* is desired. It's up to the respective transport (e.g. http, zmq etc.) to turn a request spec into an appropriate request. The request spec class also performs some basic validation. The assumption is that the Marconi API is stable and known for a given version. The API info for version 1 is thus captured in the code and not read from the home document. Nevertheless I have introduced a separate api_info() function that allows us to source the API info from the home document at a later point. Please note also that the `request.Spec` has a `headers` dict property that can be used by the auth layer to inject auth tokens etc. Change-Id: Ia72bfadcc84e7aba69aa5f32d76dfa0dc1083e0d
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
# Copyright (c) 2013 Rackspace, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from marconiclient.tests import base
|
|
from marconiclient.transport import request
|
|
|
|
|
|
HREF = '/v1/queue/'
|
|
|
|
|
|
class TestRequest(base.TestBase):
|
|
def test_valid_operation(self):
|
|
req = request.Request(endpoint=HREF, operation='create_queue',
|
|
params=dict(queue_name='high_load'))
|
|
self.assertIs(None, req.validate())
|
|
|
|
def test_invalid_operation(self):
|
|
req = request.Request(endpoint=HREF, operation='jump_queue',
|
|
params=dict(name='high_load'))
|
|
self.assertEqual("Invalid operation 'jump_queue'", req.validate())
|
|
|
|
def test_missing_mandatory_param(self):
|
|
req = request.Request(endpoint=HREF, operation='get_message',
|
|
params=dict())
|
|
self.assertEqual("Missing mandatory params: 'message_id, queue_name'",
|
|
req.validate())
|
|
|
|
def test_missing_optional_param(self):
|
|
req = request.Request(endpoint=HREF, operation='delete_message',
|
|
params=dict(queue_name='abc', message_id='1'))
|
|
self.assertIs(None, req.validate())
|
|
|
|
def test_invalid__param(self):
|
|
req = request.Request(endpoint=HREF, operation='delete_queue',
|
|
params=dict(queue_name='xy', WAT='!?'))
|
|
self.assertEqual("Invalid params: 'WAT'", req.validate())
|