@typespec/http-client-python 0.12.2 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +6 -0
  2. package/dist/emitter/emitter.d.ts.map +1 -1
  3. package/dist/emitter/emitter.js +1 -0
  4. package/dist/emitter/emitter.js.map +1 -1
  5. package/dist/emitter/http.js +1 -1
  6. package/dist/emitter/http.js.map +1 -1
  7. package/dist/emitter/lib.d.ts.map +1 -1
  8. package/dist/emitter/lib.js +5 -0
  9. package/dist/emitter/lib.js.map +1 -1
  10. package/dist/emitter/types.d.ts.map +1 -1
  11. package/dist/emitter/types.js +13 -5
  12. package/dist/emitter/types.js.map +1 -1
  13. package/dist/emitter/utils.d.ts +1 -0
  14. package/dist/emitter/utils.d.ts.map +1 -1
  15. package/dist/emitter/utils.js +1 -0
  16. package/dist/emitter/utils.js.map +1 -1
  17. package/emitter/src/emitter.ts +1 -0
  18. package/emitter/src/http.ts +1 -1
  19. package/emitter/src/lib.ts +6 -0
  20. package/emitter/src/types.ts +15 -7
  21. package/emitter/src/utils.ts +2 -0
  22. package/emitter/temp/tsconfig.tsbuildinfo +1 -1
  23. package/eng/scripts/ci/regenerate.ts +3 -0
  24. package/eng/scripts/setup/__pycache__/venvtools.cpython-39.pyc +0 -0
  25. package/generator/build/lib/pygen/codegen/__init__.py +5 -0
  26. package/generator/build/lib/pygen/codegen/models/operation.py +3 -1
  27. package/generator/build/lib/pygen/codegen/models/parameter.py +1 -0
  28. package/generator/build/lib/pygen/codegen/models/property.py +6 -0
  29. package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +2 -0
  30. package/generator/build/lib/pygen/codegen/serializers/metadata_serializer.py +1 -1
  31. package/generator/build/lib/pygen/codegen/templates/validation.py.jinja2 +18 -2
  32. package/generator/build/lib/pygen/preprocess/__init__.py +1 -2
  33. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  34. package/generator/pygen/codegen/__init__.py +5 -0
  35. package/generator/pygen/codegen/models/operation.py +3 -1
  36. package/generator/pygen/codegen/models/parameter.py +1 -0
  37. package/generator/pygen/codegen/models/property.py +6 -0
  38. package/generator/pygen/codegen/serializers/builder_serializer.py +2 -0
  39. package/generator/pygen/codegen/serializers/metadata_serializer.py +1 -1
  40. package/generator/pygen/codegen/templates/validation.py.jinja2 +18 -2
  41. package/generator/pygen/preprocess/__init__.py +1 -2
  42. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_commonproperties_async.py +31 -0
  43. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_largeheader_async.py +30 -0
  44. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_nonresource_async.py +36 -0
  45. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_initialization_async.py +9 -0
  46. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_deserialize_empty_string_as_null_async.py +20 -0
  47. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_usage_async.py +7 -0
  48. package/generator/test/azure/mock_api_tests/asynctests/test_azure_encode_duration_async.py +19 -0
  49. package/generator/test/azure/mock_api_tests/test_azure_arm_commonproperties.py +29 -0
  50. package/generator/test/azure/mock_api_tests/test_azure_arm_largeheader.py +27 -0
  51. package/generator/test/azure/mock_api_tests/test_azure_arm_nonresource.py +34 -0
  52. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_initialization.py +8 -0
  53. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_deserialize_empty_string_as_null.py +19 -0
  54. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_usage.py +4 -0
  55. package/generator/test/azure/mock_api_tests/test_azure_encode_duration.py +18 -0
  56. package/generator/test/azure/requirements.txt +4 -0
  57. package/package.json +3 -3
  58. /package/generator/test/azure/mock_api_tests/{test_resiliency_srv_driven_async.py → asynctests/test_resiliency_srv_driven_async.py} +0 -0
@@ -275,7 +275,9 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
275
275
  @property
276
276
  def need_validation(self) -> bool:
277
277
  """Whether we need parameter / operation validation. For API version."""
