Define self.client in MessagingCore
Currently self.client is referenced within MessagingCore, but no definition is made in its constructor. Additionally self.client is defined in children classes of MessagingCore. This patchset defines self.client in the constructor of MessagingCore and removes the redefinition in its children. -self.client lazily loaded Co-Authored-By: v-francoise <Vincent.FRANCOISE@b-com.com> Change-Id: I14525a175bf1ebde3d2636024ad2f2219c79d6e1 Closes-Bug: #1521636
This commit is contained in:
committed by
Vincent Françoise
parent
7406a1e713
commit
2f0c1c12cf
@@ -14,17 +14,16 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from mock import Mock
|
||||
from mock import patch
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import oslo_messaging as messaging
|
||||
from watcher.common.messaging.messaging_handler import MessagingHandler
|
||||
from watcher.tests.base import TestCase
|
||||
from watcher.common.messaging import messaging_handler
|
||||
from watcher.tests import base
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestMessagingHandler(TestCase):
|
||||
class TestMessagingHandler(base.TestCase):
|
||||
|
||||
PUBLISHER_ID = 'TEST_API'
|
||||
TOPIC_WATCHER = 'TEST_TOPIC_WATCHER'
|
||||
@@ -35,20 +34,20 @@ class TestMessagingHandler(TestCase):
|
||||
super(TestMessagingHandler, self).setUp()
|
||||
CONF.set_default('host', 'fake-fqdn')
|
||||
|
||||
@patch.object(messaging, "get_rpc_server")
|
||||
@patch.object(messaging, "Target")
|
||||
@mock.patch.object(messaging, "get_rpc_server")
|
||||
@mock.patch.object(messaging, "Target")
|
||||
def test_setup_messaging_handler(self, m_target_cls, m_get_rpc_server):
|
||||
m_target = Mock()
|
||||
m_target = mock.Mock()
|
||||
m_target_cls.return_value = m_target
|
||||
messaging_handler = MessagingHandler(
|
||||
handler = messaging_handler.MessagingHandler(
|
||||
publisher_id=self.PUBLISHER_ID,
|
||||
topic_watcher=self.TOPIC_WATCHER,
|
||||
topic_name=self.TOPIC_WATCHER,
|
||||
endpoint=self.ENDPOINT,
|
||||
version=self.VERSION,
|
||||
serializer=None,
|
||||
)
|
||||
|
||||
messaging_handler.run()
|
||||
handler.run()
|
||||
|
||||
m_target_cls.assert_called_once_with(
|
||||
server="fake-fqdn",
|
||||
@@ -56,23 +55,23 @@ class TestMessagingHandler(TestCase):
|
||||
version="1.0",
|
||||
)
|
||||
m_get_rpc_server.assert_called_once_with(
|
||||
messaging_handler.transport,
|
||||
handler.transport,
|
||||
m_target,
|
||||
[self.ENDPOINT],
|
||||
serializer=None,
|
||||
)
|
||||
|
||||
def test_messaging_handler_remove_endpoint(self):
|
||||
messaging_handler = MessagingHandler(
|
||||
handler = messaging_handler.MessagingHandler(
|
||||
publisher_id=self.PUBLISHER_ID,
|
||||
topic_watcher=self.TOPIC_WATCHER,
|
||||
topic_name=self.TOPIC_WATCHER,
|
||||
endpoint=self.ENDPOINT,
|
||||
version=self.VERSION,
|
||||
serializer=None,
|
||||
)
|
||||
|
||||
self.assertEqual(messaging_handler.endpoints, [self.ENDPOINT])
|
||||
self.assertEqual(handler.endpoints, [self.ENDPOINT])
|
||||
|
||||
messaging_handler.remove_endpoint(self.ENDPOINT)
|
||||
handler.remove_endpoint(self.ENDPOINT)
|
||||
|
||||
self.assertEqual(messaging_handler.endpoints, [])
|
||||
self.assertEqual(handler.endpoints, [])
|
||||
|
||||
Reference in New Issue
Block a user