Пример #1
0
 def test_supported_api_version_invalid_rt_for_profile(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {'2017-01-01-profile': {ResourceType.MGMT_STORAGE: '2020-10-10'}}
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
         with self.assertRaises(APIVersionException):
             supported_api_version(cli, ResourceType.MGMT_COMPUTE, min_api='2020-01-01')
Пример #2
0
 def test_supported_api_version_min_max_constraint(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {'2017-01-01-profile': {ResourceType.MGMT_STORAGE: '2020-10-10'}}
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
         self.assertTrue(
             supported_api_version(cli, ResourceType.MGMT_STORAGE, min_api='2020-01-01', max_api='2021-01-01'))
Пример #3
0
 def test_get_api_version_semver(self):
     # Can get correct resource type API version if semver used
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {'2017-01-01-profile': {ResourceType.MGMT_KEYVAULT: '7.0'}}
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
         self.assertEqual(get_api_version(cli, ResourceType.MGMT_KEYVAULT), '7.0')
Пример #4
0
 def test_supported_api_profile_preview_constraint(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2000-01-01-profile')
     self.assertTrue(
         supported_api_version(cli,
                               PROFILE_TYPE,
                               min_api='2000-01-01-preview'))
Пример #5
0
 def test_get_api_version(self):
     # Can get correct resource type API version
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {'2017-01-01-profile': {ResourceType.MGMT_STORAGE: '2020-10-10'}}
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
         self.assertEqual(get_api_version(cli, ResourceType.MGMT_STORAGE), '2020-10-10')
Пример #6
0
 def test_supported_api_version_min_max_constraint_semver(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {'2017-01-01-profile': {ResourceType.MGMT_KEYVAULT: '7.0'}}
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
         self.assertTrue(
             supported_api_version(cli, ResourceType.MGMT_KEYVAULT, min_api='6.0', max_api='8.0'))
Пример #7
0
 def test_get_api_version_invalid_active_profile(self):
     # The active profile is not in our profile dict
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='not-a-real-profile')
     test_profile = {'2017-01-01-profile': {ResourceType.MGMT_STORAGE: '2020-10-10'}}
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
         with self.assertRaises(APIVersionException):
             get_api_version(cli, ResourceType.MGMT_STORAGE)
Пример #8
0
 def test_get_api_version_invalid_rt_2(self):
     # None is not a valid resource type
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {'2017-01-01-profile': {ResourceType.MGMT_STORAGE: '2020-10-10'}}
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
         with self.assertRaises(APIVersionException):
             get_api_version(cli, None)
Пример #9
0
 def test_when_alias_doc_is_missing(self, mock_get_active_cloud):
     from azure.cli.command_modules.vm._actions import load_images_from_aliases_doc
     p = mock.PropertyMock(side_effect=CloudEndpointNotSetException(''))
     mock_cloud = mock.MagicMock()
     type(mock_cloud.endpoints).vm_image_alias_doc = p
     mock_get_active_cloud.return_value = mock_cloud
     # assert
     cli_ctx = DummyCli()
     cli_ctx.cloud = mock_cloud
     with self.assertRaises(CLIError):
         load_images_from_aliases_doc(cli_ctx)
Пример #10
0
 def test_when_alias_doc_is_missing(self, mock_get_active_cloud):
     from azure.cli.command_modules.vm._actions import load_images_from_aliases_doc
     p = mock.PropertyMock(side_effect=CloudEndpointNotSetException(''))
     mock_cloud = mock.MagicMock()
     type(mock_cloud.endpoints).vm_image_alias_doc = p
     mock_get_active_cloud.return_value = mock_cloud
     # assert
     cli_ctx = DummyCli()
     cli_ctx.cloud = mock_cloud
     with self.assertRaises(CLIError):
         load_images_from_aliases_doc(cli_ctx)
Пример #11
0
 def test_when_alias_doc_is_missing(self, mock_get_active_cloud):
     from azure.cli.command_modules.vm._actions import load_images_from_aliases_doc
     p = mock.PropertyMock(side_effect=CloudEndpointNotSetException(''))
     mock_cloud = mock.MagicMock()
     type(mock_cloud.endpoints).vm_image_alias_doc = p
     mock_get_active_cloud.return_value = mock_cloud
     # assert
     cli_ctx = DummyCli()
     cli_ctx.cloud = mock_cloud
     images = load_images_from_aliases_doc(cli_ctx)
     self.assertEqual(images[0], {'urnAlias': 'CentOS', 'publisher': 'OpenLogic',
                                  'offer': 'CentOS', 'sku': '7.5', 'version': 'latest'})
Пример #12
0
 def test_get_api_version_invalid_active_profile(self):
     # The active profile is not in our profile dict
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='not-a-real-profile')
     test_profile = {
         '2017-01-01-profile': {
             ResourceType.MGMT_STORAGE: '2020-10-10'
         }
     }
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES',
                     test_profile):
         with self.assertRaises(APIVersionException):
             get_api_version(cli, ResourceType.MGMT_STORAGE)
Пример #13
0
 def test_get_api_version_semver(self):
     # Can get correct resource type API version if semver used
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {
         '2017-01-01-profile': {
             ResourceType.MGMT_KEYVAULT: '7.0'
         }
     }
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES',
                     test_profile):
         self.assertEqual(get_api_version(cli, ResourceType.MGMT_KEYVAULT),
                          '7.0')