278
- return bool(self.added_on) or any(p for p in self.parameters if p.added_on)
278
+ return self.code_model.options["validate_versioning"] and (
279
+ bool(self.added_on) or any(p for p in self.parameters if p.added_on)
280
+ )
279
281
 
280
282
  def get_request_builder_import(
281
283
  self,
@@ -81,6 +81,7 @@ class _ParameterBase(BaseModel, abc.ABC): # pylint: disable=too-many-instance-a
81
81
  self.grouper: bool = self.yaml_data.get("grouper", False)
82
82
  self.check_client_input: bool = self.yaml_data.get("checkClientInput", False)
83
83
  self.added_on: Optional[str] = self.yaml_data.get("addedOn")
84
+ self.api_versions: Optional[List[str]] = self.yaml_data.get("apiVersions", [])
84
85
  self.is_api_version: bool = self.yaml_data.get("isApiVersion", False)
85
86
  self.in_overload: bool = self.yaml_data.get("inOverload", False)
86
87
  self.default_to_unset_sentinel: bool = self.yaml_data.get("defaultToUnsetSentinel", False)
@@ -87,11 +87,17 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
87
87
  def is_enum_discriminator(self) -> bool:
88
88
  return self.is_discriminator and self.type.type == "enum"
89
89
 
90
+ @property
91
+ def is_combined_discriminator(self) -> bool:
92
+ return self.is_discriminator and self.type.type == "combined"
93
+
90
94
  @property
91
95
  def is_base_discriminator(self) -> bool:
92
96
  """If this discriminator is on the base model for polymorphic inheritance"""
93
97
  if self.is_enum_discriminator:
94
98
  return self.is_polymorphic and self.client_default_value is None
99
+ if self.is_combined_discriminator:
100
+ return True
95
101
  return self.is_discriminator and self.is_polymorphic and cast(ConstantType, self.type).value is None
96
102
 
97
103
  @property
@@ -607,6 +607,8 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
607
607
  if params_added_on:
608
608
  retval.append(f" params_added_on={dict(params_added_on)},")
609
609
  if retval:
610
+ if builder.api_versions:
611
+ retval.append(f" api_versions_list={builder.api_versions},")
610
612
  retval_str = "\n".join(retval)
611
613
  return f"@api_version_validation(\n{retval_str}\n)"
612
614
  return ""
@@ -48,7 +48,7 @@ def _json_serialize_imports(
48
48
  ],
49
49
  ],
50
50
  ],
51
- ]
51
+ ],
52
52
  ) -> str:
53
53
  if not imports:
54
54
  return ""
@@ -6,6 +6,22 @@ import functools
6
6
  def api_version_validation(**kwargs):
7
7
  params_added_on = kwargs.pop("params_added_on", {})
8
8
  method_added_on = kwargs.pop("method_added_on", "")
9
+ api_versions_list = kwargs.pop("api_versions_list", [])
10
+
11
+ def _index_with_default(value: str, default: int = -1) -> int:
12
+ """Get the index of value in lst, or return default if not found.
13
+
14
+ :param value: The value to search for in the api_versions_list.
15
+ :type value: str
16
+ :param default: The default value to return if the value is not found.
17
+ :type default: int
18
+ :return: The index of the value in the list, or the default value if not found.
19
+ :rtype: int
20
+ """
21
+ try:
22
+ return api_versions_list.index(value)
23
+ except ValueError:
24
+ return default
9
25
 
10
26
  def decorator(func):
11
27
  @functools.wraps(func)
@@ -17,7 +33,7 @@ def api_version_validation(**kwargs):
17
33
  except AttributeError:
18
34
  return func(*args, **kwargs)
19
35
 
20
- if method_added_on > client_api_version:
36
+ if _index_with_default(method_added_on) > _index_with_default(client_api_version):
21
37
  raise ValueError(
22
38
  f"'{func.__name__}' is not available in API version "
23
39
  f"{client_api_version}. Pass service API version {method_added_on} or newer to your client."
@@ -27,7 +43,7 @@ def api_version_validation(**kwargs):
27
43
  parameter: api_version
28
44
  for api_version, parameters in params_added_on.items()
29
45
  for parameter in parameters
30
- if parameter in kwargs and api_version > client_api_version
46
+ if parameter in kwargs and _index_with_default(api_version) > _index_with_default(client_api_version)
31
47
  }
