Merge "Update samples/test_suite.yaml"
[yardstick.git] / yardstick / tests / unit / common / messaging / test_producer.py
1 # Copyright (c) 2018 Intel Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import mock
16 from oslo_config import cfg
17 import oslo_messaging
18
19 from yardstick.common import messaging
20 from yardstick.common.messaging import producer
21 from yardstick.tests.unit import base as ut_base
22
23
24 class _MessagingProducer(producer.MessagingProducer):
25     pass
26
27
28 class MessagingProducerTestCase(ut_base.BaseUnitTestCase):
29
30     def test__init(self):
31         with mock.patch.object(oslo_messaging, 'RPCClient') as \
32                 mock_RPCClient, \
33                 mock.patch.object(oslo_messaging, 'get_rpc_transport') as \
34                 mock_get_rpc_transport, \
35                 mock.patch.object(oslo_messaging, 'Target') as \
36                 mock_Target:
37             mock_get_rpc_transport.return_value = 'test_rpc_transport'
38             mock_Target.return_value = 'test_Target'
39
40             _MessagingProducer('test_topic', 'test_pid', fanout=True)
41             mock_get_rpc_transport.assert_called_once_with(
42                 cfg.CONF, url=messaging.TRANSPORT_URL)
43             mock_Target.assert_called_once_with(
44                 topic='test_topic', fanout=True, server=messaging.SERVER)
45             mock_RPCClient.assert_called_once_with('test_rpc_transport',
46                                                    'test_Target')