本文整理汇总了Python中SoftLayer.MessagingManager.get_connection方法的典型用法代码示例。如果您正苦于以下问题:Python MessagingManager.get_connection方法的具体用法?Python MessagingManager.get_connection怎么用?Python MessagingManager.get_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SoftLayer.MessagingManager
的用法示例。
在下文中一共展示了MessagingManager.get_connection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from SoftLayer import MessagingManager [as 别名]
# 或者: from SoftLayer.MessagingManager import get_connection [as 别名]
def execute(self, args):
manager = MessagingManager(self.client)
mq_client = manager.get_connection(args['<account_id>'])
mq_client.delete_subscription(
args['<topic_name>'],
args['<subscription_id>'])
示例2: queue_list
# 需要导入模块: from SoftLayer import MessagingManager [as 别名]
# 或者: from SoftLayer.MessagingManager import get_connection [as 别名]
def queue_list(account_id):
manager = MessagingManager(get_client())
mq_client = manager.get_connection(account_id)
queues = mq_client.get_queues()['items']
print queues
return ''
示例3: execute
# 需要导入模块: from SoftLayer import MessagingManager [as 别名]
# 或者: from SoftLayer.MessagingManager import get_connection [as 别名]
def execute(cls, client, args):
manager = MessagingManager(client)
mq_client = manager.get_connection(args['<account_id>'])
body = ''
if args['<message>'] is not None:
body = args['<message>']
else:
body = sys.stdin.read()
return message_table(
mq_client.push_queue_message(args['<queue_name>'], body))
示例4: MessagingManagerTests
# 需要导入模块: from SoftLayer import MessagingManager [as 别名]
# 或者: from SoftLayer.MessagingManager import get_connection [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)