32
48
  if unsupported:
33
49
  raise ValueError("".join([
@@ -3,8 +3,7 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- """The preprocessing autorest plugin.
7
- """
6
+ """The preprocessing autorest plugin."""
8
7
  import copy
9
8
  from typing import Callable, Dict, Any, List, Optional
10
9
 
@@ -109,6 +109,10 @@ class OptionsRetriever:
109
109
  def package_pprint_name(self) -> str:
110
110
  return self.options.get("package-pprint-name") or _default_pprint(str(self.package_name))
111
111
 
112
+ @property
113
+ def validate_versioning(self) -> bool:
114
+ return self.options.get("validate-versioning", True)
115
+
112
116
  @property
113
117
  def default_optional_constants_to_none(self) -> bool:
114
118
  return self.options.get(
@@ -301,6 +305,7 @@ class CodeGenerator(Plugin):
301
305
  "from_typespec",
302
306
  "flavor",
303
307
  "emit_cross_language_definition_file",
308
+ "validate_versioning",
304
309
  ]
305
310
  return {f: getattr(self.options_retriever, f) for f in flags}
306
311
 
@@ -275,7 +275,9 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
275
275
  @property
276
276
  def need_validation(self) -> bool:
277
277
  """Whether we need parameter / operation validation. For API version."""
278
- return bool(self.added_on) or any(p for p in self.parameters if p.added_on)
278
+ return self.code_model.options["validate_versioning"] and (
279
+ bool(self.added_on) or any(p for p in self.parameters if p.added_on)
280
+ )
279
281
 
280
282
  def get_request_builder_import(
281
283
  self,
@@ -81,6 +81,7 @@ class _ParameterBase(BaseModel, abc.ABC): # pylint: disable=too-many-instance-a
81
81
  self.grouper: bool = self.yaml_data.get("grouper", False)
82
82
  self.check_client_input: bool = self.yaml_data.get("checkClientInput", False)
83
83
  self.added_on: Optional[str] = self.yaml_data.get("addedOn")
84
+ self.api_versions: Optional[List[str]] = self.yaml_data.get("apiVersions", [])
84
85
  self.is_api_version: bool = self.yaml_data.get("isApiVersion", False)
85
86
  self.in_overload: bool = self.yaml_data.get("inOverload", False)
86
87
  self.default_to_unset_sentinel: bool = self.yaml_data.get("defaultToUnsetSentinel", False)
@@ -87,11 +87,17 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
87
87
  def is_enum_discriminator(self) -> bool:
88
88
  return self.is_discriminator and self.type.type == "enum"
89
89
 
90
+ @property
91
+ def is_combined_discriminator(self) -> bool:
92
+ return self.is_discriminator and self.type.type == "combined"
93
+
90
94
  @property
91
95
  def is_base_discriminator(self) -> bool:
92
96
  """If this discriminator is on the base model for polymorphic inheritance"""
93
97
  if self.is_enum_discriminator:
94
98
  return self.is_polymorphic and self.client_default_value is None
99
+ if self.is_combined_discriminator:
100
+ return True
95
101
  return self.is_discriminator and self.is_polymorphic and cast(ConstantType, self.type).value is None
96
102
 
97
103
  @property
@@ -607,6 +607,8 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
607
607
  if params_added_on:
608
608
  retval.append(f" params_added_on={dict(params_added_on)},")
609
609
  if retval:
610
+ if builder.api_versions:
611
+ retval.append(f" api_versions_list={builder.api_versions},")
610
612
  retval_str = "\n".join(retval)
611
613
  return f"@api_version_validation(\n{retval_str}\n)"
612
614
  return ""
@@ -48,7 +48,7 @@ def _json_serialize_imports(
48
48
  ],
49
49
  ],
50
50
  ],
51
- ]
51
+ ],
52
52
  ) -> str:
53
53
  if not imports:
54
54
  return ""
@@ -6,6 +6,22 @@ import functools
6
6
  def api_version_validation(**kwargs):
7
7
  params_added_on = kwargs.pop("params_added_on", {})
8
8
  method_added_on = kwargs.pop("method_added_on", "")
9
+ api_versions_list = kwargs.pop("api_versions_list", [])
10
+
11
+ def _index_with_default(value: str, default: int = -1) -> int:
12
+ """Get the index of value in lst, or return default if not found.
13
+
14
+ :param value: The value to search for in the api_versions_list.
15
+ :type value: str
16
+ :param default: The default value to return if the value is not found.
17
+ :type default: int
18
+ :return: The index of the value in the list, or the default value if not found.
19
+ :rtype: int
20
+ """
21
+ try:
22
+ return api_versions_list.index(value)
23
+ except ValueError:
24
+ return default
9
25
 
10
26
  def decorator(func):
11
27
  @functools.wraps(func)
@@ -17,7 +33,7 @@ def api_version_validation(**kwargs):
17
33
  except AttributeError:
18
34
  return func(*args, **kwargs)
19
35
 
20
- if method_added_on > client_api_version:
36
+ if _index_with_default(method_added_on) > _index_with_default(client_api_version):
21
37
  raise ValueError(
22
38
  f"'{func.__name__}' is not available in API version "
23
39
  f"{client_api_version}. Pass service API version {method_added_on} or newer to your client."
@@ -27,7 +43,7 @@ def api_version_validation(**kwargs):
27
43
  parameter: api_version
28
44
  for api_version, parameters in params_added_on.items()
29
45
  for parameter in parameters
30
- if parameter in kwargs and api_version > client_api_version
46
+ if parameter in kwargs and _index_with_default(api_version) > _index_with_default(client_api_version)
31
47
  }
32
48
  if unsupported:
