Commit 7fa5c263 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Unittest kamaki.clients.RequestManager

parent c2b5da2f
......@@ -125,11 +125,11 @@ class RequestManager(object):
url += '' if url.endswith('/') else '/'
if path:
url += _encode(path[1:] if path.startswith('/') else path)
for i, (key, val) in enumerate(params.items()):
delim = '?'
for key, val in params.items():
val = _encode(val)
url += '%s%s' % ('&' if i else '?', key)
if val:
url += '=%s' % val
url += '%s%s%s' % (delim, key, ('=%s' % val) if val else '')
delim = '&'
parsed = urlparse(url)
self.url = url
self.path = parsed.path or '/'
......@@ -144,7 +144,7 @@ class RequestManager(object):
assert method in HTTP_METHODS, 'Invalid http method %s' % method
if headers:
assert isinstance(headers, dict)
self.headers = dict(headers)
self.headers = dict(headers)
self.method, self.data = method, data
self.scheme, self.netloc = self._connection_info(url, path, params)
......
......@@ -38,11 +38,6 @@ from inspect import getmembers, isclass
from itertools import product
from random import randint
from kamaki.clients.connection.test import (
KamakiConnection,
KamakiHTTPConnection,
KamakiResponse,
KamakiHTTPResponse)
from kamaki.clients.utils.test import Utils
from kamaki.clients.astakos.test import AstakosClient
from kamaki.clients.compute.test import ComputeClient, ComputeRestClient
......@@ -97,6 +92,36 @@ class ClientError(TestCase):
self.assertEqual(exp_details, ce.details)
class RequestManager(TestCase):
def setUp(self):
from kamaki.clients import RequestManager
self.RM = RequestManager
def test___init__(self):
from kamaki.clients import HTTP_METHODS
method_values = HTTP_METHODS + [v.lower() for v in HTTP_METHODS]
for args in product(
tuple(method_values),
('http://www.example.com', 'https://example.com', ''),
('/some/path', '/' ''),
('Some data', '', None),
(dict(k1='v1', k2='v2'), dict()),
(dict(k='v', k2=None, k3='v3'), dict(k=0), dict(k='v'), {})):
req = self.RM(*args)
method, url, path, data, headers, params = args
self.assertEqual(req.method, method.upper())
for i, (k, v) in enumerate(params.items()):
path += '%s%s%s' % (
'&' if '?' in path or i else '?',
k,
('=%s' % v) if v else '')
self.assertEqual(req.path, path)
self.assertEqual(req.data, data)
self.assertEqual(req.headers, headers)
self.assertRaises(AssertionError, self.RM, 'GOT', '', '', '', {}, {})
class SilentEvent(TestCase):
def thread_content(self, methodid, raiseException=0):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment