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


Python MessagingManager.get_endpoints方法代码示例

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


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

示例1: execute

# 需要导入模块: from SoftLayer import MessagingManager [as 别名]
# 或者: from SoftLayer.MessagingManager import get_endpoints [as 别名]
    def execute(self, args):
        manager = MessagingManager(self.client)
        regions = manager.get_endpoints()

        table = Table([
            'name', 'public', 'private'
        ])
        for region, endpoints in regions.items():
            table.add_row([
                region,
                endpoints.get('public') or blank(),
                endpoints.get('private') or blank(),
            ])

        return table
开发者ID:aparnapatil,项目名称:softlayer-python,代码行数:17,代码来源:messaging.py

示例2: MessagingManagerTests

# 需要导入模块: from SoftLayer import MessagingManager [as 别名]
# 或者: from SoftLayer.MessagingManager import get_endpoints [as 别名]
class MessagingManagerTests(unittest.TestCase):

    def setUp(self):
        self.client = MagicMock()
        self.manager = MessagingManager(self.client)

    def test_list_accounts(self):
        self.manager.list_accounts()
        self.client['Account'].getMessageQueueAccounts.assert_called_with(
            mask=ANY)

    def test_get_endpoints(self):
        endpoints = self.manager.get_endpoints()
        self.assertEqual(endpoints, SoftLayer.managers.messaging.ENDPOINTS)

    @patch('SoftLayer.managers.messaging.ENDPOINTS', {
        'datacenter01': {
            'private': 'private_endpoint', 'public': 'public_endpoint'},
        'dal05': {
            'private': 'dal05_private', 'public': 'dal05_public'}})
    def test_get_endpoint(self):
        # Defaults to dal05, public
        endpoint = self.manager.get_endpoint()
        self.assertEqual(endpoint, 'https://dal05_public')

        endpoint = self.manager.get_endpoint(network='private')
        self.assertEqual(endpoint, 'https://dal05_private')

        endpoint = self.manager.get_endpoint(datacenter='datacenter01')
        self.assertEqual(endpoint, 'https://public_endpoint')

        endpoint = self.manager.get_endpoint(datacenter='datacenter01',
                                             network='private')
        self.assertEqual(endpoint, 'https://private_endpoint')

        endpoint = self.manager.get_endpoint(datacenter='datacenter01',
                                             network='private')
        self.assertEqual(endpoint, 'https://private_endpoint')

        # ERROR CASES
        self.assertRaises(
            TypeError,
            self.manager.get_endpoint, datacenter='doesnotexist')

        self.assertRaises(
            TypeError,
            self.manager.get_endpoint, network='doesnotexist')

    @patch('SoftLayer.managers.messaging.MessagingConnection')
    def test_get_connection(self, conn):
        queue_conn = self.manager.get_connection('QUEUE_ACCOUNT_ID')
        conn.assert_called_with(
            'QUEUE_ACCOUNT_ID', endpoint='https://dal05.mq.softlayer.net')
        conn().authenticate.assert_called_with(
            self.client.auth.username, self.client.auth.api_key)
        self.assertEqual(queue_conn, conn())

    def test_get_connection_no_auth(self):
        self.client.auth = None
        self.assertRaises(SoftLayerError,
                          self.manager.get_connection, 'QUEUE_ACCOUNT_ID')

    def test_get_connection_no_username(self):
        self.client.auth.username = None
        self.assertRaises(SoftLayerError,
                          self.manager.get_connection, 'QUEUE_ACCOUNT_ID')

    def test_get_connection_no_api_key(self):
        self.client.auth.api_key = None
        self.assertRaises(SoftLayerError,
                          self.manager.get_connection, 'QUEUE_ACCOUNT_ID')

    @patch('SoftLayer.managers.messaging.requests.get')
    def test_ping(self, get):
        result = self.manager.ping()

        get.assert_called_with('https://dal05.mq.softlayer.net/v1/ping')
        get().raise_for_status.assert_called_with()
        self.assertTrue(result)
开发者ID:anil-kumbhar,项目名称:softlayer-python,代码行数:81,代码来源:queue_tests.py


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