Пример #14
0
 def test_get_api_version_invalid_rt_2(self):
     # None is not a valid resource type
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {
         '2017-01-01-profile': {
             ResourceType.MGMT_STORAGE: '2020-10-10'
         }
     }
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES',
                     test_profile):
         with self.assertRaises(APIVersionException):
             get_api_version(cli, None)
Пример #15
0
 def test_get_api_version(self):
     # Can get correct resource type API version
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {
         '2017-01-01-profile': {
             ResourceType.MGMT_STORAGE: '2020-10-10'
         }
     }
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES',
                     test_profile):
         self.assertEqual(get_api_version(cli, ResourceType.MGMT_STORAGE),
                          '2020-10-10')
Пример #16
0
 def test_supported_api_version_invalid_rt_for_profile(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {
         '2017-01-01-profile': {
             ResourceType.MGMT_STORAGE: '2020-10-10'
         }
     }
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES',
                     test_profile):
         with self.assertRaises(APIVersionException):
             supported_api_version(cli,
                                   ResourceType.MGMT_COMPUTE,
                                   min_api='2020-01-01')
Пример #17
0
 def test_supported_api_version_preview_constraint(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {
         '2017-01-01-profile': {
             ResourceType.MGMT_STORAGE: '2020-10-10-preview'
         }
     }
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES',
                     test_profile):
         self.assertTrue(
             supported_api_version(cli,
                                   ResourceType.MGMT_STORAGE,
                                   min_api='2020-01-01'))
Пример #18
0
 def test_supported_api_version_min_constraint_not_supported_semver(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {
         '2017-01-01-profile': {
             ResourceType.MGMT_KEYVAULT: '7.0'
         }
     }
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES',
                     test_profile):
         self.assertFalse(
             supported_api_version(cli,
                                   ResourceType.MGMT_KEYVAULT,
                                   min_api='8.0'))
Пример #19
0
 def test_supported_api_version_invalid_profile_name(self):
     # Invalid name for the profile name
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='not-a-real-profile')
     with self.assertRaises(ValueError):
         supported_api_version(cli, PROFILE_TYPE, min_api='2000-01-01')
Пример #20
0
 def test_supported_api_profile_max_constraint_not_supported(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2000-01-01-profile')
     self.assertFalse(supported_api_version(cli, PROFILE_TYPE, max_api='1999-12-30'))
Пример #21
0
 def test_supported_api_profile_latest(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='latest')
     self.assertTrue(
         supported_api_version(cli, PROFILE_TYPE, min_api='2000-01-01'))
Пример #22
0
 def test_supported_api_version_min_constraint_not_supported_mixed_type(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
     test_profile = {'2017-01-01-profile': {ResourceType.MGMT_STORAGE: '2016-06-04'}}
     with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
         self.assertFalse(supported_api_version(cli, ResourceType.MGMT_STORAGE, min_api='8.0'))
Пример #23
0
 def test_supported_api_profile_max_constraint_not_supported(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2000-01-01-profile')
     self.assertFalse(
         supported_api_version(cli, PROFILE_TYPE, max_api='1999-12-30'))
Пример #24
0
 def test_supported_api_version_invalid_profile_name(self):
     # Invalid name for the profile name
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='not-a-real-profile')
     with self.assertRaises(ValueError):
         supported_api_version(cli, PROFILE_TYPE, min_api='2000-01-01')
Пример #25
0
 def test_supported_api_profile_preview_constraint_in_profile(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2000-01-01-profile-preview')
     self.assertFalse(supported_api_version(cli, PROFILE_TYPE, min_api='2000-01-01'))
Пример #26
0
 def test_endpoint_none(self):
     with self.assertRaises(CloudEndpointNotSetException):
         cli = DummyCli()
         cli.cloud = Cloud('AzureCloud')
         profile = Profile(cli_ctx=cli)
         profile.get_login_credentials()
Пример #27
0
 def test_supported_api_profile_min_max_constraint(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='2000-01-01-profile')
     self.assertTrue(supported_api_version(cli, PROFILE_TYPE, min_api='2000-01-01', max_api='2000-01-01'))
Пример #28
0
 def test_endpoint_none(self):
     with self.assertRaises(CloudEndpointNotSetException):
         cli = DummyCli()
         cli.cloud = Cloud('AzureCloud')
         profile = Profile(cli_ctx=cli)
         profile.get_login_credentials()
Пример #29
0
 def test_supported_api_profile_latest(self):
     cli = DummyCli()
     cli.cloud = Cloud('TestCloud', profile='latest')
     self.assertTrue(supported_api_version(cli, PROFILE_TYPE, min_api='2000-01-01'))