當前位置: 首頁>>代碼示例>>Python>>正文


Python Profile._set_subscriptions方法代碼示例

本文整理匯總了Python中azure.cli._profile.Profile._set_subscriptions方法的典型用法代碼示例。如果您正苦於以下問題:Python Profile._set_subscriptions方法的具體用法?Python Profile._set_subscriptions怎麽用?Python Profile._set_subscriptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在azure.cli._profile.Profile的用法示例。


在下文中一共展示了Profile._set_subscriptions方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_get_login_credentials

# 需要導入模塊: from azure.cli._profile import Profile [as 別名]
# 或者: from azure.cli._profile.Profile import _set_subscriptions [as 別名]
    def test_get_login_credentials(self, mock_get_token, mock_read_cred_file):
        some_token_type = 'Bearer'
        mock_read_cred_file.return_value = json.dumps([Test_Profile.token_entry1])
        mock_get_token.return_value = (some_token_type, Test_Profile.raw_token1)
        #setup
        storage_mock = {'subscriptions': None}
        profile = Profile(storage_mock)
        consolidated = Profile._normalize_properties(self.user1,
                                                     [self.subscription1],
                                                     False,
                                                     ENV_DEFAULT)
        profile._set_subscriptions(consolidated)
        #action
        cred, subscription_id, _ = profile.get_login_credentials()

        #verify
        self.assertEqual(subscription_id, '1')

        #verify the cred._tokenRetriever is a working lambda
        token_type, token = cred._token_retriever()
        self.assertEqual(token, self.raw_token1)
        self.assertEqual(some_token_type, token_type)
        self.assertEqual(mock_read_cred_file.call_count, 1)
        mock_get_token.assert_called_once_with(mock.ANY, self.user1, self.tenant_id,
                                               'https://management.core.windows.net/')
        self.assertEqual(mock_get_token.call_count, 1)
開發者ID:johanste,項目名稱:azure-cli-private,代碼行數:28,代碼來源:test_profile.py

示例2: test_update_add_two_different_subscriptions

# 需要導入模塊: from azure.cli._profile import Profile [as 別名]
# 或者: from azure.cli._profile.Profile import _set_subscriptions [as 別名]
    def test_update_add_two_different_subscriptions(self):
        storage_mock = {'subscriptions': None}
        profile = Profile(storage_mock)

        #add the first and verify
        consolidated = Profile._normalize_properties(self.user1,
                                                     [self.subscription1],
                                                     False,
                                                     ENV_DEFAULT)
        profile._set_subscriptions(consolidated)

        self.assertEqual(len(storage_mock['subscriptions']), 1)
        subscription1 = storage_mock['subscriptions'][0]
        self.assertEqual(subscription1, {
            'environmentName': 'AzureCloud',
            'id': '1',
            'name': self.display_name1,
            'state': self.state1,
            'user': {
                'name': self.user1,
                'type': 'user'
                },
            'isDefault': True,
            'tenantId': self.tenant_id
            })

        #add the second and verify
        consolidated = Profile._normalize_properties(self.user2,
                                                     [self.subscription2],
                                                     False,
                                                     ENV_DEFAULT)
        profile._set_subscriptions(consolidated)

        self.assertEqual(len(storage_mock['subscriptions']), 2)
        subscription2 = storage_mock['subscriptions'][1]
        self.assertEqual(subscription2, {
            'environmentName': 'AzureCloud',
            'id': '2',
            'name': self.display_name2,
            'state': self.state2,
            'user': {
                'name': self.user2,
                'type': 'user'
                },
            'isDefault': True,
            'tenantId': self.tenant_id
            })

        #verify the old one stays, but no longer active
        self.assertEqual(storage_mock['subscriptions'][0]['name'],
                         subscription1['name'])
        self.assertFalse(storage_mock['subscriptions'][0]['isDefault'])
開發者ID:johanste,項目名稱:azure-cli-private,代碼行數:54,代碼來源:test_profile.py

示例3: test_get_current_account_user

# 需要導入模塊: from azure.cli._profile import Profile [as 別名]
# 或者: from azure.cli._profile.Profile import _set_subscriptions [as 別名]
    def test_get_current_account_user(self, mock_read_cred_file):
        #setup
        mock_read_cred_file.return_value = json.dumps([Test_Profile.token_entry1])

        storage_mock = {'subscriptions': None}
        profile = Profile(storage_mock)
        consolidated = Profile._normalize_properties(self.user1,
                                                     [self.subscription1],
                                                     False,
                                                     ENV_DEFAULT)
        profile._set_subscriptions(consolidated)
        #action
        user = profile.get_current_account_user()

        #verify
        self.assertEqual(user, self.user1)
開發者ID:johanste,項目名稱:azure-cli-private,代碼行數:18,代碼來源:test_profile.py

示例4: test_get_login_credentials_for_graph_client

