summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGary Kotton <gkotton@redhat.com>2012-06-17 04:05:37 -0400
committerGary Kotton <gkotton@redhat.com>2012-06-18 01:15:09 -0400
commit9f938720f158889252fa1db44be96745fa48e1ff (patch)
tree5383ca2084fc6e188c59bef6224c78b2719a5ed9 /tests
parent925edb3ee8bbd97afaa43b2888ab45d2bca50faf (diff)
downloadoslo-9f938720f158889252fa1db44be96745fa48e1ff.tar.gz
oslo-9f938720f158889252fa1db44be96745fa48e1ff.tar.xz
oslo-9f938720f158889252fa1db44be96745fa48e1ff.zip
Update common code to support pep 1.3.
bug 1014216 Change-Id: I3f8fa2e11c9d3f3d34fb20f65ce886bb9c94463d
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/extensions/foxinsocks.py6
-rw-r--r--tests/unit/rpc/common.py46
-rw-r--r--tests/unit/rpc/test_dispatcher.py20
-rw-r--r--tests/unit/rpc/test_kombu.py68
-rw-r--r--tests/unit/rpc/test_proxy.py9
-rw-r--r--tests/unit/rpc/test_qpid.py62
-rw-r--r--tests/unit/rpc/test_zmq.py17
-rw-r--r--tests/unit/test_cfg.py43
-rw-r--r--tests/unit/test_config.py2
-rw-r--r--tests/unit/test_extensions.py106
-rw-r--r--tests/unit/test_policy.py17
-rw-r--r--tests/unit/test_setup.py6
-rw-r--r--tests/unit/test_wsgi.py7
13 files changed, 219 insertions, 190 deletions
diff --git a/tests/unit/extensions/foxinsocks.py b/tests/unit/extensions/foxinsocks.py
index 50c6afa..2291a9f 100644
--- a/tests/unit/extensions/foxinsocks.py
+++ b/tests/unit/extensions/foxinsocks.py
@@ -49,7 +49,7 @@ class Foxinsocks(object):
def get_resources(self):
resources = []
resource = extensions.ResourceExtension('foxnsocks',
- FoxInSocksController())
+ FoxInSocksController())
resources.append(resource)
return resources
@@ -73,7 +73,7 @@ class Foxinsocks(object):
return res
req_ext1 = extensions.RequestExtension('GET', '/dummy_resources/:(id)',
- _goose_handler)
+ _goose_handler)
request_exts.append(req_ext1)
def _bands_handler(req, res):
@@ -85,7 +85,7 @@ class Foxinsocks(object):
return res
req_ext2 = extensions.RequestExtension('GET', '/dummy_resources/:(id)',
- _bands_handler)
+ _bands_handler)
request_exts.append(req_ext2)
return request_exts
diff --git a/tests/unit/rpc/common.py b/tests/unit/rpc/common.py
index 013418d..3497688 100644
--- a/tests/unit/rpc/common.py
+++ b/tests/unit/rpc/common.py
@@ -80,8 +80,8 @@ class BaseRpcTestCase(unittest.TestCase):
value = 42
result = self.rpc.call(FLAGS, self.context, self.topic,
- {"method": "echo_three_times_yield",
- "args": {"value": value}})
+ {"method": "echo_three_times_yield",
+ "args": {"value": value}})
self.assertEqual(value + 2, result)
def test_multicall_succeed_once(self):
@@ -90,9 +90,9 @@ class BaseRpcTestCase(unittest.TestCase):
value = 42
result = self.rpc.multicall(FLAGS, self.context,
- self.topic,
- {"method": "echo",
- "args": {"value": value}})
+ self.topic,
+ {"method": "echo",
+ "args": {"value": value}})
for i, x in enumerate(result):
if i > 0:
self.fail('should only receive one response')
@@ -104,9 +104,9 @@ class BaseRpcTestCase(unittest.TestCase):
value = 42
result = self.rpc.multicall(FLAGS, self.context,
- self.topic,
- {"method": "multicall_three_nones",
- "args": {"value": value}})
+ self.topic,
+ {"method": "multicall_three_nones",
+ "args": {"value": value}})
for i, x in enumerate(result):
self.assertEqual(x, None)
# i should have been 0, 1, and finally 2:
@@ -118,9 +118,9 @@ class BaseRpcTestCase(unittest.TestCase):
value = 42
result = self.rpc.multicall(FLAGS, self.context,
- self.topic,
- {"method": "echo_three_times_yield",
- "args": {"value": value}})
+ self.topic,
+ {"method": "echo_three_times_yield",
+ "args": {"value": value}})
for i, x in enumerate(result):
self.assertEqual(value + i, x)
@@ -131,8 +131,8 @@ class BaseRpcTestCase(unittest.TestCase):
"""Makes sure a context is passed through rpc call."""
value = 42
result = self.rpc.call(FLAGS, self.context,
- self.topic, {"method": "context",
- "args": {"value": value}})
+ self.topic, {"method": "context",
+ "args": {"value": value}})
self.assertEqual(self.context.to_dict(), result)
def _test_cast(self, fanout=False):
@@ -189,14 +189,14 @@ class BaseRpcTestCase(unittest.TestCase):
def echo(context, queue, value):
"""Calls echo in the passed queue."""
LOG.debug(_("Nested received %(queue)s, %(value)s")
- % locals())
+ % locals())
# TODO(comstud):
# so, it will replay the context and use the same REQID?
# that's bizarre.
ret = self.rpc.call(FLAGS, context,
- queue,
- {"method": "echo",
- "args": {"value": value}})
+ queue,
+ {"method": "echo",
+ "args": {"value": value}})
LOG.debug(_("Nested return %s"), ret)
return value
@@ -228,10 +228,10 @@ class BaseRpcTestCase(unittest.TestCase):
"args": {"value": value}}, timeout=1)
try:
self.rpc.call(FLAGS, self.context,
- self.topic,
- {"method": "block",
- "args": {"value": value}},
- timeout=1)
+ self.topic,
+ {"method": "block",
+ "args": {"value": value}},
+ timeout=1)
self.fail("should have thrown Timeout")
except rpc_common.Timeout as exc:
pass
@@ -272,8 +272,8 @@ class BaseRpcAMQPTestCase(BaseRpcTestCase):
value = 42
result = self.rpc.call(FLAGS, self.context, self.topic,
- {"method": "echo",
- "args": {"value": value}})
+ {"method": "echo",
+ "args": {"value": value}})
self.assertEqual(value, result)
diff --git a/tests/unit/rpc/test_dispatcher.py b/tests/unit/rpc/test_dispatcher.py
index a085567..681ff76 100644
--- a/tests/unit/rpc/test_dispatcher.py
+++ b/tests/unit/rpc/test_dispatcher.py
@@ -87,18 +87,22 @@ class RpcDispatcherTestCase(unittest.TestCase):
self._test_dispatch('3.1', (None, None, self.ctxt, 1))
def test_dispatch_higher_minor_version(self):
- self.assertRaises(rpc_common.UnsupportedRpcVersion,
- self._test_dispatch, '2.6', (None, None, None, None))
- self.assertRaises(rpc_common.UnsupportedRpcVersion,
- self._test_dispatch, '3.6', (None, None, None, None))
+ self.assertRaises(
+ rpc_common.UnsupportedRpcVersion,
+ self._test_dispatch, '2.6', (None, None, None, None))
+ self.assertRaises(
+ rpc_common.UnsupportedRpcVersion,
+ self._test_dispatch, '3.6', (None, None, None, None))
def test_dispatch_lower_major_version(self):
- self.assertRaises(rpc_common.UnsupportedRpcVersion,
- self._test_dispatch, '1.0', (None, None, None, None))
+ self.assertRaises(
+ rpc_common.UnsupportedRpcVersion,
+ self._test_dispatch, '1.0', (None, None, None, None))
def test_dispatch_higher_major_version(self):
- self.assertRaises(rpc_common.UnsupportedRpcVersion,
- self._test_dispatch, '4.0', (None, None, None, None))
+ self.assertRaises(
+ rpc_common.UnsupportedRpcVersion,
+ self._test_dispatch, '4.0', (None, None, None, None))
def test_dispatch_no_version_uses_v1(self):
v1 = self.API1()
diff --git a/tests/unit/rpc/test_kombu.py b/tests/unit/rpc/test_kombu.py
index ccab4a2..e280e1e 100644
--- a/tests/unit/rpc/test_kombu.py
+++ b/tests/unit/rpc/test_kombu.py
@@ -51,7 +51,7 @@ class MyException(Exception):
def _raise_exc_stub(stubs, times, obj, method, exc_msg,
- exc_class=MyException):
+ exc_class=MyException):
info = {'called': 0}
orig_method = getattr(obj, method)
@@ -166,13 +166,14 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
class MyConnection(impl_kombu.Connection):
def __init__(myself, *args, **kwargs):
super(MyConnection, myself).__init__(*args, **kwargs)
- self.assertEqual(myself.params,
- {'hostname': FLAGS.rabbit_host,
- 'userid': FLAGS.rabbit_userid,
- 'password': FLAGS.rabbit_password,
- 'port': FLAGS.rabbit_port,
- 'virtual_host': FLAGS.rabbit_virtual_host,
- 'transport': 'memory'})
+ self.assertEqual(
+ myself.params,
+ {'hostname': FLAGS.rabbit_host,
+ 'userid': FLAGS.rabbit_userid,
+ 'password': FLAGS.rabbit_password,
+ 'port': FLAGS.rabbit_port,
+ 'virtual_host': FLAGS.rabbit_virtual_host,
+ 'transport': 'memory'})
def topic_send(_context, topic, msg):
pass
@@ -198,13 +199,14 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
class MyConnection(impl_kombu.Connection):
def __init__(myself, *args, **kwargs):
super(MyConnection, myself).__init__(*args, **kwargs)
- self.assertEqual(myself.params,
- {'hostname': server_params['hostname'],
- 'userid': server_params['username'],
- 'password': server_params['password'],
- 'port': server_params['port'],
- 'virtual_host': server_params['virtual_host'],
- 'transport': 'memory'})
+ self.assertEqual(
+ myself.params,
+ {'hostname': server_params['hostname'],
+ 'userid': server_params['username'],
+ 'password': server_params['password'],
+ 'port': server_params['port'],
+ 'virtual_host': server_params['virtual_host'],
+ 'transport': 'memory'})
def topic_send(_context, topic, msg):
pass
@@ -213,7 +215,7 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
self.stubs.Set(impl_kombu, 'Connection', MyConnection)
impl_kombu.cast_to_server(FLAGS, ctxt, server_params,
- 'fake_topic', {'msg': 'fake'})
+ 'fake_topic', {'msg': 'fake'})
@testutils.skip_test("kombu memory transport seems buggy with "
"fanout queues as this test passes when "
@@ -248,11 +250,11 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
# Test that any exception with 'timeout' in it causes a
# reconnection
info = _raise_exc_stub(self.stubs, 2, self.rpc.DirectConsumer,
- '__init__', 'foo timeout foo')
+ '__init__', 'foo timeout foo')
conn = self.rpc.Connection(FLAGS)
result = conn.declare_consumer(self.rpc.DirectConsumer,
- 'test_topic', None)
+ 'test_topic', None)
self.assertEqual(info['called'], 3)
self.assertTrue(isinstance(result, self.rpc.DirectConsumer))
@@ -262,13 +264,13 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
self.stubs.UnsetAll()
info = _raise_exc_stub(self.stubs, 1, self.rpc.DirectConsumer,
- '__init__', 'meow')
+ '__init__', 'meow')
conn = self.rpc.Connection(FLAGS)
conn.connection_errors = (MyException, )
result = conn.declare_consumer(self.rpc.DirectConsumer,
- 'test_topic', None)
+ 'test_topic', None)
self.assertEqual(info['called'], 2)
self.assertTrue(isinstance(result, self.rpc.DirectConsumer))
@@ -277,11 +279,11 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
def test_declare_consumer_ioerrors_will_reconnect(self):
"""Test that an IOError exception causes a reconnection"""
info = _raise_exc_stub(self.stubs, 2, self.rpc.DirectConsumer,
- '__init__', 'Socket closed', exc_class=IOError)
+ '__init__', 'Socket closed', exc_class=IOError)
conn = self.rpc.Connection(FLAGS)
result = conn.declare_consumer(self.rpc.DirectConsumer,
- 'test_topic', None)
+ 'test_topic', None)
self.assertEqual(info['called'], 3)
self.assertTrue(isinstance(result, self.rpc.DirectConsumer))
@@ -292,7 +294,7 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
# reconnection when declaring the publisher class and when
# calling send()
info = _raise_exc_stub(self.stubs, 2, self.rpc.DirectPublisher,
- '__init__', 'foo timeout foo')
+ '__init__', 'foo timeout foo')
conn = self.rpc.Connection(FLAGS)
conn.publisher_send(self.rpc.DirectPublisher, 'test_topic', 'msg')
@@ -301,7 +303,7 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
self.stubs.UnsetAll()
info = _raise_exc_stub(self.stubs, 2, self.rpc.DirectPublisher,
- 'send', 'foo timeout foo')
+ 'send', 'foo timeout foo')
conn = self.rpc.Connection(FLAGS)
conn.publisher_send(self.rpc.DirectPublisher, 'test_topic', 'msg')
@@ -314,7 +316,7 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
self.stubs.UnsetAll()
info = _raise_exc_stub(self.stubs, 1, self.rpc.DirectPublisher,
- '__init__', 'meow')
+ '__init__', 'meow')
conn = self.rpc.Connection(FLAGS)
conn.connection_errors = (MyException, )
@@ -325,7 +327,7 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
self.stubs.UnsetAll()
info = _raise_exc_stub(self.stubs, 1, self.rpc.DirectPublisher,
- 'send', 'meow')
+ 'send', 'meow')
conn = self.rpc.Connection(FLAGS)
conn.connection_errors = (MyException, )
@@ -348,7 +350,7 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
conn.direct_send('a_direct', message)
info = _raise_exc_stub(self.stubs, 1, conn.connection,
- 'drain_events', 'foo timeout foo')
+ 'drain_events', 'foo timeout foo')
conn.consume(limit=1)
conn.close()
@@ -374,9 +376,9 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
"args": {"value": value}})
try:
self.rpc.call(FLAGS, self.context,
- 'test',
- {"method": "fail",
- "args": {"value": value}})
+ 'test',
+ {"method": "fail",
+ "args": {"value": value}})
self.fail("should have thrown Exception")
except NotImplementedError as exc:
self.assertTrue(value in unicode(exc))
@@ -404,9 +406,9 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
"args": {"value": value}})
try:
self.rpc.call(FLAGS, self.context,
- 'test',
- {"method": "fail_converted",
- "args": {"value": value}})
+ 'test',
+ {"method": "fail_converted",
+ "args": {"value": value}})
self.fail("should have thrown Exception")
except exception.ApiError as exc:
self.assertTrue(value in unicode(exc))
diff --git a/tests/unit/rpc/test_proxy.py b/tests/unit/rpc/test_proxy.py
index 1af37c7..393f328 100644
--- a/tests/unit/rpc/test_proxy.py
+++ b/tests/unit/rpc/test_proxy.py
@@ -39,14 +39,14 @@ class RpcProxyTestCase(unittest.TestCase):
super(RpcProxyTestCase, self).tearDown()
def _test_rpc_method(self, rpc_method, has_timeout=False, has_retval=False,
- server_params=None, supports_topic_override=True):
+ server_params=None, supports_topic_override=True):
topic = 'fake_topic'
timeout = 123
rpc_proxy = proxy.RpcProxy(topic, '1.0')
ctxt = context.RequestContext('fake_user', 'fake_project')
msg = {'method': 'fake_method', 'args': {'x': 'y'}}
expected_msg = {'method': 'fake_method', 'args': {'x': 'y'},
- 'version': '1.0'}
+ 'version': '1.0'}
expected_retval = 'hi' if has_retval else None
@@ -120,8 +120,9 @@ class RpcProxyTestCase(unittest.TestCase):
self._test_rpc_method('cast_to_server', server_params={'blah': 1})
def test_fanout_cast_to_server(self):
- self._test_rpc_method('fanout_cast_to_server',
- server_params={'blah': 1}, supports_topic_override=False)
+ self._test_rpc_method(
+ 'fanout_cast_to_server',
+ server_params={'blah': 1}, supports_topic_override=False)
def test_make_msg(self):
self.assertEqual(proxy.RpcProxy.make_msg('test_method', a=1, b=2),
diff --git a/tests/unit/rpc/test_qpid.py b/tests/unit/rpc/test_qpid.py
index a7526c5..52cd5c9 100644
--- a/tests/unit/rpc/test_qpid.py
+++ b/tests/unit/rpc/test_qpid.py
@@ -124,20 +124,22 @@ class RpcQpidTestCase(unittest.TestCase):
self.mock_connection.session().AndReturn(self.mock_session)
if fanout:
# The link name includes a UUID, so match it with a regex.
- expected_address = mox.Regex(r'^impl_qpid_test_fanout ; '
+ expected_address = mox.Regex(
+ r'^impl_qpid_test_fanout ; '
'{"node": {"x-declare": {"auto-delete": true, "durable": '
'false, "type": "fanout"}, "type": "topic"}, "create": '
'"always", "link": {"x-declare": {"auto-delete": true, '
'"exclusive": true, "durable": false}, "durable": true, '
'"name": "impl_qpid_test_fanout_.*"}}$')
else:
- expected_address = ('nova/impl_qpid_test ; {"node": {"x-declare": '
+ expected_address = (
+ 'nova/impl_qpid_test ; {"node": {"x-declare": '
'{"auto-delete": true, "durable": true}, "type": "topic"}, '
'"create": "always", "link": {"x-declare": {"auto-delete": '
'true, "exclusive": false, "durable": false}, "durable": '
'true, "name": "impl_qpid_test"}}')
self.mock_session.receiver(expected_address).AndReturn(
- self.mock_receiver)
+ self.mock_receiver)
self.mock_receiver.capacity = 1
self.mock_connection.close()
@@ -173,7 +175,7 @@ class RpcQpidTestCase(unittest.TestCase):
'true, "exclusive": false, "durable": false}, "durable": '
'true, "name": "impl.qpid.test.workers"}}')
self.mock_session.receiver(expected_address).AndReturn(
- self.mock_receiver)
+ self.mock_receiver)
self.mock_receiver.capacity = 1
self.mock_connection.close()
@@ -196,12 +198,14 @@ class RpcQpidTestCase(unittest.TestCase):
self.mock_connection.session().AndReturn(self.mock_session)
if fanout:
- expected_address = ('impl_qpid_test_fanout ; '
+ expected_address = (
+ 'impl_qpid_test_fanout ; '
'{"node": {"x-declare": {"auto-delete": true, '
'"durable": false, "type": "fanout"}, '
'"type": "topic"}, "create": "always"}')
else:
- expected_address = ('nova/impl_qpid_test ; {"node": {"x-declare": '
+ expected_address = (
+ 'nova/impl_qpid_test ; {"node": {"x-declare": '
'{"auto-delete": true, "durable": false}, "type": "topic"}, '
'"create": "always"}')
self.mock_session.sender(expected_address).AndReturn(self.mock_sender)
@@ -253,12 +257,12 @@ class RpcQpidTestCase(unittest.TestCase):
def __init__(myself, *args, **kwargs):
super(MyConnection, myself).__init__(*args, **kwargs)
self.assertEqual(myself.connection.username,
- server_params['username'])
+ server_params['username'])
self.assertEqual(myself.connection.password,
- server_params['password'])
+ server_params['password'])
self.assertEqual(myself.broker,
- server_params['hostname'] + ':' +
- str(server_params['port']))
+ server_params['hostname'] + ':' +
+ str(server_params['port']))
MyConnection.pool = rpc_amqp.Pool(FLAGS, MyConnection)
self.stubs.Set(impl_qpid, 'Connection', MyConnection)
@@ -290,43 +294,43 @@ class RpcQpidTestCase(unittest.TestCase):
self.mock_connection.opened().AndReturn(False)
self.mock_connection.open()
self.mock_connection.session().AndReturn(self.mock_session)
- rcv_addr = mox.Regex(r'^.*/.* ; {"node": {"x-declare": {"auto-delete":'
- ' true, "durable": true, "type": "direct"}, "type": '
- '"topic"}, "create": "always", "link": {"x-declare": '
- '{"auto-delete": true, "exclusive": true, "durable": '
- 'false}, "durable": true, "name": ".*"}}')
+ rcv_addr = mox.Regex(
+ r'^.*/.* ; {"node": {"x-declare": {"auto-delete":'
+ ' true, "durable": true, "type": "direct"}, "type": '
+ '"topic"}, "create": "always", "link": {"x-declare": '
+ '{"auto-delete": true, "exclusive": true, "durable": '
+ 'false}, "durable": true, "name": ".*"}}')
self.mock_session.receiver(rcv_addr).AndReturn(self.mock_receiver)
self.mock_receiver.capacity = 1
- send_addr = ('nova/impl_qpid_test ; {"node": {"x-declare": '
+ send_addr = (
+ 'nova/impl_qpid_test ; {"node": {"x-declare": '
'{"auto-delete": true, "durable": false}, "type": "topic"}, '
'"create": "always"}')
self.mock_session.sender(send_addr).AndReturn(self.mock_sender)
self.mock_sender.send(mox.IgnoreArg())
self.mock_session.next_receiver(timeout=mox.IsA(int)).AndReturn(
- self.mock_receiver)
+ self.mock_receiver)
self.mock_receiver.fetch().AndReturn(qpid.messaging.Message(
- {"result": "foo", "failure": False, "ending": False}))
+ {"result": "foo", "failure": False, "ending": False}))
self.mock_session.acknowledge(mox.IgnoreArg())
if multi:
self.mock_session.next_receiver(timeout=mox.IsA(int)).AndReturn(
- self.mock_receiver)
+ self.mock_receiver)
self.mock_receiver.fetch().AndReturn(
- qpid.messaging.Message(
- {"result": "bar", "failure": False,
- "ending": False}))
+ qpid.messaging.Message({"result": "bar", "failure": False,
+ "ending": False}))
self.mock_session.acknowledge(mox.IgnoreArg())
self.mock_session.next_receiver(timeout=mox.IsA(int)).AndReturn(
- self.mock_receiver)
+ self.mock_receiver)
self.mock_receiver.fetch().AndReturn(
- qpid.messaging.Message(
- {"result": "baz", "failure": False,
- "ending": False}))
+ qpid.messaging.Message({"result": "baz", "failure": False,
+ "ending": False}))
self.mock_session.acknowledge(mox.IgnoreArg())
self.mock_session.next_receiver(timeout=mox.IsA(int)).AndReturn(
- self.mock_receiver)
+ self.mock_receiver)
self.mock_receiver.fetch().AndReturn(qpid.messaging.Message(
- {"failure": False, "ending": True}))
+ {"failure": False, "ending": True}))
self.mock_session.acknowledge(mox.IgnoreArg())
self.mock_session.close()
self.mock_connection.session().AndReturn(self.mock_session)
@@ -342,7 +346,7 @@ class RpcQpidTestCase(unittest.TestCase):
method = impl_qpid.call
res = method(FLAGS, ctx, "impl_qpid_test",
- {"method": "test_method", "args": {}})
+ {"method": "test_method", "args": {}})
if multi:
self.assertEquals(list(res), ["foo", "bar", "baz"])
diff --git a/tests/unit/rpc/test_zmq.py b/tests/unit/rpc/test_zmq.py
index 5c69445..d77850e 100644
--- a/tests/unit/rpc/test_zmq.py
+++ b/tests/unit/rpc/test_zmq.py
@@ -54,7 +54,7 @@ class _RpcZmqBaseTestCase(common.BaseRpcTestCase):
self.rpc = impl_zmq
self.rpc.register_opts(FLAGS)
FLAGS.set_default('rpc_zmq_matchmaker',
- 'mod_matchmaker.MatchMakerLocalhost')
+ 'mod_matchmaker.MatchMakerLocalhost')
# We'll change this if we detect no daemon running.
ipc_dir = FLAGS.rpc_zmq_ipc_dir
@@ -87,17 +87,18 @@ class _RpcZmqBaseTestCase(common.BaseRpcTestCase):
consumption_proxy = impl_zmq.InternalContext(None)
self.reactor.register(consumption_proxy,
- consume_in, zmq.PULL, out_bind=True)
+ consume_in,
+ zmq.PULL,
+ out_bind=True)
self.reactor.consume_in_thread()
except zmq.ZMQError:
assert False, _("Could not create ZeroMQ receiver daemon. "
"Socket may already be in use.")
except OSError:
- assert False, _("Could not create IPC directory %s") % \
- (ipc_dir, )
+ assert False, _("Could not create IPC directory %s") % (ipc_dir, )
finally:
- super(_RpcZmqBaseTestCase, self).setUp(
- topic=topic, topic_nested=topic_nested)
+ super(RpcZmqBaseTestCase, self).setUp(
+ topic=topic, topic_nested=topic_nested)
def tearDown(self):
if not impl_zmq:
@@ -128,5 +129,5 @@ class RpcZmqDirectTopicTestCase(_RpcZmqBaseTestCase):
"""
def setUp(self):
super(RpcZmqDirectTopicTestCase, self).setUp(
- topic='test.localhost',
- topic_nested='nested.localhost')
+ topic='test.localhost',
+ topic_nested='nested.localhost')
diff --git a/tests/unit/test_cfg.py b/tests/unit/test_cfg.py
index 25cf57e..c72c18e 100644
--- a/tests/unit/test_cfg.py
+++ b/tests/unit/test_cfg.py
@@ -296,8 +296,8 @@ class ConfigFileOptsTestCase(BaseTestCase):
self.conf.register_opt(opt_class('newfoo', deprecated_name='oldfoo'))
paths2 = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'newfoo = %s\n' % value)])
+ '[DEFAULT]\n'
+ 'newfoo = %s\n' % value)])
self.conf(['--config-file', paths2[0]])
self.assertTrue(hasattr(self.conf, 'newfoo'))
@@ -306,8 +306,7 @@ class ConfigFileOptsTestCase(BaseTestCase):
def test_conf_file_str_default(self):
self.conf.register_opt(StrOpt('foo', default='bar'))
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n')])
+ paths = self.create_tempfiles([('test', '[DEFAULT]\n')])
self.conf(['--config-file', paths[0]])
@@ -317,9 +316,7 @@ class ConfigFileOptsTestCase(BaseTestCase):
def test_conf_file_str_value(self):
self.conf.register_opt(StrOpt('foo'))
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = bar\n')])
+ paths = self.create_tempfiles([('test', '[DEFAULT]\n''foo = bar\n')])
self.conf(['--config-file', paths[0]])
@@ -577,7 +574,7 @@ class ConfigFileOptsTestCase(BaseTestCase):
def test_conf_file_multistr_values_append_deprecated(self):
self.conf.register_cli_opt(MultiStrOpt('foo',
- deprecated_name='oldfoo'))
+ deprecated_name='oldfoo'))
paths = self.create_tempfiles([('1',
'[DEFAULT]\n'
@@ -713,7 +710,7 @@ class OptGroupsTestCase(BaseTestCase):
def test_arg_group_in_config_file_with_deprecated(self):
self.conf.register_group(OptGroup('blaa'))
self.conf.register_opt(StrOpt('foo', deprecated_name='oldfoo'),
- group='blaa')
+ group='blaa')
paths = self.create_tempfiles([('test',
'[blaa]\n'
@@ -1410,20 +1407,20 @@ class OptDumpingTestCase(BaseTestCase):
self.conf.log_opt_values(logger, 666)
self.assertEquals(logger.logged, [
- "*" * 80,
- "Configuration options gathered from:",
- "command line args: ['--foo', 'this', '--blaa-bar', 'that', "
- "'--blaa-key', 'admin', '--passwd', 'hush']",
- "config files: []",
- "=" * 80,
- "config_dir = None",
- "config_file = []",
- "foo = this",
- "passwd = ****",
- "blaa.bar = that",
- "blaa.key = *****",
- "*" * 80,
- ])
+ "*" * 80,
+ "Configuration options gathered from:",
+ "command line args: ['--foo', 'this', '--blaa-bar', "
+ "'that', '--blaa-key', 'admin', '--passwd', 'hush']",
+ "config files: []",
+ "=" * 80,
+ "config_dir = None",
+ "config_file = []",
+ "foo = this",
+ "passwd = ****",
+ "blaa.bar = that",
+ "blaa.key = *****",
+ "*" * 80,
+ ])
class CommonOptsTestCase(BaseTestCase):
diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py
index 55d24a4..0467213 100644
--- a/tests/unit/test_config.py
+++ b/tests/unit/test_config.py
@@ -86,7 +86,7 @@ class TestConfig(unittest.TestCase):
# Test that an app cannot be configured
with mock.patch('openstack.common.config.find_config_file',
- mock.Mock(return_value=True)):
+ mock.Mock(return_value=True)):
self.assertRaises(RuntimeError, config.load_paste_config,
'fake_app', {}, [])
diff --git a/tests/unit/test_extensions.py b/tests/unit/test_extensions.py
index 166914b..f3c067b 100644
--- a/tests/unit/test_extensions.py
+++ b/tests/unit/test_extensions.py
@@ -65,8 +65,9 @@ class ResourceExtensionTest(unittest.TestCase):
return {'collection': 'value'}
def test_resource_can_be_added_as_extension(self):
- res_ext = extensions.ResourceExtension('tweedles',
- self.ResourceExtensionController())
+ res_ext = extensions.ResourceExtension(
+ 'tweedles',
+ self.ResourceExtensionController())
test_app = setup_extensions_app(SimpleExtensionManager(res_ext))
index_response = test_app.get("/tweedles")
@@ -179,8 +180,9 @@ class ActionExtensionTest(unittest.TestCase):
action_name = 'FOXNSOX:add_tweedle'
action_params = dict(name='Beetle')
req_body = json.dumps({action_name: action_params})
- response = self.extension_app.post('/dummy_resources/1/action',
- req_body, content_type='application/json')
+ response = self.extension_app.post(
+ '/dummy_resources/1/action',
+ req_body, content_type='application/json')
self.assertEqual("Tweedle Beetle Added.", response.json)
@@ -188,8 +190,9 @@ class ActionExtensionTest(unittest.TestCase):
action_name = 'FOXNSOX:delete_tweedle'
action_params = dict(name='Bailey')
req_body = json.dumps({action_name: action_params})
- response = self.extension_app.post("/dummy_resources/1/action",
- req_body, content_type='application/json')
+ response = self.extension_app.post(
+ "/dummy_resources/1/action",
+ req_body, content_type='application/json')
self.assertEqual("Tweedle Bailey Deleted.", response.json)
def test_returns_404_for_non_existant_action(self):
@@ -197,9 +200,10 @@ class ActionExtensionTest(unittest.TestCase):
action_params = dict(name="test")
req_body = json.dumps({non_existant_action: action_params})
- response = self.extension_app.post("/dummy_resources/1/action",
- req_body, content_type='application/json',
- status='*')
+ response = self.extension_app.post(
+ "/dummy_resources/1/action",
+ req_body, content_type='application/json',
+ status='*')
self.assertEqual(404, response.status_int)
@@ -208,8 +212,9 @@ class ActionExtensionTest(unittest.TestCase):
action_params = dict(name='Beetle')
req_body = json.dumps({action_name: action_params})
- response = self.extension_app.post("/asdf/1/action", req_body,
- content_type='application/json', status='*')
+ response = self.extension_app.post(
+ "/asdf/1/action", req_body,
+ content_type='application/json', status='*')
self.assertEqual(404, response.status_int)
@@ -226,7 +231,7 @@ class RequestExtensionTest(unittest.TestCase):
headers={'X-NEW-REQUEST-HEADER': "sox"})
self.assertEqual(response.headers['X-NEW-RESPONSE-HEADER'],
- "response_header_data")
+ "response_header_data")
def test_extend_get_resource_response(self):
def extend_response_data(req, res):
@@ -269,15 +274,17 @@ class RequestExtensionTest(unittest.TestCase):
self.assertEqual(response.json['uneditable'], "original_value")
ext_app = self._setup_app_with_request_handler(_update_handler,
- 'PUT')
- ext_response = ext_app.put("/dummy_resources/1",
- json.dumps({'uneditable': "new_value"}),
- headers={'Content-Type': "application/json"})
+ 'PUT')
+ ext_response = ext_app.put(
+ "/dummy_resources/1",
+ json.dumps({'uneditable': "new_value"}),
+ headers={'Content-Type': "application/json"})
self.assertEqual(ext_response.json['uneditable'], "new_value")
def _setup_app_with_request_handler(self, handler, verb):
- req_ext = extensions.RequestExtension(verb,
- '/dummy_resources/:(id)', handler)
+ req_ext = extensions.RequestExtension(
+ verb,
+ '/dummy_resources/:(id)', handler)
manager = SimpleExtensionManager(None, None, req_ext)
return setup_extensions_app(manager)
@@ -312,7 +319,8 @@ class ExtensionControllerTest(unittest.TestCase):
response = self.test_app.get("/extensions")
foxnsox = response.json["extensions"][0]
- self.assertEqual(foxnsox, {
+ self.assertEqual(
+ foxnsox, {
'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0',
'name': 'Fox In Socks',
'updated': '2011-01-22T13:25:27-06:00',
@@ -326,7 +334,8 @@ class ExtensionControllerTest(unittest.TestCase):
json_response = self.test_app.get("/extensions/FOXNSOX").json
foxnsox = json_response['extension']
- self.assertEqual(foxnsox, {
+ self.assertEqual(
+ foxnsox, {
'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0',
'name': 'Fox In Socks',
'updated': '2011-01-22T13:25:27-06:00',
@@ -352,10 +361,12 @@ class ExtensionControllerTest(unittest.TestCase):
exts = root.findall('{0}extension'.format(NS))
fox_ext = exts[0]
self.assertEqual(fox_ext.get('name'), 'Fox In Socks')
- self.assertEqual(fox_ext.get('namespace'),
+ self.assertEqual(
+ fox_ext.get('namespace'),
'http://www.fox.in.socks/api/ext/pie/v1.0')
self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00')
- self.assertEqual(fox_ext.findtext('{0}description'.format(NS)),
+ self.assertEqual(
+ fox_ext.findtext('{0}description'.format(NS)),
'The Fox In Socks Extension')
def test_get_extension_xml(self):
@@ -367,10 +378,12 @@ class ExtensionControllerTest(unittest.TestCase):
self.assertEqual(root.tag.split('extension')[0], NS)
self.assertEqual(root.get('alias'), 'FOXNSOX')
self.assertEqual(root.get('name'), 'Fox In Socks')
- self.assertEqual(root.get('namespace'),
+ self.assertEqual(
+ root.get('namespace'),
'http://www.fox.in.socks/api/ext/pie/v1.0')
self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00')
- self.assertEqual(root.findtext('{0}description'.format(NS)),
+ self.assertEqual(
+ root.findtext('{0}description'.format(NS)),
'The Fox In Socks Extension')
@@ -399,13 +412,15 @@ class ExtensionsXMLSerializerTest(unittest.TestCase):
def test_serialize_extenstion(self):
serializer = extensions.ExtensionsXMLSerializer()
- data = {'extension': {
- 'name': 'ext1',
- 'namespace': 'http://docs.rack.com/servers/api/ext/pie/v1.0',
- 'alias': 'RS-PIE',
- 'updated': '2011-01-22T13:25:27-06:00',
- 'description': 'Adds the capability to share an image.',
- 'links': [{'rel': 'describedby',
+ data = {
+ 'extension': {
+ 'name': 'ext1',
+ 'namespace': 'http://docs.rack.com/servers/api/ext/pie/v1.0',
+ 'alias': 'RS-PIE',
+ 'updated': '2011-01-22T13:25:27-06:00',
+ 'description': 'Adds the capability to share an image.',
+ 'links': [
+ {'rel': 'describedby',
'type': 'application/pdf',
'href': 'http://docs.rack.com/servers/api/ext/cs.pdf'},
{'rel': 'describedby',
@@ -416,7 +431,7 @@ class ExtensionsXMLSerializerTest(unittest.TestCase):
root = etree.XML(xml)
ext_dict = data['extension']
self.assertEqual(root.findtext('{0}description'.format(NS)),
- ext_dict['description'])
+ ext_dict['description'])
for key in ['name', 'namespace', 'alias', 'updated']:
self.assertEqual(root.get(key), ext_dict[key])
@@ -429,30 +444,31 @@ class ExtensionsXMLSerializerTest(unittest.TestCase):
def test_serialize_extensions(self):
serializer = extensions.ExtensionsXMLSerializer()
- data = {"extensions": [{
+ data = {
+ "extensions": [{
"name": "Public Image Extension",
"namespace": "http://foo.com/api/ext/pie/v1.0",
"alias": "RS-PIE",
"updated": "2011-01-22T13:25:27-06:00",
"description": "Adds the capability to share an image.",
"links": [{"rel": "describedby",
- "type": "application/pdf",
- "type": "application/vnd.sun.wadl+xml",
- "href": "http://foo.com/api/ext/cs-pie.pdf"},
- {"rel": "describedby",
- "type": "application/vnd.sun.wadl+xml",
- "href": "http://foo.com/api/ext/cs-pie.wadl"}]},
+ "type": "application/pdf",
+ "type": "application/vnd.sun.wadl+xml",
+ "href": "http://foo.com/api/ext/cs-pie.pdf"},
+ {"rel": "describedby",
+ "type": "application/vnd.sun.wadl+xml",
+ "href": "http://foo.com/api/ext/cs-pie.wadl"}]},
{"name": "Cloud Block Storage",
"namespace": "http://foo.com/api/ext/cbs/v1.0",
"alias": "RS-CBS",
"updated": "2011-01-12T11:22:33-06:00",
"description": "Allows mounting cloud block storage.",
"links": [{"rel": "describedby",
- "type": "application/pdf",
- "href": "http://foo.com/api/ext/cs-cbs.pdf"},
- {"rel": "describedby",
- "type": "application/vnd.sun.wadl+xml",
- "href": "http://foo.com/api/ext/cs-cbs.wadl"}]}]}
+ "type": "application/pdf",
+ "href": "http://foo.com/api/ext/cs-cbs.pdf"},
+ {"rel": "describedby",
+ "type": "application/vnd.sun.wadl+xml",
+ "href": "http://foo.com/api/ext/cs-cbs.wadl"}]}]}
xml = serializer.serialize(data, 'index')
root = etree.XML(xml)
@@ -534,7 +550,7 @@ class ExtensionDescriptorInterfaceTest(unittest.TestCase):
'get_actions', 'get_request_extensions']
predicate = lambda a: (inspect.ismethod(a) and
- not a.__name__.startswith('_'))
+ not a.__name__.startswith('_'))
for method in inspect.getmembers(extensions.ExtensionDescriptor,
predicate):
self.assertFalse(method[0] not in contract_methods)
diff --git a/tests/unit/test_policy.py b/tests/unit/test_policy.py
index da70820..9471855 100644
--- a/tests/unit/test_policy.py
+++ b/tests/unit/test_policy.py
@@ -131,10 +131,12 @@ class BrainTestCase(unittest.TestCase):
}"""
brain = policy.Brain.load_json(exemplar, "default")
- self.assertEqual(brain.rules, dict(
+ self.assertEqual(
+ brain.rules, dict(
admin_or_owner=[["role:admin"], ["project_id:%(project_id)s"]],
default=[],
- ))
+ )
+ )
self.assertEqual(brain.default_rule, "default")
def test_add_rule(self):
@@ -142,7 +144,8 @@ class BrainTestCase(unittest.TestCase):
brain.add_rule("rule1",
[["role:admin"], ["project_id:%(project_id)s"]])
- self.assertEqual(brain.rules, dict(
+ self.assertEqual(
+ brain.rules, dict(
rule1=[["role:admin"], ["project_id:%(project_id)s"]]))
def test_check_with_badmatch(self):
@@ -384,8 +387,8 @@ class HttpBrainTestCase(unittest.TestCase):
self.assertEqual(result, False)
self.assertEqual(self.url, "//spam.example.org/spam")
self.assertEqual(self.decode_post_data(), dict(
- target=dict(tenant="spam"),
- credentials=dict(roles=["a", "b", "c"])))
+ target=dict(tenant="spam"),
+ credentials=dict(roles=["a", "b", "c"])))
def test_http_true(self):
self.urlopen_result = "True"
@@ -397,5 +400,5 @@ class HttpBrainTestCase(unittest.TestCase):
self.assertEqual(result, True)
self.assertEqual(self.url, "//spam.example.org/spam")
self.assertEqual(self.decode_post_data(), dict(
- target=dict(tenant="spam"),
- credentials=dict(roles=["a", "b", "c"])))
+ target=dict(tenant="spam"),
+ credentials=dict(roles=["a", "b", "c"])))
diff --git a/tests/unit/test_setup.py b/tests/unit/test_setup.py
index fbfaebd..0ea0800 100644
--- a/tests/unit/test_setup.py
+++ b/tests/unit/test_setup.py
@@ -38,19 +38,19 @@ class SetupTest(unittest.TestCase):
with open(self.mailmap, 'w') as mm_fh:
mm_fh.write("Foo Bar <email@foo.com> Foo Bar <email@bar.com>\n")
self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
- parse_mailmap(self.mailmap))
+ parse_mailmap(self.mailmap))
def test_mailmap_with_firstname(self):
with open(self.mailmap, 'w') as mm_fh:
mm_fh.write("Foo <email@foo.com> Foo <email@bar.com>\n")
self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
- parse_mailmap(self.mailmap))
+ parse_mailmap(self.mailmap))
def test_mailmap_with_noname(self):
with open(self.mailmap, 'w') as mm_fh:
mm_fh.write("<email@foo.com> <email@bar.com>\n")
self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
- parse_mailmap(self.mailmap))
+ parse_mailmap(self.mailmap))
def tearDown(self):
if os.path.exists(self.mailmap):
diff --git a/tests/unit/test_wsgi.py b/tests/unit/test_wsgi.py
index 16c5345..94f12b7 100644
--- a/tests/unit/test_wsgi.py
+++ b/tests/unit/test_wsgi.py
@@ -412,8 +412,9 @@ class ResourceTest(unittest.TestCase):
def test_malformed_request_body_throws_bad_request(self):
resource = wsgi.Resource(None)
- request = wsgi.Request.blank("/", body="{mal:formed", method='POST',
- headers={'Content-Type': "application/json"})
+ request = wsgi.Request.blank(
+ "/", body="{mal:formed", method='POST',
+ headers={'Content-Type': "application/json"})
response = resource(request)
self.assertEqual(response.status, '400 Bad Request')
@@ -421,7 +422,7 @@ class ResourceTest(unittest.TestCase):
def test_wrong_content_type_throws_unsupported_media_type_error(self):
resource = wsgi.Resource(None)
request = wsgi.Request.blank("/", body="{some:json}", method='POST',
- headers={'Content-Type': "xxx"})
+ headers={'Content-Type': "xxx"})
response = resource(request)
self.assertEqual(response.status, '415 Unsupported Media Type')