33
49
  raise ValueError("".join([
@@ -3,8 +3,7 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- """The preprocessing autorest plugin.
7
- """
6
+ """The preprocessing autorest plugin."""
8
7
  import copy
9
8
  from typing import Callable, Dict, Any, List, Optional
10
9
 
@@ -6,6 +6,7 @@
6
6
  import pytest
7
7
  from azure.resourcemanager.commonproperties.aio import CommonPropertiesClient
8
8
  from azure.resourcemanager.commonproperties import models
9
+ from azure.core import exceptions
9
10
 
10
11
  SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
11
12
  RESOURCE_GROUP_NAME = "test-rg"
@@ -61,3 +62,33 @@ async def test_managed_identity_update_with_user_assigned_and_system_assigned(cl
61
62
  assert result.location == "eastus"
62
63
  assert result.identity.type == "SystemAssigned,UserAssigned"
63
64
  assert result.properties.provisioning_state == "Succeeded"
65
+
66
+
67
+ @pytest.mark.asyncio
68
+ async def test_error_get_for_predefined_error(client):
69
+ try:
70
+ await client.error.get_for_predefined_error(
71
+ resource_group_name=RESOURCE_GROUP_NAME,
72
+ confidential_resource_name="confidential",
73
+ )
74
+ except exceptions.ResourceNotFoundError as e:
75
+ assert e.status_code == 404
76
+ assert (
77
+ e.error.message
78
+ == "The Resource 'Azure.ResourceManager.CommonProperties/confidentialResources/confidential' under resource group 'test-rg' was not found."
79
+ )
80
+
81
+
82
+ @pytest.mark.asyncio
83
+ async def test_error_create_for_user_defined_error(client):
84
+ try:
85
+ await client.error.create_for_user_defined_error(
86
+ resource_group_name=RESOURCE_GROUP_NAME,
87
+ confidential_resource_name="confidential",
88
+ resource=models.ConfidentialResource(
89
+ location="eastus", properties=models.ConfidentialResourceProperties(username="00")
90
+ ),
91
+ )
92
+ except exceptions.HttpResponseError as e:
93
+ assert e.status_code == 400
94
+ assert e.error.message == "Username should not contain only numbers."
@@ -0,0 +1,30 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+ import pytest
7
+ from azure.resourcemanager.largeheader.aio import LargeHeaderClient
8
+ from azure.resourcemanager.largeheader import models
9
+
10
+ SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
11
+ RESOURCE_GROUP_NAME = "test-rg"
12
+
13
+
14
+ @pytest.fixture
15
+ async def client(credential, authentication_policy):
16
+ async with LargeHeaderClient(
17
+ credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
18
+ ) as client:
19
+ yield client
20
+
21
+
22
+ @pytest.mark.asyncio
23
+ async def test_large_headers_begin_two6_k(client: LargeHeaderClient):
24
+ result = await (
25
+ await client.large_headers.begin_two6_k(
26
+ resource_group_name=RESOURCE_GROUP_NAME,
27
+ large_header_name="header1",
28
+ )
29
+ ).result()
30
+ assert result == models.CancelResult(succeeded=True)
@@ -0,0 +1,36 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+ import pytest
7
+ from azure.resourcemanager.nonresource.aio import NonResourceClient
8
+ from azure.resourcemanager.nonresource import models
9
+
10
+ SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
11
+ RESOURCE_GROUP_NAME = "test-rg"
12
+
13
+
14
+ @pytest.fixture
15
+ async def client(credential, authentication_policy):
16
+ async with NonResourceClient(
17
+ credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
18
+ ) as client:
19
+ yield client
20
+
21
+
22
+ @pytest.mark.asyncio
23
+ async def test_non_resource_create(client: NonResourceClient):
24
+ result = await client.non_resource_operations.create(
25
+ location="eastus", parameter="hello", body=models.NonResource(id="id", name="hello", type="nonResource")
26
+ )
27
+ assert result == models.NonResource(id="id", name="hello", type="nonResource")
28
+
29
+
30
+ @pytest.mark.asyncio
31
+ async def test_non_resource_get(client: NonResourceClient):
32
+ result = await client.non_resource_operations.get(
33
+ location="eastus",
34
+ parameter="hello",
35
+ )
36
+ assert result == models.NonResource(id="id", name="hello", type="nonResource")
@@ -10,6 +10,7 @@ from specs.azure.clientgenerator.core.clientinitialization.aio import (
10
10
  MixedParamsClient,
11
11
  PathParamClient,
12
12
  ParamAliasClient,
13
+ ParentClient,
13
14
  )
14
15
  from specs.azure.clientgenerator.core.clientinitialization.models import Input
15
16
 
@@ -48,3 +49,11 @@ async def test_param_alias_client():
48
49
  async with ParamAliasClient("sample-blob") as client:
49
50
  await client.with_aliased_name()
50
51
  await client.with_original_name()
52
+
53
+
54
+ # @pytest.mark.asyncio
55
+ # async def test_parent_child_client():
56
+ # async with ParentClient() as client:
57
+ # await client.child_client.with_query()
58
+ # await client.child_client.get_standalone()
59
+ # await client.child_client.delete_standalone()
@@ -0,0 +1,20 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+ import pytest
7
+ from specs.azure.clientgenerator.core.emptystring.aio import DeserializeEmptyStringAsNullClient
8
+ from specs.azure.clientgenerator.core.emptystring import models
9
+
10
+
11
+ @pytest.fixture
12
+ async def client():
13
+ async with DeserializeEmptyStringAsNullClient() as client:
14
+ yield client
15
+
16
+
17
+ @pytest.mark.asyncio
18
+ async def test_get(client: DeserializeEmptyStringAsNullClient):
19
+ result = await client.get()
20
+ assert result == models.ResponseModel(sample_url="")
@@ -29,3 +29,10 @@ async def test_model_usage(client: UsageClient):
29
29
  assert models.RoundTripModel(
30
30
  result=models.ResultModel(name="Madge")
31
31
  ) == await client.model_in_operation.model_in_read_only_property(body=models.RoundTripModel())
32
+
33
+
34
+ # @pytest.mark.asyncio
35
+ # async def test_orphan_model_serializable(client: UsageClient):
36
+ # await client.model_in_operation.orphan_model_serializable(
37
+ # body=models.OrphanModel(model_name="name", description="desc")
38
+ # )
@@ -0,0 +1,19 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+ import pytest
7
+ from specs.azure.encode.duration.aio import DurationClient
8
+ from specs.azure.encode.duration import models
9
+
10
+
11
+ @pytest.fixture
12
+ async def client():
13
+ async with DurationClient() as client:
14
+ yield client
15
+
16
+
17
+ @pytest.mark.asyncio
18
+ async def test_duration_constant(client: DurationClient):
19
+ await client.duration_constant(models.DurationModel(input="1.02:59:59.5000000"))
@@ -6,6 +6,7 @@
6
6
  import pytest
7
7
  from azure.resourcemanager.commonproperties import CommonPropertiesClient
8
8
  from azure.resourcemanager.commonproperties import models
9
+ from azure.core import exceptions
9
10
 
10
11
  SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
11
12
  RESOURCE_GROUP_NAME = "test-rg"
@@ -58,3 +59,31 @@ def test_managed_identity_update_with_user_assigned_and_system_assigned(client):
58
59
  assert result.location == "eastus"
59
60
  assert result.identity.type == "SystemAssigned,UserAssigned"
60
61
  assert result.properties.provisioning_state == "Succeeded"
62
+
63
+
64
+ def test_error_get_for_predefined_error(client):
65
+ try:
66
+ client.error.get_for_predefined_error(
67
+ resource_group_name=RESOURCE_GROUP_NAME,
68
+ confidential_resource_name="confidential",
69
+ )
70
+ except exceptions.ResourceNotFoundError as e:
71
+ assert e.status_code == 404
72
+ assert (
73
+ e.error.message
74
+ == "The Resource 'Azure.ResourceManager.CommonProperties/confidentialResources/confidential' under resource group 'test-rg' was not found."
75
+ )
76
+
77
+
78
+ def test_error_create_for_user_defined_error(client):
79
+ try:
80
+ client.error.create_for_user_defined_error(
81
+ resource_group_name=RESOURCE_GROUP_NAME,
82
+ confidential_resource_name="confidential",
83
+ resource=models.ConfidentialResource(
84
+ location="eastus", properties=models.ConfidentialResourceProperties(username="00")
85
+ ),
86
+ )
87
+ except exceptions.HttpResponseError as e:
88
+ assert e.status_code == 400
89
+ assert e.error.message == "Username should not contain only numbers."
@@ -0,0 +1,27 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+ import pytest
7
+ from azure.resourcemanager.largeheader import LargeHeaderClient
8
+ from azure.resourcemanager.largeheader import models
9
+
10
+ SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
11
+ RESOURCE_GROUP_NAME = "test-rg"
12
+
13
+
14
+ @pytest.fixture
15
+ def client(credential, authentication_policy):
16
+ with LargeHeaderClient(
17
+ credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
18
+ ) as client:
19
+ yield client
20
+
21
+
22
+ def test_large_headers_begin_two6_k(client: LargeHeaderClient):
23
+ result = client.large_headers.begin_two6_k(
24
+ resource_group_name=RESOURCE_GROUP_NAME,
25
+ large_header_name="header1",
26
+ ).result()
27
+ assert result == models.CancelResult(succeeded=True)
@@ -0,0 +1,34 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+ import pytest
7
+ from azure.resourcemanager.nonresource import NonResourceClient
8
+ from azure.resourcemanager.nonresource import models
9
+
10
+ SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
11
+ RESOURCE_GROUP_NAME = "test-rg"
12
+
13
+
14
+ @pytest.fixture
15
+ def client(credential, authentication_policy):
16
+ with NonResourceClient(
17
+ credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
18
+ ) as client:
19
+ yield client
20
+
21
+
22
+ def test_non_resource_create(client: NonResourceClient):
23
+ result = client.non_resource_operations.create(
24
+ location="eastus", parameter="hello", body=models.NonResource(id="id", name="hello", type="nonResource")
25
+ )
26
+ assert result == models.NonResource(id="id", name="hello", type="nonResource")
27
+
28
+
29
+ def test_non_resource_get(client: NonResourceClient):
30
+ result = client.non_resource_operations.get(
31
+ location="eastus",
32
+ parameter="hello",
33
+ )
34
+ assert result == models.NonResource(id="id", name="hello", type="nonResource")
@@ -9,6 +9,7 @@ from specs.azure.clientgenerator.core.clientinitialization import (
9
9
  MixedParamsClient,
10
10
  PathParamClient,
11
11
  ParamAliasClient,
12
+ ParentClient,
12
13
  )
13
14
  from specs.azure.clientgenerator.core.clientinitialization.models import Input
14
15
 
@@ -42,3 +43,10 @@ def test_param_alias_client():
42
43
  with ParamAliasClient("sample-blob") as client:
43
44
  client.with_aliased_name()
44
45
  client.with_original_name()
46
+
47
+
48
+ # def test_parent_child_client():
49
+ # with ParentClient() as client:
50
+ # client.child_client.with_query()
51
+ # client.child_client.get_standalone()
52
+ # client.child_client.delete_standalone()
@@ -0,0 +1,19 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+ import pytest
7
+ from specs.azure.clientgenerator.core.emptystring import DeserializeEmptyStringAsNullClient
8
+ from specs.azure.clientgenerator.core.emptystring import models
9
+
10
+
11
+ @pytest.fixture
12
+ def client():
13
+ with DeserializeEmptyStringAsNullClient() as client:
14
+ yield client
15
+
16
+
17
+ def test_get(client: DeserializeEmptyStringAsNullClient):
18
+ result = client.get()
19
+ assert result == models.ResponseModel(sample_url="")
@@ -26,3 +26,7 @@ def test_model_usage(client: UsageClient):
26
26
  assert models.RoundTripModel(
27
27
  result=models.ResultModel(name="Madge")
28
28
  ) == client.model_in_operation.model_in_read_only_property(body=models.RoundTripModel())
29
+
30
+
31
+ # def test_orphan_model_serializable(client: UsageClient):
32
+ # client.model_in_operation.orphan_model_serializable(body=models.OrphanModel(model_name="name", description="desc"))
@@ -0,0 +1,18 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+ import pytest
7
+ from specs.azure.encode.duration import DurationClient
8
+ from specs.azure.encode.duration import models
9
+
10
+
11
+ @pytest.fixture
12
+ def client():
13
+ with DurationClient() as client:
14
+ yield client
15
+
16
+
17
+ def test_duration_constant(client: DurationClient):
18
+ client.duration_constant(models.DurationModel(input="1.02:59:59.5000000"))
@@ -5,6 +5,7 @@ azure-mgmt-core==1.5.0
5
5
  # only for azure
6
6
  -e ./generated/azure-client-generator-core-access
7
7
  -e ./generated/azure-client-generator-core-client-initialization
8
+ -e ./generated/azure-client-generator-core-deserialize-empty-string-as-null
8
9
  -e ./generated/azure-client-generator-core-flatten-property
9
10
  -e ./generated/azure-client-generator-core-usage
10
11
  -e ./generated/azure-core-basic
@@ -14,9 +15,12 @@ azure-mgmt-core==1.5.0
14
15
  -e ./generated/azure-core-model
15
16
  -e ./generated/azure-core-traits
16
17
  -e ./generated/azure-core-page
18
+ -e ./generated/azure-encode-duration
17
19
  -e ./generated/azure-special-headers-client-request-id/
18
20
  -e ./generated/azure-example-basic
19
21
  -e ./generated/azure-resource-manager-common-properties
22
+ -e ./generated/azure-resource-manager-large-header
23
+ -e ./generated/azure-resource-manager-non-resource
20
24
  -e ./generated/azure-resource-manager-operation-templates
21
25
  -e ./generated/azure-resource-manager-resources
22
26
  # -e ./generated/client-namespace
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-python",
3
- "version": "0.12.2",
3
+ "version": "0.12.4",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec emitter for Python SDKs",
6
6
  "homepage": "https://typespec.io",
@@ -81,8 +81,8 @@
81
81
  "@azure-tools/typespec-azure-core": "~0.57.0",
82
82
  "@azure-tools/typespec-azure-resource-manager": "~0.57.0",
83
83
  "@azure-tools/typespec-azure-rulesets": "~0.57.0",
84
- "@azure-tools/typespec-client-generator-core": "~0.57.1",
85
- "@azure-tools/azure-http-specs": "0.1.0-alpha.19",
84
+ "@azure-tools/typespec-client-generator-core": "~0.57.2",
85
+ "@azure-tools/azure-http-specs": "0.1.0-alpha.20",
86
86
  "@typespec/compiler": "^1.1.0",
87
87
  "@typespec/http": "^1.1.0",
88
88
  "@typespec/openapi": "^1.1.0",