# 需要導入模塊: from azure.cli._profile import Profile [as 別名]
# 或者: from azure.cli._profile.Profile import _set_subscriptions [as 別名]
 def test_get_login_credentials_for_graph_client(self, mock_get_token, mock_read_cred_file):
     some_token_type = 'Bearer'
     mock_read_cred_file.return_value = json.dumps([Test_Profile.token_entry1])
     mock_get_token.return_value = (some_token_type, Test_Profile.raw_token1)
     #setup
     storage_mock = {'subscriptions': None}
     profile = Profile(storage_mock)
     consolidated = Profile._normalize_properties(self.user1, [self.subscription1],
                                                  False, ENV_DEFAULT)
     profile._set_subscriptions(consolidated)
     #action
     cred, _, tenant_id = profile.get_login_credentials(for_graph_client=True)
     _, _ = cred._token_retriever()
     #verify
     mock_get_token.assert_called_once_with(mock.ANY, self.user1, self.tenant_id,
                                            'https://graph.windows.net/')
     self.assertEqual(tenant_id, self.tenant_id)
開發者ID:johanste,項目名稱:azure-cli-private,代碼行數:19,代碼來源:test_profile.py

示例5: test_logout

# 需要導入模塊: from azure.cli._profile import Profile [as 別名]
# 或者: from azure.cli._profile.Profile import _set_subscriptions [as 別名]
    def test_logout(self, mock_persist_creds, mock_read_cred_file):
        #setup
        mock_read_cred_file.return_value = json.dumps([Test_Profile.token_entry1])

        storage_mock = {'subscriptions': None}
        profile = Profile(storage_mock)
        consolidated = Profile._normalize_properties(self.user1,
                                                     [self.subscription1],
                                                     False,
                                                     ENV_DEFAULT)
        profile._set_subscriptions(consolidated)
        self.assertEqual(1, len(storage_mock['subscriptions']))
        #action
        profile.logout(self.user1)

        #verify
        self.assertEqual(0, len(storage_mock['subscriptions']))
        self.assertEqual(mock_read_cred_file.call_count, 1)
        self.assertEqual(mock_persist_creds.call_count, 1)
開發者ID:johanste,項目名稱:azure-cli-private,代碼行數:21,代碼來源:test_profile.py

示例6: test_logout_all

# 需要導入模塊: from azure.cli._profile import Profile [as 別名]
# 或者: from azure.cli._profile.Profile import _set_subscriptions [as 別名]
    def test_logout_all(self, mock_delete_cred_file):
        #setup
        storage_mock = {'subscriptions': None}
        profile = Profile(storage_mock)
        consolidated = Profile._normalize_properties(self.user1,
                                                     [self.subscription1],
                                                     False,
                                                     ENV_DEFAULT)
        consolidated2 = Profile._normalize_properties(self.user2,
                                                      [self.subscription2],
                                                      False,
                                                      ENV_DEFAULT)
        profile._set_subscriptions(consolidated + consolidated2)

        self.assertEqual(2, len(storage_mock['subscriptions']))
        #action
        profile.logout_all()

        #verify
        self.assertEqual(0, len(storage_mock['subscriptions']))
        self.assertEqual(mock_delete_cred_file.call_count, 1)
開發者ID:johanste,項目名稱:azure-cli-private,代碼行數:23,代碼來源:test_profile.py

示例7: test_set_active_subscription

# 需要導入模塊: from azure.cli._profile import Profile [as 別名]
# 或者: from azure.cli._profile.Profile import _set_subscriptions [as 別名]
    def test_set_active_subscription(self):
        storage_mock = {'subscriptions': None}
        profile = Profile(storage_mock)

        consolidated = Profile._normalize_properties(self.user1,
                                                     [self.subscription1],
                                                     False,
                                                     ENV_DEFAULT)
        profile._set_subscriptions(consolidated)

        consolidated = profile._normalize_properties(self.user2,
                                                     [self.subscription2],
                                                     False,
                                                     ENV_DEFAULT)
        profile._set_subscriptions(consolidated)

        subscription1 = storage_mock['subscriptions'][0]
        subscription2 = storage_mock['subscriptions'][1]
        self.assertTrue(subscription2['isDefault'])

        profile.set_active_subscription(subscription1['id'])
        self.assertFalse(subscription2['isDefault'])
        self.assertTrue(subscription1['isDefault'])
開發者ID:johanste,項目名稱:azure-cli-private,代碼行數:25,代碼來源:test_profile.py

示例8: test_update_with_same_subscription_added_twice

# 需要導入模塊: from azure.cli._profile import Profile [as 別名]
# 或者: from azure.cli._profile.Profile import _set_subscriptions [as 別名]
    def test_update_with_same_subscription_added_twice(self):
        storage_mock = {'subscriptions': None}
        profile = Profile(storage_mock)

        #add one twice and verify we will have one but with new token
        consolidated = Profile._normalize_properties(self.user1,
                                                     [self.subscription1],
                                                     False,
                                                     ENV_DEFAULT)
        profile._set_subscriptions(consolidated)

        new_subscription1 = SubscriptionStub(self.id1,
                                             self.display_name1,
                                             self.state1,
                                             self.tenant_id)
        consolidated = Profile._normalize_properties(self.user1,
                                                     [new_subscription1],
                                                     False,
                                                     ENV_DEFAULT)
        profile._set_subscriptions(consolidated)

        self.assertEqual(len(storage_mock['subscriptions']), 1)
        self.assertTrue(storage_mock['subscriptions'][0]['isDefault'])
開發者ID:johanste,項目名稱:azure-cli-private,代碼行數:25,代碼來源:test_profile.py


注:本文中的azure.cli._profile.Profile._set_subscriptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。