Fix parameters of assertEqual are misplaced
Many assertEqual sentences don't follow assertEqual(expected, actual), These misplaces have 2 impacts: 1, giving confusing messages when some tests failed. 2, mislead other developers, new test modules may follow these wrong pattern. This patch fix all of them. Change-Id: Icc6e404dd02fe47b76c7366d31d91c8d8e464f54 Closes-Bug: #1604213
This commit is contained in:
parent
74fa4d096b
commit
9ed95bbdc9
@ -49,10 +49,10 @@ class PikaIncomingMessageTestCase(unittest.TestCase):
|
||||
self._body
|
||||
)
|
||||
|
||||
self.assertEqual(message.ctxt.get("key_context", None),
|
||||
"context_value")
|
||||
self.assertEqual(message.message.get("payload_key", None),
|
||||
"payload_value")
|
||||
self.assertEqual("context_value",
|
||||
message.ctxt.get("key_context", None))
|
||||
self.assertEqual("payload_value",
|
||||
message.message.get("payload_key", None))
|
||||
|
||||
def test_message_acknowledge(self):
|
||||
message = pika_drv_msg.PikaIncomingMessage(
|
||||
@ -129,13 +129,13 @@ class RpcPikaIncomingMessageTestCase(unittest.TestCase):
|
||||
self._body
|
||||
)
|
||||
|
||||
self.assertEqual(message.ctxt.get("key_context", None),
|
||||
"context_value")
|
||||
self.assertEqual(message.msg_id, 123456789)
|
||||
self.assertEqual(message.reply_q, "reply_queue")
|
||||
self.assertEqual("context_value",
|
||||
message.ctxt.get("key_context", None))
|
||||
self.assertEqual(123456789, message.msg_id)
|
||||
self.assertEqual("reply_queue", message.reply_q)
|
||||
|
||||
self.assertEqual(message.message.get("payload_key", None),
|
||||
"payload_value")
|
||||
self.assertEqual("payload_value",
|
||||
message.message.get("payload_key", None))
|
||||
|
||||
def test_cast_message_body_parsing(self):
|
||||
message = pika_drv_msg.RpcPikaIncomingMessage(
|
||||
@ -143,13 +143,13 @@ class RpcPikaIncomingMessageTestCase(unittest.TestCase):
|
||||
self._body
|
||||
)
|
||||
|
||||
self.assertEqual(message.ctxt.get("key_context", None),
|
||||
"context_value")
|
||||
self.assertEqual(message.msg_id, None)
|
||||
self.assertEqual(message.reply_q, None)
|
||||
self.assertEqual("context_value",
|
||||
message.ctxt.get("key_context", None))
|
||||
self.assertEqual(None, message.msg_id)
|
||||
self.assertEqual(None, message.reply_q)
|
||||
|
||||
self.assertEqual(message.message.get("payload_key", None),
|
||||
"payload_value")
|
||||
self.assertEqual("payload_value",
|
||||
message.message.get("payload_key", None))
|
||||
|
||||
@patch(("oslo_messaging._drivers.pika_driver.pika_message."
|
||||
"PikaOutgoingMessage.send"))
|
||||
@ -159,17 +159,17 @@ class RpcPikaIncomingMessageTestCase(unittest.TestCase):
|
||||
self._body
|
||||
)
|
||||
|
||||
self.assertEqual(message.ctxt.get("key_context", None),
|
||||
"context_value")
|
||||
self.assertEqual(message.msg_id, None)
|
||||
self.assertEqual(message.reply_q, None)
|
||||
self.assertEqual("context_value",
|
||||
message.ctxt.get("key_context", None))
|
||||
self.assertEqual(None, message.msg_id)
|
||||
self.assertEqual(None, message.reply_q)
|
||||
|
||||
self.assertEqual(message.message.get("payload_key", None),
|
||||
"payload_value")
|
||||
self.assertEqual("payload_value",
|
||||
message.message.get("payload_key", None))
|
||||
|
||||
message.reply(reply=object())
|
||||
|
||||
self.assertEqual(send_reply_mock.call_count, 0)
|
||||
self.assertEqual(0, send_reply_mock.call_count)
|
||||
|
||||
@patch("oslo_messaging._drivers.pika_driver.pika_message."
|
||||
"RpcReplyPikaOutgoingMessage")
|
||||
@ -185,13 +185,13 @@ class RpcPikaIncomingMessageTestCase(unittest.TestCase):
|
||||
self._body
|
||||
)
|
||||
|
||||
self.assertEqual(message.ctxt.get("key_context", None),
|
||||
"context_value")
|
||||
self.assertEqual(message.msg_id, 123456789)
|
||||
self.assertEqual(message.reply_q, "reply_queue")
|
||||
self.assertEqual("context_value",
|
||||
message.ctxt.get("key_context", None))
|
||||
self.assertEqual(123456789, message.msg_id)
|
||||
self.assertEqual("reply_queue", message.reply_q)
|
||||
|
||||
self.assertEqual(message.message.get("payload_key", None),
|
||||
"payload_value")
|
||||
self.assertEqual("payload_value",
|
||||
message.message.get("payload_key", None))
|
||||
reply = "all_fine"
|
||||
message.reply(reply=reply)
|
||||
|
||||
@ -221,13 +221,13 @@ class RpcPikaIncomingMessageTestCase(unittest.TestCase):
|
||||
self._body
|
||||
)
|
||||
|
||||
self.assertEqual(message.ctxt.get("key_context", None),
|
||||
"context_value")
|
||||
self.assertEqual(message.msg_id, 123456789)
|
||||
self.assertEqual(message.reply_q, "reply_queue")
|
||||
self.assertEqual("context_value",
|
||||
message.ctxt.get("key_context", None))
|
||||
self.assertEqual(123456789, message.msg_id)
|
||||
self.assertEqual("reply_queue", message.reply_q)
|
||||
|
||||
self.assertEqual(message.message.get("payload_key", None),
|
||||
"payload_value")
|
||||
self.assertEqual("payload_value",
|
||||
message.message.get("payload_key", None))
|
||||
|
||||
failure_info = object()
|
||||
message.reply(failure=failure_info)
|
||||
@ -277,9 +277,9 @@ class RpcReplyPikaIncomingMessageTestCase(unittest.TestCase):
|
||||
body
|
||||
)
|
||||
|
||||
self.assertEqual(message.msg_id, 123456789)
|
||||
self.assertEqual(123456789, message.msg_id)
|
||||
self.assertIsNone(message.failure)
|
||||
self.assertEqual(message.result, "all fine")
|
||||
self.assertEqual("all fine", message.result)
|
||||
|
||||
def test_negative_reply_message_body_parsing(self):
|
||||
|
||||
@ -297,12 +297,12 @@ class RpcReplyPikaIncomingMessageTestCase(unittest.TestCase):
|
||||
body
|
||||
)
|
||||
|
||||
self.assertEqual(message.msg_id, 123456789)
|
||||
self.assertEqual(123456789, message.msg_id)
|
||||
self.assertIsNone(message.result)
|
||||
self.assertEqual(
|
||||
str(message.failure),
|
||||
'Error message\n'
|
||||
'TRACE HERE'
|
||||
'TRACE HERE',
|
||||
str(message.failure)
|
||||
)
|
||||
self.assertIsInstance(message.failure,
|
||||
oslo_messaging.MessagingException)
|
||||
@ -359,12 +359,12 @@ class PikaOutgoingMessageTestCase(unittest.TestCase):
|
||||
props = self._pika_engine.connection_with_confirmation_pool.acquire(
|
||||
).__enter__().channel.publish.call_args[1]["properties"]
|
||||
|
||||
self.assertEqual(props.content_encoding, 'utf-8')
|
||||
self.assertEqual(props.content_type, 'application/json')
|
||||
self.assertEqual(props.delivery_mode, 2)
|
||||
self.assertEqual('utf-8', props.content_encoding)
|
||||
self.assertEqual('application/json', props.content_type)
|
||||
self.assertEqual(2, props.delivery_mode)
|
||||
self.assertTrue(self._expiration * 1000 - float(props.expiration) <
|
||||
100)
|
||||
self.assertEqual(props.headers, {'version': '1.0'})
|
||||
self.assertEqual({'version': '1.0'}, props.headers)
|
||||
self.assertTrue(props.message_id)
|
||||
|
||||
@patch("oslo_serialization.jsonutils.dumps",
|
||||
@ -404,12 +404,12 @@ class PikaOutgoingMessageTestCase(unittest.TestCase):
|
||||
props = self._pika_engine.connection_without_confirmation_pool.acquire(
|
||||
).__enter__().channel.publish.call_args[1]["properties"]
|
||||
|
||||
self.assertEqual(props.content_encoding, 'utf-8')
|
||||
self.assertEqual(props.content_type, 'application/json')
|
||||
self.assertEqual(props.delivery_mode, 1)
|
||||
self.assertEqual('utf-8', props.content_encoding)
|
||||
self.assertEqual('application/json', props.content_type)
|
||||
self.assertEqual(1, props.delivery_mode)
|
||||
self.assertTrue(self._expiration * 1000 - float(props.expiration)
|
||||
< 100)
|
||||
self.assertEqual(props.headers, {'version': '1.0'})
|
||||
self.assertEqual({'version': '1.0'}, props.headers)
|
||||
self.assertTrue(props.message_id)
|
||||
|
||||
|
||||
@ -463,11 +463,11 @@ class RpcPikaOutgoingMessageTestCase(unittest.TestCase):
|
||||
props = self._pika_engine.connection_with_confirmation_pool.acquire(
|
||||
).__enter__().channel.publish.call_args[1]["properties"]
|
||||
|
||||
self.assertEqual(props.content_encoding, 'utf-8')
|
||||
self.assertEqual(props.content_type, 'application/json')
|
||||
self.assertEqual(props.delivery_mode, 1)
|
||||
self.assertEqual('utf-8', props.content_encoding)
|
||||
self.assertEqual('application/json', props.content_type)
|
||||
self.assertEqual(1, props.delivery_mode)
|
||||
self.assertTrue(expiration * 1000 - float(props.expiration) < 100)
|
||||
self.assertEqual(props.headers, {'version': '1.0'})
|
||||
self.assertEqual({'version': '1.0'}, props.headers)
|
||||
self.assertIsNone(props.correlation_id)
|
||||
self.assertIsNone(props.reply_to)
|
||||
self.assertTrue(props.message_id)
|
||||
@ -521,13 +521,13 @@ class RpcPikaOutgoingMessageTestCase(unittest.TestCase):
|
||||
props = self._pika_engine.connection_with_confirmation_pool.acquire(
|
||||
).__enter__().channel.publish.call_args[1]["properties"]
|
||||
|
||||
self.assertEqual(props.content_encoding, 'utf-8')
|
||||
self.assertEqual(props.content_type, 'application/json')
|
||||
self.assertEqual(props.delivery_mode, 1)
|
||||
self.assertEqual('utf-8', props.content_encoding)
|
||||
self.assertEqual('application/json', props.content_type)
|
||||
self.assertEqual(1, props.delivery_mode)
|
||||
self.assertTrue(expiration * 1000 - float(props.expiration) < 100)
|
||||
self.assertEqual(props.headers, {'version': '1.0'})
|
||||
self.assertEqual(props.correlation_id, message.msg_id)
|
||||
self.assertEqual(props.reply_to, reply_queue_name)
|
||||
self.assertEqual({'version': '1.0'}, props.headers)
|
||||
self.assertEqual(message.msg_id, props.correlation_id)
|
||||
self.assertEqual(reply_queue_name, props.reply_to)
|
||||
self.assertTrue(props.message_id)
|
||||
|
||||
|
||||
@ -567,13 +567,13 @@ class RpcReplyPikaOutgoingMessageTestCase(unittest.TestCase):
|
||||
props = self._pika_engine.connection_with_confirmation_pool.acquire(
|
||||
).__enter__().channel.publish.call_args[1]["properties"]
|
||||
|
||||
self.assertEqual(props.content_encoding, 'utf-8')
|
||||
self.assertEqual(props.content_type, 'application/json')
|
||||
self.assertEqual(props.delivery_mode, 1)
|
||||
self.assertEqual('utf-8', props.content_encoding)
|
||||
self.assertEqual('application/json', props.content_type)
|
||||
self.assertEqual(1, props.delivery_mode)
|
||||
self.assertTrue(self._expiration * 1000 - float(props.expiration) <
|
||||
100)
|
||||
self.assertEqual(props.headers, {'version': '1.0'})
|
||||
self.assertEqual(props.correlation_id, message.msg_id)
|
||||
self.assertEqual({'version': '1.0'}, props.headers)
|
||||
self.assertEqual(message.msg_id, props.correlation_id)
|
||||
self.assertIsNone(props.reply_to)
|
||||
self.assertTrue(props.message_id)
|
||||
|
||||
@ -612,12 +612,12 @@ class RpcReplyPikaOutgoingMessageTestCase(unittest.TestCase):
|
||||
props = self._pika_engine.connection_with_confirmation_pool.acquire(
|
||||
).__enter__().channel.publish.call_args[1]["properties"]
|
||||
|
||||
self.assertEqual(props.content_encoding, 'utf-8')
|
||||
self.assertEqual(props.content_type, 'application/json')
|
||||
self.assertEqual(props.delivery_mode, 1)
|
||||
self.assertEqual('utf-8', props.content_encoding)
|
||||
self.assertEqual('application/json', props.content_type)
|
||||
self.assertEqual(1, props.delivery_mode)
|
||||
self.assertTrue(self._expiration * 1000 - float(props.expiration) <
|
||||
100)
|
||||
self.assertEqual(props.headers, {'version': '1.0'})
|
||||
self.assertEqual(props.correlation_id, message.msg_id)
|
||||
self.assertEqual({'version': '1.0'}, props.headers)
|
||||
self.assertEqual(message.msg_id, props.correlation_id)
|
||||
self.assertIsNone(props.reply_to)
|
||||
self.assertTrue(props.message_id)
|
||||
|
@ -98,9 +98,9 @@ class PikaPollerTestCase(unittest.TestCase):
|
||||
unused, method, properties, body
|
||||
)
|
||||
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(1, len(res))
|
||||
|
||||
self.assertEqual(res[0], [incoming_message_class_mock.return_value])
|
||||
self.assertEqual([incoming_message_class_mock.return_value], res[0])
|
||||
incoming_message_class_mock.assert_called_once_with(
|
||||
self._pika_engine, self._poller_channel_mock, method, properties,
|
||||
body
|
||||
@ -139,16 +139,16 @@ class PikaPollerTestCase(unittest.TestCase):
|
||||
*params[i]
|
||||
)
|
||||
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(len(res[0]), 10)
|
||||
self.assertEqual(incoming_message_class_mock.call_count, n)
|
||||
self.assertEqual(1, len(res))
|
||||
self.assertEqual(10, len(res[0]))
|
||||
self.assertEqual(n, incoming_message_class_mock.call_count)
|
||||
|
||||
for i in range(n):
|
||||
self.assertEqual(res[0][i],
|
||||
incoming_message_class_mock.return_value)
|
||||
self.assertEqual(incoming_message_class_mock.return_value,
|
||||
res[0][i])
|
||||
self.assertEqual(
|
||||
incoming_message_class_mock.call_args_list[i][0],
|
||||
(self._pika_engine, self._poller_channel_mock) + params[i][1:]
|
||||
(self._pika_engine, self._poller_channel_mock) + params[i][1:],
|
||||
incoming_message_class_mock.call_args_list[i][0]
|
||||
)
|
||||
|
||||
self.assertTrue(self._pika_engine.create_connection.called)
|
||||
@ -193,16 +193,16 @@ class PikaPollerTestCase(unittest.TestCase):
|
||||
|
||||
self.assertTrue(evt.wait(timeout * 2))
|
||||
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(len(res[0]), success_count)
|
||||
self.assertEqual(incoming_message_class_mock.call_count, success_count)
|
||||
self.assertEqual(1, len(res))
|
||||
self.assertEqual(success_count, len(res[0]))
|
||||
self.assertEqual(success_count, incoming_message_class_mock.call_count)
|
||||
|
||||
for i in range(success_count):
|
||||
self.assertEqual(res[0][i],
|
||||
incoming_message_class_mock.return_value)
|
||||
self.assertEqual(incoming_message_class_mock.return_value,
|
||||
res[0][i])
|
||||
self.assertEqual(
|
||||
incoming_message_class_mock.call_args_list[i][0],
|
||||
(self._pika_engine, self._poller_channel_mock) + params[i][1:]
|
||||
(self._pika_engine, self._poller_channel_mock) + params[i][1:],
|
||||
incoming_message_class_mock.call_args_list[i][0]
|
||||
)
|
||||
|
||||
self.assertTrue(self._pika_engine.create_connection.called)
|
||||
@ -255,7 +255,7 @@ class RpcServicePikaPollerTestCase(unittest.TestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
declare_queue_binding_by_channel_mock.call_count, 6
|
||||
6, declare_queue_binding_by_channel_mock.call_count
|
||||
)
|
||||
|
||||
declare_queue_binding_by_channel_mock.assert_has_calls((
|
||||
@ -345,7 +345,7 @@ class RpcReplyServicePikaPollerTestCase(unittest.TestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
declare_queue_binding_by_channel_mock.call_count, 1
|
||||
1, declare_queue_binding_by_channel_mock.call_count
|
||||
)
|
||||
|
||||
declare_queue_binding_by_channel_mock.assert_called_once_with(
|
||||
@ -399,7 +399,7 @@ class NotificationPikaPollerTestCase(unittest.TestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
declare_queue_binding_by_channel_mock.call_count, 3
|
||||
3, declare_queue_binding_by_channel_mock.call_count
|
||||
)
|
||||
|
||||
declare_queue_binding_by_channel_mock.assert_has_calls((
|
||||
@ -448,7 +448,7 @@ class NotificationPikaPollerTestCase(unittest.TestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
declare_queue_binding_by_channel_mock.call_count, 3
|
||||
3, declare_queue_binding_by_channel_mock.call_count
|
||||
)
|
||||
|
||||
declare_queue_binding_by_channel_mock.assert_has_calls((
|
||||
|
@ -144,7 +144,7 @@ class TestAmqpSend(_AmqpBrokerTestCase):
|
||||
self.assertIsNone(rc)
|
||||
listener.join(timeout=30)
|
||||
self.assertFalse(listener.isAlive())
|
||||
self.assertEqual(listener.messages.get().message, {"msg": "value"})
|
||||
self.assertEqual({"msg": "value"}, listener.messages.get().message)
|
||||
driver.cleanup()
|
||||
|
||||
def test_send_exchange_with_reply(self):
|
||||
@ -161,14 +161,14 @@ class TestAmqpSend(_AmqpBrokerTestCase):
|
||||
wait_for_reply=True,
|
||||
timeout=30)
|
||||
self.assertIsNotNone(rc)
|
||||
self.assertEqual(rc.get('correlation-id'), 'e1')
|
||||
self.assertEqual('e1', rc.get('correlation-id'))
|
||||
|
||||
rc = driver.send(target2, {"context": "whatever"},
|
||||
{"method": "echo", "id": "e2"},
|
||||
wait_for_reply=True,
|
||||
timeout=30)
|
||||
self.assertIsNotNone(rc)
|
||||
self.assertEqual(rc.get('correlation-id'), 'e2')
|
||||
self.assertEqual('e2', rc.get('correlation-id'))
|
||||
|
||||
listener1.join(timeout=30)
|
||||
self.assertFalse(listener1.isAlive())
|
||||
@ -193,15 +193,15 @@ class TestAmqpSend(_AmqpBrokerTestCase):
|
||||
driver.send(shared_target, {"context": "whatever"},
|
||||
{"method": "echo", "id": "either-1"},
|
||||
wait_for_reply=True)
|
||||
self.assertEqual(self._broker.topic_count, 1)
|
||||
self.assertEqual(self._broker.direct_count, 1) # reply
|
||||
self.assertEqual(1, self._broker.topic_count)
|
||||
self.assertEqual(1, self._broker.direct_count) # reply
|
||||
|
||||
# this should go to the other server:
|
||||
driver.send(shared_target, {"context": "whatever"},
|
||||
{"method": "echo", "id": "either-2"},
|
||||
wait_for_reply=True)
|
||||
self.assertEqual(self._broker.topic_count, 2)
|
||||
self.assertEqual(self._broker.direct_count, 2) # reply
|
||||
self.assertEqual(2, self._broker.topic_count)
|
||||
self.assertEqual(2, self._broker.direct_count) # reply
|
||||
|
||||
# these should only go to listener1:
|
||||
driver.send(target1, {"context": "whatever"},
|
||||
@ -211,13 +211,13 @@ class TestAmqpSend(_AmqpBrokerTestCase):
|
||||
driver.send(target1, {"context": "whatever"},
|
||||
{"method": "echo", "id": "server1-2"},
|
||||
wait_for_reply=True)
|
||||
self.assertEqual(self._broker.direct_count, 6) # 2X(send+reply)
|
||||
self.assertEqual(6, self._broker.direct_count) # 2X(send+reply)
|
||||
|
||||
# this should only go to listener2:
|
||||
driver.send(target2, {"context": "whatever"},
|
||||
{"method": "echo", "id": "server2"},
|
||||
wait_for_reply=True)
|
||||
self.assertEqual(self._broker.direct_count, 8)
|
||||
self.assertEqual(8, self._broker.direct_count)
|
||||
|
||||
# both listeners should get a copy:
|
||||
driver.send(fanout_target, {"context": "whatever"},
|
||||
@ -227,7 +227,7 @@ class TestAmqpSend(_AmqpBrokerTestCase):
|
||||
self.assertFalse(listener1.isAlive())
|
||||
listener2.join(timeout=30)
|
||||
self.assertFalse(listener2.isAlive())
|
||||
self.assertEqual(self._broker.fanout_count, 1)
|
||||
self.assertEqual(1, self._broker.fanout_count)
|
||||
|
||||
listener1_ids = [x.message.get('id') for x in listener1.get_messages()]
|
||||
listener2_ids = [x.message.get('id') for x in listener2.get_messages()]
|
||||
@ -306,13 +306,13 @@ class TestAmqpNotification(_AmqpBrokerTestCase):
|
||||
listener.join(timeout=30)
|
||||
self.assertFalse(listener.isAlive())
|
||||
topics = [x.message.get('target') for x in listener.get_messages()]
|
||||
self.assertEqual(len(topics), msg_count)
|
||||
self.assertEqual(topics.count('topic-1.info'), 2)
|
||||
self.assertEqual(topics.count('topic-1.error'), 2)
|
||||
self.assertEqual(topics.count('topic-2.debug'), 2)
|
||||
self.assertEqual(self._broker.dropped_count, 4)
|
||||
self.assertEqual(excepted_targets.count('topic-1.bad'), 0)
|
||||
self.assertEqual(excepted_targets.count('bad-topic.debug'), 0)
|
||||
self.assertEqual(msg_count, len(topics))
|
||||
self.assertEqual(2, topics.count('topic-1.info'))
|
||||
self.assertEqual(2, topics.count('topic-1.error'))
|
||||
self.assertEqual(2, topics.count('topic-2.debug'))
|
||||
self.assertEqual(4, self._broker.dropped_count)
|
||||
self.assertEqual(0, excepted_targets.count('topic-1.bad'))
|
||||
self.assertEqual(0, excepted_targets.count('bad-topic.debug'))
|
||||
driver.cleanup()
|
||||
|
||||
|
||||
@ -567,11 +567,11 @@ class TestFailover(test_utils.BaseTestCase):
|
||||
wait_for_reply=True,
|
||||
timeout=30)
|
||||
self.assertIsNotNone(rc)
|
||||
self.assertEqual(rc.get('correlation-id'), 'echo-1')
|
||||
self.assertEqual('echo-1', rc.get('correlation-id'))
|
||||
|
||||
# 1 request msg, 1 response:
|
||||
self.assertEqual(self._brokers[self._primary].topic_count, 1)
|
||||
self.assertEqual(self._brokers[self._primary].direct_count, 1)
|
||||
self.assertEqual(1, self._brokers[self._primary].topic_count)
|
||||
self.assertEqual(1, self._brokers[self._primary].direct_count)
|
||||
|
||||
# invoke failover method
|
||||
fail_broker(self._brokers[self._primary])
|
||||
@ -588,11 +588,11 @@ class TestFailover(test_utils.BaseTestCase):
|
||||
wait_for_reply=True,
|
||||
timeout=2)
|
||||
self.assertIsNotNone(rc)
|
||||
self.assertEqual(rc.get('correlation-id'), 'echo-2')
|
||||
self.assertEqual('echo-2', rc.get('correlation-id'))
|
||||
|
||||
# 1 request msg, 1 response:
|
||||
self.assertEqual(self._brokers[self._backup].topic_count, 1)
|
||||
self.assertEqual(self._brokers[self._backup].direct_count, 1)
|
||||
self.assertEqual(1, self._brokers[self._backup].topic_count)
|
||||
self.assertEqual(1, self._brokers[self._backup].direct_count)
|
||||
|
||||
listener.join(timeout=30)
|
||||
self.assertFalse(listener.isAlive())
|
||||
|
@ -654,7 +654,7 @@ class TestRacyWaitForReply(test_utils.BaseTestCase):
|
||||
# Verify the _send_reply was not invoked by driver:
|
||||
with mock.patch.object(msgs[2], '_send_reply') as method:
|
||||
msgs[2].reply({'rx_id': 2})
|
||||
self.assertEqual(method.call_count, 0)
|
||||
self.assertEqual(0, method.call_count)
|
||||
|
||||
# Wait for the 3rd thread to finish
|
||||
senders[2].join()
|
||||
|
@ -66,8 +66,8 @@ class TestImplMatchmaker(test_utils.BaseTestCase):
|
||||
def test_register(self):
|
||||
self.test_matcher.register(self.target, self.host1, "test")
|
||||
|
||||
self.assertEqual(self.test_matcher.get_hosts(self.target, "test"),
|
||||
[self.host1])
|
||||
self.assertEqual([self.host1],
|
||||
self.test_matcher.get_hosts(self.target, "test"))
|
||||
|
||||
def test_register_two_hosts(self):
|
||||
self.test_matcher.register(self.target, self.host1, "test")
|
||||
@ -89,8 +89,8 @@ class TestImplMatchmaker(test_utils.BaseTestCase):
|
||||
self.test_matcher.register(self.target, self.host1, "test")
|
||||
self.test_matcher.register(self.target, self.host1, "test")
|
||||
|
||||
self.assertEqual(self.test_matcher.get_hosts(self.target, "test"),
|
||||
[self.host1])
|
||||
self.assertEqual([self.host1],
|
||||
self.test_matcher.get_hosts(self.target, "test"))
|
||||
|
||||
def test_get_hosts_wrong_topic(self):
|
||||
target = oslo_messaging.Target(topic="no_such_topic")
|
||||
@ -99,4 +99,4 @@ class TestImplMatchmaker(test_utils.BaseTestCase):
|
||||
hosts = self.test_matcher.get_hosts(target, "test")
|
||||
except (timeout.TimeoutException, retrying.RetryError):
|
||||
pass
|
||||
self.assertEqual(hosts, [])
|
||||
self.assertEqual([], hosts)
|
||||
|
@ -68,12 +68,12 @@ class LoggingNotificationHandlerTestCase(utils.SkipIfNoTransportURL):
|
||||
log_method('Test logging at priority: %s' % self.priority)
|
||||
|
||||
events = listener.get_events(timeout=1)
|
||||
self.assertEqual(len(events), 1)
|
||||
self.assertEqual(1, len(events))
|
||||
|
||||
info_event = events[0]
|
||||
|
||||
self.assertEqual(info_event[0], self.priority)
|
||||
self.assertEqual(info_event[1], 'logrecord')
|
||||
self.assertEqual(self.priority, info_event[0])
|
||||
self.assertEqual('logrecord', info_event[1])
|
||||
|
||||
for key in ['name', 'thread', 'extra', 'process', 'funcName',
|
||||
'levelno', 'processName', 'pathname', 'lineno',
|
||||
|
@ -49,14 +49,14 @@ class NotifierMiddlewareTest(utils.BaseTestCase):
|
||||
m(req)
|
||||
# Check first notification with only 'request'
|
||||
call_args = notify.call_args_list[0][0]
|
||||
self.assertEqual(call_args[1], 'http.request')
|
||||
self.assertEqual(call_args[3], 'INFO')
|
||||
self.assertEqual(set(call_args[2].keys()),
|
||||
set(['request']))
|
||||
self.assertEqual('http.request', call_args[1])
|
||||
self.assertEqual('INFO', call_args[3])
|
||||
self.assertEqual(set(['request']),
|
||||
set(call_args[2].keys()))
|
||||
|
||||
request = call_args[2]['request']
|
||||
self.assertEqual(request['PATH_INFO'], '/foo/bar')
|
||||
self.assertEqual(request['REQUEST_METHOD'], 'GET')
|
||||
self.assertEqual('/foo/bar', request['PATH_INFO'])
|
||||
self.assertEqual('GET', request['REQUEST_METHOD'])
|
||||
self.assertIn('HTTP_X_SERVICE_NAME', request)
|
||||
self.assertNotIn('HTTP_X_AUTH_TOKEN', request)
|
||||
self.assertFalse(any(map(lambda s: s.startswith('wsgi.'),
|
||||
@ -65,14 +65,14 @@ class NotifierMiddlewareTest(utils.BaseTestCase):
|
||||
|
||||
# Check second notification with request + response
|
||||
call_args = notify.call_args_list[1][0]
|
||||
self.assertEqual(call_args[1], 'http.response')
|
||||
self.assertEqual(call_args[3], 'INFO')
|
||||
self.assertEqual(set(call_args[2].keys()),
|
||||
set(['request', 'response']))
|
||||
self.assertEqual('http.response', call_args[1])
|
||||
self.assertEqual('INFO', call_args[3])
|
||||
self.assertEqual(set(['request', 'response']),
|
||||
set(call_args[2].keys()))
|
||||
|
||||
request = call_args[2]['request']
|
||||
self.assertEqual(request['PATH_INFO'], '/foo/bar')
|
||||
self.assertEqual(request['REQUEST_METHOD'], 'GET')
|
||||
self.assertEqual('/foo/bar', request['PATH_INFO'])
|
||||
self.assertEqual('GET', request['REQUEST_METHOD'])
|
||||
self.assertIn('HTTP_X_SERVICE_NAME', request)
|
||||
self.assertNotIn('HTTP_X_AUTH_TOKEN', request)
|
||||
self.assertFalse(any(map(lambda s: s.startswith('wsgi.'),
|
||||
@ -80,8 +80,8 @@ class NotifierMiddlewareTest(utils.BaseTestCase):
|
||||
"WSGI fields are filtered out")
|
||||
|
||||
response = call_args[2]['response']
|
||||
self.assertEqual(response['status'], '200 OK')
|
||||
self.assertEqual(response['headers']['content-length'], '13')
|
||||
self.assertEqual('200 OK', response['status'])
|
||||
self.assertEqual('13', response['headers']['content-length'])
|
||||
|
||||
def test_notification_response_failure(self):
|
||||
m = middleware.RequestNotifier(FakeFailingApp())
|
||||
@ -97,14 +97,14 @@ class NotifierMiddlewareTest(utils.BaseTestCase):
|
||||
pass
|
||||
# Check first notification with only 'request'
|
||||
call_args = notify.call_args_list[0][0]
|
||||
self.assertEqual(call_args[1], 'http.request')
|
||||
self.assertEqual(call_args[3], 'INFO')
|
||||
self.assertEqual(set(call_args[2].keys()),
|
||||
set(['request']))
|
||||
self.assertEqual('http.request', call_args[1])
|
||||
self.assertEqual('INFO', call_args[3])
|
||||
self.assertEqual(set(['request']),
|
||||
set(call_args[2].keys()))
|
||||
|
||||
request = call_args[2]['request']
|
||||
self.assertEqual(request['PATH_INFO'], '/foo/bar')
|
||||
self.assertEqual(request['REQUEST_METHOD'], 'GET')
|
||||
self.assertEqual('/foo/bar', request['PATH_INFO'])
|
||||
self.assertEqual('GET', request['REQUEST_METHOD'])
|
||||
self.assertIn('HTTP_X_SERVICE_NAME', request)
|
||||
self.assertNotIn('HTTP_X_AUTH_TOKEN', request)
|
||||
self.assertFalse(any(map(lambda s: s.startswith('wsgi.'),
|
||||
@ -113,14 +113,14 @@ class NotifierMiddlewareTest(utils.BaseTestCase):
|
||||
|
||||
# Check second notification with 'request' and 'exception'
|
||||
call_args = notify.call_args_list[1][0]
|
||||
self.assertEqual(call_args[1], 'http.response')
|
||||
self.assertEqual(call_args[3], 'INFO')
|
||||
self.assertEqual(set(call_args[2].keys()),
|
||||
set(['request', 'exception']))
|
||||
self.assertEqual('http.response', call_args[1])
|
||||
self.assertEqual('INFO', call_args[3])
|
||||
self.assertEqual(set(['request', 'exception']),
|
||||
set(call_args[2].keys()))
|
||||
|
||||
request = call_args[2]['request']
|
||||
self.assertEqual(request['PATH_INFO'], '/foo/bar')
|
||||
self.assertEqual(request['REQUEST_METHOD'], 'GET')
|
||||
self.assertEqual('/foo/bar', request['PATH_INFO'])
|
||||
self.assertEqual('GET', request['REQUEST_METHOD'])
|
||||
self.assertIn('HTTP_X_SERVICE_NAME', request)
|
||||
self.assertNotIn('HTTP_X_AUTH_TOKEN', request)
|
||||
self.assertFalse(any(map(lambda s: s.startswith('wsgi.'),
|
||||
@ -130,7 +130,7 @@ class NotifierMiddlewareTest(utils.BaseTestCase):
|
||||
exception = call_args[2]['exception']
|
||||
self.assertIn('middleware.py', exception['traceback'][0])
|
||||
self.assertIn('It happens!', exception['traceback'][-1])
|
||||
self.assertEqual(exception['value'], "Exception('It happens!',)")
|
||||
self.assertEqual("Exception('It happens!',)", exception['value'])
|
||||
|
||||
def test_process_request_fail(self):
|
||||
def notify_error(context, publisher_id, event_type,
|
||||
@ -168,23 +168,23 @@ class NotifierMiddlewareTest(utils.BaseTestCase):
|
||||
# Check GET request does not send notification
|
||||
m(req)
|
||||
m(req1)
|
||||
self.assertEqual(len(notify.call_args_list), 0)
|
||||
self.assertEqual(0, len(notify.call_args_list))
|
||||
|
||||
# Check non-GET request does send notification
|
||||
m(req2)
|
||||
self.assertEqual(len(notify.call_args_list), 2)
|
||||
self.assertEqual(2, len(notify.call_args_list))
|
||||
call_args = notify.call_args_list[0][0]
|
||||
self.assertEqual(call_args[1], 'http.request')
|
||||
self.assertEqual(call_args[3], 'INFO')
|
||||
self.assertEqual(set(call_args[2].keys()),
|
||||
set(['request']))
|
||||
self.assertEqual('http.request', call_args[1])
|
||||
self.assertEqual('INFO', call_args[3])
|
||||
self.assertEqual(set(['request']),
|
||||
set(call_args[2].keys()))
|
||||
|
||||
request = call_args[2]['request']
|
||||
self.assertEqual(request['PATH_INFO'], '/accept/foo')
|
||||
self.assertEqual(request['REQUEST_METHOD'], 'POST')
|
||||
self.assertEqual('/accept/foo', request['PATH_INFO'])
|
||||
self.assertEqual('POST', request['REQUEST_METHOD'])
|
||||
|
||||
call_args = notify.call_args_list[1][0]
|
||||
self.assertEqual(call_args[1], 'http.response')
|
||||
self.assertEqual(call_args[3], 'INFO')
|
||||
self.assertEqual(set(call_args[2].keys()),
|
||||
set(['request', 'response']))
|
||||
self.assertEqual('http.response', call_args[1])
|
||||
self.assertEqual('INFO', call_args[3])
|
||||
self.assertEqual(set(['request', 'response']),
|
||||
set(call_args[2].keys()))
|
||||
|
@ -604,8 +604,8 @@ class TestServerLocking(test_utils.BaseTestCase):
|
||||
self.server.stop()
|
||||
self.server.wait()
|
||||
|
||||
self.assertEqual(len(self.executors), 1)
|
||||
self.assertEqual(self.executors[0]._calls, ['shutdown'])
|
||||
self.assertEqual(1, len(self.executors))
|
||||
self.assertEqual(['shutdown'], self.executors[0]._calls)
|
||||
self.assertTrue(self.server.listener.cleanup.called)
|
||||
|
||||
def test_reversed_order(self):
|
||||
@ -624,8 +624,8 @@ class TestServerLocking(test_utils.BaseTestCase):
|
||||
|
||||
self.server.wait()
|
||||
|
||||
self.assertEqual(len(self.executors), 1)
|
||||
self.assertEqual(self.executors[0]._calls, ['shutdown'])
|
||||
self.assertEqual(1, len(self.executors))
|
||||
self.assertEqual(['shutdown'], self.executors[0]._calls)
|
||||
|
||||
def test_wait_for_running_task(self):
|
||||
# Test that if 2 threads call a method simultaneously, both will wait,
|
||||
@ -675,7 +675,7 @@ class TestServerLocking(test_utils.BaseTestCase):
|
||||
|
||||
# We haven't signalled completion yet, so submit shouldn't have run
|
||||
self.assertEqual(1, len(self.executors))
|
||||
self.assertEqual(self.executors[0]._calls, [])
|
||||
self.assertEqual([], self.executors[0]._calls)
|
||||
self.assertFalse(waiter_finished.is_set())
|
||||
|
||||
# Let the runner complete
|
||||
@ -687,7 +687,7 @@ class TestServerLocking(test_utils.BaseTestCase):
|
||||
# and execute ran
|
||||
self.assertTrue(waiter_finished.is_set())
|
||||
self.assertEqual(1, len(self.executors))
|
||||
self.assertEqual(self.executors[0]._calls, [])
|
||||
self.assertEqual([], self.executors[0]._calls)
|
||||
|
||||
def test_start_stop_wait_stop_wait(self):
|
||||
# Test that we behave correctly when calling stop/wait more than once.
|
||||
@ -700,7 +700,7 @@ class TestServerLocking(test_utils.BaseTestCase):
|
||||
self.server.wait()
|
||||
|
||||
self.assertEqual(len(self.executors), 1)
|
||||
self.assertEqual(self.executors[0]._calls, ['shutdown'])
|
||||
self.assertEqual(['shutdown'], self.executors[0]._calls)
|
||||
self.assertTrue(self.server.listener.cleanup.called)
|
||||
|
||||
def test_state_wrapping(self):
|
||||
@ -736,7 +736,7 @@ class TestServerLocking(test_utils.BaseTestCase):
|
||||
|
||||
# The server should have started, but stop should not have been called
|
||||
self.assertEqual(1, len(self.executors))
|
||||
self.assertEqual(self.executors[0]._calls, [])
|
||||
self.assertEqual([], self.executors[0]._calls)
|
||||
self.assertFalse(thread1_finished.is_set())
|
||||
|
||||
self.server.stop()
|
||||
@ -745,7 +745,7 @@ class TestServerLocking(test_utils.BaseTestCase):
|
||||
# We should have gone through all the states, and thread1 should still
|
||||
# be waiting
|
||||
self.assertEqual(1, len(self.executors))
|
||||
self.assertEqual(self.executors[0]._calls, ['shutdown'])
|
||||
self.assertEqual(['shutdown'], self.executors[0]._calls)
|
||||
self.assertFalse(thread1_finished.is_set())
|
||||
|
||||
# Start again
|
||||
@ -753,8 +753,8 @@ class TestServerLocking(test_utils.BaseTestCase):
|
||||
|
||||
# We should now record 4 executors (2 for each server)
|
||||
self.assertEqual(2, len(self.executors))
|
||||
self.assertEqual(self.executors[0]._calls, ['shutdown'])
|
||||
self.assertEqual(self.executors[1]._calls, [])
|
||||
self.assertEqual(['shutdown'], self.executors[0]._calls)
|
||||
self.assertEqual([], self.executors[1]._calls)
|
||||
self.assertFalse(thread1_finished.is_set())
|
||||
|
||||
# Allow thread1 to complete
|
||||
@ -764,8 +764,8 @@ class TestServerLocking(test_utils.BaseTestCase):
|
||||
# thread1 should now have finished, and stop should not have been
|
||||
# called again on either the first or second executor
|
||||
self.assertEqual(2, len(self.executors))
|
||||
self.assertEqual(self.executors[0]._calls, ['shutdown'])
|
||||
self.assertEqual(self.executors[1]._calls, [])
|
||||
self.assertEqual(['shutdown'], self.executors[0]._calls)
|
||||
self.assertEqual([], self.executors[1]._calls)
|
||||
self.assertTrue(thread1_finished.is_set())
|
||||
|
||||
@mock.patch.object(server_module, 'DEFAULT_LOG_AFTER', 1)
|
||||
|
@ -53,25 +53,19 @@ class TestConfigOptsProxy(test_utils.BaseTestCase):
|
||||
'unknown_group')
|
||||
self.assertTrue(isinstance(getattr(conf, group),
|
||||
conf.GroupAttrProxy))
|
||||
self.assertEqual(conf.oslo_messaging_rabbit.rabbit_retry_interval,
|
||||
1)
|
||||
self.assertEqual(conf.oslo_messaging_rabbit.rabbit_qos_prefetch_count,
|
||||
2)
|
||||
self.assertEqual(conf.oslo_messaging_rabbit.rabbit_max_retries,
|
||||
3)
|
||||
self.assertEqual(1, conf.oslo_messaging_rabbit.rabbit_retry_interval)
|
||||
self.assertEqual(2,
|
||||
conf.oslo_messaging_rabbit.rabbit_qos_prefetch_count)
|
||||
self.assertEqual(3, conf.oslo_messaging_rabbit.rabbit_max_retries)
|
||||
self.assertRaises(cfg.NoSuchOptError,
|
||||
conf.oslo_messaging_rabbit.__getattr__,
|
||||
'unknown_opt')
|
||||
self.assertRaises(ValueError,
|
||||
conf.oslo_messaging_rabbit.__getattr__,
|
||||
'kombu_reconnect_delay')
|
||||
self.assertEqual(conf.oslo_messaging_rabbit.list_str,
|
||||
['1', '2', '3'])
|
||||
self.assertEqual(conf.oslo_messaging_rabbit.list_int,
|
||||
[1, 2, 3])
|
||||
self.assertEqual(conf.oslo_messaging_rabbit.dict,
|
||||
{'x': '1', 'y': '2', 'z': '3'})
|
||||
self.assertEqual(conf.oslo_messaging_rabbit.bool,
|
||||
True)
|
||||
self.assertEqual(conf.oslo_messaging_rabbit.str,
|
||||
'default')
|
||||
self.assertEqual(['1', '2', '3'], conf.oslo_messaging_rabbit.list_str)
|
||||
self.assertEqual([1, 2, 3], conf.oslo_messaging_rabbit.list_int)
|
||||
self.assertEqual({'x': '1', 'y': '2', 'z': '3'},
|
||||
conf.oslo_messaging_rabbit.dict)
|
||||
self.assertEqual(True, conf.oslo_messaging_rabbit.bool)
|
||||
self.assertEqual('default', conf.oslo_messaging_rabbit.str)
|
||||
|
@ -41,7 +41,7 @@ class TestRequestContextSerializer(test_utils.BaseTestCase):
|
||||
|
||||
entity = self.serializer.serialize_entity(self.context, self.entity)
|
||||
self.assertFalse(self.serializer._base.serialize_entity.called)
|
||||
self.assertEqual(entity, self.entity)
|
||||
self.assertEqual(self.entity, entity)
|
||||
|
||||
def test_deserialize_entity(self):
|
||||
self.serializer.deserialize_entity(self.context, self.entity)
|
||||
@ -56,12 +56,12 @@ class TestRequestContextSerializer(test_utils.BaseTestCase):
|
||||
|
||||
entity = self.serializer.deserialize_entity(self.context, self.entity)
|
||||
self.assertFalse(self.serializer._base.serialize_entity.called)
|
||||
self.assertEqual(entity, self.entity)
|
||||
self.assertEqual(self.entity, entity)
|
||||
|
||||
def test_serialize_context(self):
|
||||
new_context = self.serializer.serialize_context(self.context)
|
||||
|
||||
self.assertEqual(new_context, self.context.to_dict())
|
||||
self.assertEqual(self.context.to_dict(), new_context)
|
||||
|
||||
@mock.patch.object(common_context.RequestContext, 'from_dict',
|
||||
return_value='foobar')
|
||||
@ -70,6 +70,6 @@ class TestRequestContextSerializer(test_utils.BaseTestCase):
|
||||
|
||||
mock_to_dict.assert_called_with(self.context)
|
||||
self.assertEqual(
|
||||
new_context,
|
||||
common_context.RequestContext.from_dict(self.context)
|
||||
common_context.RequestContext.from_dict(self.context),
|
||||
new_context
|
||||
)
|
||||
|
@ -145,10 +145,12 @@ class GetTransportTestCase(test_utils.BaseTestCase):
|
||||
transport_ = oslo_messaging.get_transport(self.conf, **kwargs)
|
||||
|
||||
if self.aliases is not None:
|
||||
self.assertEqual(fake_logger.warning.mock_calls,
|
||||
[mock.call('legacy "rpc_backend" is deprecated, '
|
||||
'"testfoo" must be replaced by '
|
||||
'"%s"' % self.aliases.get('testfoo'))])
|
||||
self.assertEqual(
|
||||
[mock.call('legacy "rpc_backend" is deprecated, '
|
||||
'"testfoo" must be replaced by '
|
||||
'"%s"' % self.aliases.get('testfoo'))],
|
||||
fake_logger.warning.mock_calls
|
||||
)
|
||||
|
||||
self.assertIsNotNone(transport_)
|
||||
self.assertIs(transport_.conf, self.conf)
|
||||
@ -354,10 +356,10 @@ class TestTransportUrlCustomisation(test_utils.BaseTestCase):
|
||||
self.assertNotEqual(self.url1, self.url4)
|
||||
|
||||
def test_query(self):
|
||||
self.assertEqual(self.url1.query, {'x': '1', 'y': '2', 'z': '3'})
|
||||
self.assertEqual(self.url2.query, {'foo': 'bar'})
|
||||
self.assertEqual(self.url3.query, {'l': '1,2,3'})
|
||||
self.assertEqual(self.url4.query, {'d': 'x:1,y:2,z:3'})
|
||||
self.assertEqual({'x': '1', 'y': '2', 'z': '3'}, self.url1.query)
|
||||
self.assertEqual({'foo': 'bar'}, self.url2.query)
|
||||
self.assertEqual({'l': '1,2,3'}, self.url3.query)
|
||||
self.assertEqual({'d': 'x:1,y:2,z:3'}, self.url4.query)
|
||||
|
||||
|
||||
class TestTransportHostCustomisation(test_utils.BaseTestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user