当前位置: 首页>>代码示例>>Python>>正文


Python ExchangeManager._make_management_call方法代码示例

本文整理汇总了Python中pyon.ion.exchange.ExchangeManager._make_management_call方法的典型用法代码示例。如果您正苦于以下问题:Python ExchangeManager._make_management_call方法的具体用法?Python ExchangeManager._make_management_call怎么用?Python ExchangeManager._make_management_call使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyon.ion.exchange.ExchangeManager的用法示例。


在下文中一共展示了ExchangeManager._make_management_call方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestManagementAPI

# 需要导入模块: from pyon.ion.exchange import ExchangeManager [as 别名]
# 或者: from pyon.ion.exchange.ExchangeManager import _make_management_call [as 别名]
class TestManagementAPI(PyonTestCase):
    def setUp(self):
        self.ex_manager = ExchangeManager(Mock())
        self.ex_manager._nodes = MagicMock()
        self.ex_manager._nodes.get.return_value.client.parameters.host = "testhost" # stringifies so don't use sentinel

        self.ex_manager._ems_client = Mock()

    def test__get_management_url(self):
        url = self.ex_manager._get_management_url()

        self.assertEquals(url, "http://testhost:port/api/")

    def test__get_management_url_with_parts(self):
        url = self.ex_manager._get_management_url("test", "this")

        self.assertEquals(url, "http://testhost:port/api/test/this")

    @patch('pyon.ion.exchange.json')
    @patch('pyon.ion.exchange.requests')
    def test__call_management(self, reqmock, jsonmock):
        content = self.ex_manager._call_management(sentinel.url)

        self.assertEquals(content, jsonmock.loads.return_value)
        reqmock.get.assert_called_once_with(sentinel.url, auth=('user', 'pass'), data=None)

    @patch('pyon.ion.exchange.json')
    @patch('pyon.ion.exchange.requests')
    def test__call_management_delete(self, reqmock, jsonmock):
        content = self.ex_manager._call_management_delete(sentinel.url)

        self.assertEquals(content, jsonmock.loads.return_value)
        reqmock.delete.assert_called_once_with(sentinel.url, auth=('user', 'pass'), data=None)

    @patch('pyon.ion.exchange.json')
    @patch('pyon.ion.exchange.requests')
    def test__make_management_call(self, reqmock, jsonmock):
        content = self.ex_manager._make_management_call(sentinel.url, method="scoop")

        reqmock.scoop.assert_called_once_with(sentinel.url, auth=('user', 'pass'), data=None)

    def test__make_management_call_delegates_to_ems(self):
        self.ex_manager._ems_available = Mock(return_value=True)

        content = self.ex_manager._make_management_call(sentinel.url, method=sentinel.anymeth)

        self.ex_manager._ems_client.call_management.assert_called_once_with(sentinel.url, sentinel.anymeth, headers=None)

    def test__make_management_call_raises_exceptions(self):
        rmock = Mock()
        rmock.return_value.raise_for_status.side_effect = requests.exceptions.Timeout

        with patch('pyon.ion.exchange.requests.get', rmock):
            self.assertRaises(exception.Timeout, self.ex_manager._make_management_call, sentinel.url, use_ems=False)

    def test_list_queues_does_filtering(self):
        self.ex_manager._list_queues = Mock(return_value=[{'name':'a_1'}, {'name':'a_2'}, {'name':'b_1'}, {'name':'b_2'}])

        self.assertEquals(len(self.ex_manager.list_queues("a_")), 2)
        self.assertEquals(len(self.ex_manager.list_queues("b_")), 2)
        self.assertEquals(len(self.ex_manager.list_queues("_")), 4)
        self.assertEquals(len(self.ex_manager.list_queues("_1")), 2)
        self.assertEquals(len(self.ex_manager.list_queues("_2")), 2)

    def test_list_bindings_does_filtering(self):
        self.ex_manager._list_bindings = Mock(return_value=[{'source':'ex_1', 'destination':'qq', 'routing_key':'', 'properties_key':'', 'destination_type':'queue'},
                                                            {'source':'ex_2', 'destination':'qa', 'routing_key':'', 'properties_key':'', 'destination_type':'queue'},
                                                            {'source':'ex_1', 'destination':'aq', 'routing_key':'', 'properties_key':'', 'destination_type':'queue'},
                                                            {'source':'ex_2', 'destination':'za', 'routing_key':'', 'properties_key':'', 'destination_type':'queue'},])

        self.assertEquals(len(self.ex_manager.list_bindings(exchange="ex_1")), 2)
        self.assertEquals(len(self.ex_manager.list_bindings(exchange="ex_2")), 2)
        self.assertEquals(len(self.ex_manager.list_bindings(exchange="ex_")), 4)
        self.assertEquals(len(self.ex_manager.list_bindings(queue="qq")), 1)
        self.assertEquals(len(self.ex_manager.list_bindings(queue="a")), 3)
        self.assertEquals(len(self.ex_manager.list_bindings(queue="q")), 3)
开发者ID:j2project,项目名称:pyon,代码行数:78,代码来源:test_exchange.py


注:本文中的pyon.ion.exchange.ExchangeManager._make_management_call方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。