Skip to content

Commit 7738969

Browse files
azure-sdkmsyyc
andauthored
[multiapi combiner] fix for api version validation (Azure#30881)
* fix * Fix * update --------- Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
1 parent d1e926a commit 7738969

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

sdk/compute/azure-mgmt-compute/tests/test_mgmt_api_version.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def test_api_version(self):
2525
# expect to raise error when method signatue is not supported for the api version
2626
client = self.client(api_version="2016-04-30-preview")
2727
signature = inspect.signature(client.availability_sets.list_by_subscription)
28-
assert not ("expand" in signature.parameters.keys())
29-
30-
28+
result = "expand" in signature.parameters.keys()
29+
try:
30+
# old package structure
31+
assert result == False
32+
except AssertionError:
33+
# new package structure
34+
with pytest.raises(ValueError):
35+
client.availability_sets.list_by_subscription(expand="fake_expand")

tools/azure-sdk-tools/packaging_tools/templates/multiapi_combiner/validation.py.jinja2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ def api_version_validation(**kwargs):
1616
def wrapper(*args, **kwargs):
1717
func_name = func.__name__
1818
try:
19+
client = args[0]
1920
client_api_version = client._get_api_version(func_name) # pylint: disable=protected-access
2021
except AttributeError:
21-
client_api_version = client._api_version
22+
client_api_version = client._api_version # pylint: disable=protected-access
2223

23-
if client_api_version not in method_valid_on:
24+
if method_valid_on and client_api_version not in method_valid_on:
2425
raise ValueError(
2526
f"'{func_name}' is not available in API version "
2627
f"{client_api_version}. All valid API version are {', '.join(method_valid_on)}."

0 commit comments

Comments
 (0)