Files
python-zaqarclient/tests/unit/transport/test_request.py
Flavio Percoco 9d917b7db1 Add prepare_request function to requests.py
This function is supposed to be called to prepare a request that will be
used later by other parts of this client.

Future patches will more clearly show how this function is meant to be
used.

Implements blueprint python-marconiclient-v1

Change-Id: I08b35996119c4e12c31e3113771390b2ec58dfd3
2013-10-02 21:34:32 +02:00

62 lines
2.3 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.
import json
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())
def test_prepare_request(self):
req = request.prepare_request(self.conf)
self.assertTrue(isinstance(req, request.Request))
self.assertIsNone(req.content)
def test_prepare_request_with_data(self):
data = {"data": "tons of GBs"}
req = request.prepare_request(self.conf, data)
self.assertTrue(isinstance(req, request.Request))
self.assertEquals(req.content, json.dumps(data))