Skip to content

Commit eef4a76

Browse files
committed
adding in none
1 parent 77ef1c5 commit eef4a76

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/azure-cli-core/azure/cli/core/profiles/_shared.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ def supported_api_version(api_profile, resource_type, min_api=None, max_api=None
427427
Returns True if current API version for the resource type satisfies min/max range.
428428
To compare profile versions, set resource type to None.
429429
Can return a tuple<operation_group, bool> if the resource_type supports SDKProfile.
430+
note: if the api_version for the given profile is None (inherrited from the SDK), returns True
431+
as there is no easy way to extract the api version.
430432
note: Currently supports YYYY-MM-DD, YYYY-MM-DD-preview, YYYY-MM-DD-profile
431433
or YYYY-MM-DD-profile-preview formatted strings.
432434
"""
@@ -438,6 +440,8 @@ def supported_api_version(api_profile, resource_type, min_api=None, max_api=None
438440
if isinstance(resource_type, (ResourceType, CustomResourceType)) else api_profile
439441
if isinstance(api_version_obj, SDKProfile):
440442
api_version_obj = api_version_obj.profile.get(operation_group or '', api_version_obj.default_api_version)
443+
if not api_version_obj:
444+
return True
441445
return _validate_api_version(api_version_obj, min_api, max_api)
442446

443447

src/azure-cli-core/azure/cli/core/tests/test_api_profiles.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ def test_supported_api_version_min_constraint_mixed_type(self):
133133
with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
134134
self.assertTrue(supported_api_version(cli, ResourceType.MGMT_KEYVAULT, min_api='2016-06-04'))
135135

136+
def test_supported_api_version_min_constraint_none(self):
137+
cli = DummyCli()
138+
cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
139+
test_profile = {'2017-01-01-profile': {ResourceType.MGMT_STORAGE: None}}
140+
with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
141+
self.assertTrue(supported_api_version(cli, ResourceType.MGMT_STORAGE, min_api='2000-01-01'))
142+
136143
def test_supported_api_version_max_constraint(self):
137144
cli = DummyCli()
138145
cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
@@ -154,6 +161,13 @@ def test_supported_api_version_max_constraint_mixed_type(self):
154161
with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
155162
self.assertTrue(supported_api_version(cli, ResourceType.MGMT_KEYVAULT, max_api='8.0'))
156163

164+
def test_supported_api_version_max_constraint_none(self):
165+
cli = DummyCli()
166+
cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
167+
test_profile = {'2017-01-01-profile': {ResourceType.MGMT_STORAGE: None}}
168+
with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
169+
self.assertTrue(supported_api_version(cli, ResourceType.MGMT_STORAGE, max_api='2021-01-01'))
170+
157171
def test_supported_api_version_min_max_constraint(self):
158172
cli = DummyCli()
159173
cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
@@ -170,6 +184,14 @@ def test_supported_api_version_min_max_constraint_semver(self):
170184
self.assertTrue(
171185
supported_api_version(cli, ResourceType.MGMT_KEYVAULT, min_api='6.0', max_api='8.0'))
172186

187+
def test_supported_api_version_min_max_constraint_none(self):
188+
cli = DummyCli()
189+
cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')
190+
test_profile = {'2017-01-01-profile': {ResourceType.MGMT_STORAGE: None}}
191+
with mock.patch('azure.cli.core.profiles._shared.AZURE_API_PROFILES', test_profile):
192+
self.assertTrue(
193+
supported_api_version(cli, ResourceType.MGMT_STORAGE, min_api='2000-01-01', max_api='2021-01-01'))
194+
173195
def test_supported_api_version_max_constraint_not_supported(self):
174196
cli = DummyCli()
175197
cli.cloud = Cloud('TestCloud', profile='2017-01-01-profile')

0 commit comments

Comments
 (0)