@typespec/http-client-python 0.23.1 → 0.24.1

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 (81) hide show
  1. package/dist/emitter/code-model.d.ts.map +1 -1
  2. package/dist/emitter/code-model.js +40 -25
  3. package/dist/emitter/code-model.js.map +1 -1
  4. package/dist/emitter/http.d.ts +4 -4
  5. package/dist/emitter/http.d.ts.map +1 -1
  6. package/dist/emitter/http.js +41 -35
  7. package/dist/emitter/http.js.map +1 -1
  8. package/dist/emitter/types.d.ts +1 -1
  9. package/dist/emitter/types.d.ts.map +1 -1
  10. package/dist/emitter/types.js +2 -2
  11. package/dist/emitter/types.js.map +1 -1
  12. package/dist/emitter/utils.d.ts +2 -2
  13. package/dist/emitter/utils.d.ts.map +1 -1
  14. package/dist/emitter/utils.js +7 -6
  15. package/dist/emitter/utils.js.map +1 -1
  16. package/emitter/src/code-model.ts +65 -18
  17. package/emitter/src/http.ts +107 -22
  18. package/emitter/src/types.ts +2 -1
  19. package/emitter/src/utils.ts +11 -9
  20. package/emitter/temp/tsconfig.tsbuildinfo +1 -1
  21. package/eng/scripts/ci/dev_requirements.txt +3 -3
  22. package/eng/scripts/ci/pylintrc +1 -1
  23. package/eng/scripts/ci/regenerate.ts +8 -1
  24. package/eng/scripts/setup/__pycache__/package_manager.cpython-311.pyc +0 -0
  25. package/eng/scripts/setup/__pycache__/venvtools.cpython-311.pyc +0 -0
  26. package/generator/build/lib/pygen/codegen/models/code_model.py +4 -0
  27. package/generator/build/lib/pygen/codegen/models/enum_type.py +8 -1
  28. package/generator/build/lib/pygen/codegen/models/list_type.py +6 -2
  29. package/generator/build/lib/pygen/codegen/models/model_type.py +2 -2
  30. package/generator/build/lib/pygen/codegen/models/operation.py +10 -1
  31. package/generator/build/lib/pygen/codegen/models/operation_group.py +3 -1
  32. package/generator/build/lib/pygen/codegen/models/request_builder.py +20 -3
  33. package/generator/build/lib/pygen/codegen/models/response.py +2 -2
  34. package/generator/build/lib/pygen/codegen/models/utils.py +7 -0
  35. package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +20 -11
  36. package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +1 -2
  37. package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +1 -1
  38. package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +3 -0
  39. package/generator/build/lib/pygen/codegen/templates/enum.py.jinja2 +3 -1
  40. package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +10 -7
  41. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  42. package/generator/pygen/codegen/models/code_model.py +4 -0
  43. package/generator/pygen/codegen/models/enum_type.py +8 -1
  44. package/generator/pygen/codegen/models/list_type.py +6 -2
  45. package/generator/pygen/codegen/models/model_type.py +2 -2
  46. package/generator/pygen/codegen/models/operation.py +10 -1
  47. package/generator/pygen/codegen/models/operation_group.py +3 -1
  48. package/generator/pygen/codegen/models/request_builder.py +20 -3
  49. package/generator/pygen/codegen/models/response.py +2 -2
  50. package/generator/pygen/codegen/models/utils.py +7 -0
  51. package/generator/pygen/codegen/serializers/builder_serializer.py +20 -11
  52. package/generator/pygen/codegen/serializers/client_serializer.py +1 -2
  53. package/generator/pygen/codegen/serializers/general_serializer.py +1 -1
  54. package/generator/pygen/codegen/serializers/model_serializer.py +3 -0
  55. package/generator/pygen/codegen/templates/enum.py.jinja2 +3 -1
  56. package/generator/pygen/codegen/templates/model_base.py.jinja2 +10 -7
  57. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py +17 -0
  58. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_default_value_async.py +46 -0
  59. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_location_async.py +48 -21
  60. package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_multi_service_async.py +110 -0
  61. package/generator/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py +33 -0
  62. package/generator/test/azure/mock_api_tests/asynctests/test_service_multi_service_async.py +31 -0
  63. package/generator/test/azure/mock_api_tests/asynctests/test_special_words_async.py +18 -0
  64. package/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py +15 -0
  65. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_default_value.py +42 -0
  66. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_location.py +44 -19
  67. package/generator/test/azure/mock_api_tests/test_azure_resource_manager_multi_service.py +104 -0
  68. package/generator/test/azure/mock_api_tests/test_payload_multipart.py +31 -0
  69. package/generator/test/azure/mock_api_tests/test_service_multi_service.py +29 -0
  70. package/generator/test/azure/mock_api_tests/test_special_words.py +17 -0
  71. package/generator/test/azure/requirements.txt +10 -1
  72. package/generator/test/generic_mock_api_tests/asynctests/test_parameters_query_async.py +18 -0
  73. package/generator/test/generic_mock_api_tests/test_parameters_query.py +17 -0
  74. package/generator/test/generic_mock_api_tests/test_typetest_scalar.py +0 -5
  75. package/generator/test/generic_mock_api_tests/test_typetest_union_discriminated.py +290 -0
  76. package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_multipart_async.py +33 -0
  77. package/generator/test/unbranded/mock_api_tests/test_payload_multipart.py +31 -0
  78. package/generator/test/unbranded/mock_api_tests/test_unbranded.py +8 -3
  79. package/generator/test/unbranded/requirements.txt +3 -0
  80. package/generator/test/unittests/test_model_base_serialization.py +66 -0
  81. package/package.json +33 -33
@@ -781,8 +781,14 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
781
781
  client_names = [
782
782
  overload.request_builder.parameters.body_parameter.client_name for overload in builder.overloads
783
783
  ]
784
- for v in sorted(set(client_names), key=client_names.index):
785
- retval.append(f"_{v} = None")
784
+ all_dpg_model_overloads = False
785
+ if self.code_model.options["models-mode"] == "dpg" and builder.overloads:
786
+ all_dpg_model_overloads = all(
787
+ isinstance(o.parameters.body_parameter.type, DPGModelType) for o in builder.overloads
788
+ )
789
+ if not all_dpg_model_overloads:
790
+ for v in sorted(set(client_names), key=client_names.index):
791
+ retval.append(f"_{v} = None")
786
792
  try:
787
793
  # if there is a binary overload, we do a binary check first.
788
794
  binary_overload = cast(
@@ -808,17 +814,20 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
808
814
  f'"{other_overload.parameters.body_parameter.default_content_type}"{check_body_suffix}'
809
815
  )
810
816
  except StopIteration:
811
- for idx, overload in enumerate(builder.overloads):
812
- if_statement = "if" if idx == 0 else "elif"
813
- body_param = overload.parameters.body_parameter
814
- retval.append(
815
- f"{if_statement} {body_param.type.instance_check_template.format(body_param.client_name)}:"
816
- )
817
- if body_param.default_content_type and not same_content_type:
817
+ if all_dpg_model_overloads:
818
+ retval.extend(f"{l}" for l in self._create_body_parameter(cast(OperationType, builder.overloads[0])))
819
+ else:
820
+ for idx, overload in enumerate(builder.overloads):
821
+ if_statement = "if" if idx == 0 else "elif"
822
+ body_param = overload.parameters.body_parameter
818
823
  retval.append(
819
- f' content_type = content_type or "{body_param.default_content_type}"{check_body_suffix}'
824
+ f"{if_statement} {body_param.type.instance_check_template.format(body_param.client_name)}:"
820
825
  )
821
- retval.extend(f" {l}" for l in self._create_body_parameter(cast(OperationType, overload)))
826
+ if body_param.default_content_type and not same_content_type:
827
+ retval.append(
828
+ f' content_type = content_type or "{body_param.default_content_type}"{check_body_suffix}'
829
+ )
830
+ retval.extend(f" {l}" for l in self._create_body_parameter(cast(OperationType, overload)))
822
831
  return retval
823
832
 
824
833
  def _create_request_builder_call(
@@ -182,11 +182,10 @@ class ClientSerializer:
182
182
  retval.append("self._serialize.client_side_validation = False")
183
183
  operation_groups = [og for og in self.client.operation_groups if not og.is_mixin]
184
184
  for og in operation_groups:
185
- api_version = ""
186
185
  retval.extend(
187
186
  [
188
187
  f"self.{og.property_name} = {og.class_name}(",
189
- f" self._client, self._config, self._serialize, self._deserialize{api_version}",
188
+ " self._client, self._config, self._serialize, self._deserialize",
190
189
  ")",
191
190
  ]
192
191
  )
@@ -23,7 +23,7 @@ VERSION_MAP = {
23
23
  "msrest": "0.7.1",
24
24
  "isodate": "0.6.1",
25
25
  "azure-mgmt-core": "1.6.0",
26
- "azure-core": "1.36.0",
26
+ "azure-core": "1.37.0",
27
27
  "typing-extensions": "4.6.0",
28
28
  "corehttp": "1.0.0b6",
29
29
  }
@@ -285,6 +285,9 @@ class DpgModelSerializer(_ModelSerializer):
285
285
  file_import.add_submodule_import("typing", "overload", ImportType.STDLIB)
286
286
  file_import.add_submodule_import("typing", "Mapping", ImportType.STDLIB)
287
287
  file_import.add_submodule_import("typing", "Any", ImportType.STDLIB)
288
+ # if there is a property named `list` we have to make sure there's no conflict with the built-in `list`
289
+ if self.code_model.has_property_named_list:
290
+ file_import.define_mypy_type("List", "list")
288
291
  return file_import
289
292
 
290
293
  def declare_model(self, model: ModelType) -> str:
@@ -1,5 +1,7 @@
1
1
 
2
- class {{ enum.name }}({{ enum.value_type.type_annotation(is_operation_file=False) }}, Enum, metaclass=CaseInsensitiveEnumMeta):
2
+ class {{ enum.name }}({{enum.pylint_disable()}}
3
+ {{ enum.value_type.type_annotation(is_operation_file=False) }}, Enum, metaclass=CaseInsensitiveEnumMeta
4
+ ):
3
5
  {% if enum.yaml_data.get("description") %}
4
6
  """{{ op_tools.wrap_string(enum.yaml_data["description"], "\n ") }}
5
7
  """
@@ -36,6 +36,7 @@ __all__ = ["SdkJSONEncoder", "Model", "rest_field", "rest_discriminator"]
36
36
 
37
37
  TZ_UTC = timezone.utc
38
38
  _T = typing.TypeVar("_T")
39
+ _NONE_TYPE = type(None)
39
40
 
40
41
  {% if code_model.has_external_type %}
41
42
  TYPE_HANDLER_REGISTRY = TypeHandlerRegistry()
@@ -223,7 +224,7 @@ def _deserialize_datetime(attr: typing.Union[str, datetime]) -> datetime:
223
224
  test_utc = date_obj.utctimetuple()
224
225
  if test_utc.tm_year > 9999 or test_utc.tm_year < 1:
225
226
  raise OverflowError("Hit max or min date")
226
- return date_obj
227
+ return date_obj # type: ignore[no-any-return]
227
228
 
228
229
 
229
230
  def _deserialize_datetime_rfc7231(attr: typing.Union[str, datetime]) -> datetime:
@@ -277,7 +278,7 @@ def _deserialize_time(attr: typing.Union[str, time]) -> time:
277
278
  """
278
279
  if isinstance(attr, time):
279
280
  return attr
280
- return isodate.parse_time(attr)
281
+ return isodate.parse_time(attr) # type: ignore[no-any-return]
281
282
 
282
283
 
283
284
  def _deserialize_bytes(attr):
@@ -916,16 +917,16 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
916
917
 
917
918
  # is it optional?
918
919
  try:
919
- if any(a for a in annotation.__args__ if a == type(None)): # pyright: ignore
920
+ if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore
920
921
  if len(annotation.__args__) <= 2: # pyright: ignore
921
922
  if_obj_deserializer = _get_deserialize_callable_from_annotation(
922
- next(a for a in annotation.__args__ if a != type(None)), module, rf # pyright: ignore
923
+ next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore
923
924
  )
924
925
 
925
926
  return functools.partial(_deserialize_with_optional, if_obj_deserializer)
926
927
  # the type is Optional[Union[...]], we need to remove the None type from the Union
927
928
  annotation_copy = copy.copy(annotation)
928
- annotation_copy.__args__ = [a for a in annotation_copy.__args__ if a != type(None)] # pyright: ignore
929
+ annotation_copy.__args__ = [a for a in annotation_copy.__args__ if a is not _NONE_TYPE] # pyright: ignore
929
930
  return _get_deserialize_callable_from_annotation(annotation_copy, module, rf)
930
931
  except AttributeError:
931
932
  pass
@@ -1327,7 +1328,7 @@ def _get_wrapped_element(
1327
1328
  _get_element(v, exclude_readonly, meta, wrapped_element)
1328
1329
  else:
1329
1330
  wrapped_element.text = _get_primitive_type_value(v)
1330
- return wrapped_element
1331
+ return wrapped_element # type: ignore[no-any-return]
1331
1332
 
1332
1333
 
1333
1334
  def _get_primitive_type_value(v) -> str:
@@ -1340,7 +1341,9 @@ def _get_primitive_type_value(v) -> str:
1340
1341
  return str(v)
1341
1342
 
1342
1343
 
1343
- def _create_xml_element(tag, prefix=None, ns=None):
1344
+ def _create_xml_element(
1345
+ tag: typing.Any, prefix: typing.Optional[str] = None, ns: typing.Optional[str] = None
1346
+ ) -> ET.Element:
1344
1347
  if prefix and ns:
1345
1348
  ET.register_namespace(prefix, ns)
1346
1349
  if ns:
@@ -174,3 +174,20 @@ async def test_optional_body_provider_post_with_body(client):
174
174
  )
175
175
  assert result.total_allowed == 100
176
176
  assert result.status == "Changed to requested allowance"
177
+
178
+
179
+ @pytest.mark.asyncio
180
+ async def test_lro_paging_begin_post_paging_lro(client):
181
+ poller = await client.lro_paging.begin_post_paging_lro(
182
+ resource_group_name=RESOURCE_GROUP_NAME,
183
+ product_name="default",
184
+ )
185
+ result = await poller.result()
186
+ items = [item async for item in result]
187
+ assert len(items) == 2
188
+ assert items[0].name == "product1"
189
+ assert items[0].properties.product_id == "product1"
190
+ assert items[0].properties.provisioning_state == "Succeeded"
191
+ assert items[1].name == "product2"
192
+ assert items[1].properties.product_id == "product2"
193
+ assert items[1].properties.provisioning_state == "Succeeded"
@@ -0,0 +1,46 @@
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.clientdefaultvalue.aio import ClientDefaultValueClient
8
+ from specs.azure.clientgenerator.core.clientdefaultvalue.models import ModelWithDefaultValues
9
+
10
+
11
+ @pytest.fixture
12
+ async def client():
13
+ async with ClientDefaultValueClient() as client:
14
+ yield client
15
+
16
+
17
+ @pytest.mark.asyncio
18
+ async def test_put_model_property(client: ClientDefaultValueClient):
19
+ """Test case 1: @clientDefaultValue for model property."""
20
+ body = ModelWithDefaultValues(name="test")
21
+ result = await client.put_model_property(body=body)
22
+ assert result.name == "test"
23
+ assert result.timeout == 30
24
+ assert result.tier == "standard"
25
+ assert result.retry is True
26
+
27
+
28
+ @pytest.mark.asyncio
29
+ async def test_get_operation_parameter(client: ClientDefaultValueClient):
30
+ """Test case 2: @clientDefaultValue for operation parameter."""
31
+ # Test with only required parameter (name), defaults should be applied
32
+ await client.get_operation_parameter(name="test")
33
+
34
+
35
+ @pytest.mark.asyncio
36
+ async def test_get_path_parameter(client: ClientDefaultValueClient):
37
+ """Test case 3: @clientDefaultValue for first path segment."""
38
+ # Test with only required segment2, segment1 should use default
39
+ await client.get_path_parameter(segment2="segment2")
40
+
41
+
42
+ @pytest.mark.asyncio
43
+ async def test_get_header_parameter(client: ClientDefaultValueClient):
44
+ """Test case 4: @clientDefaultValue for header parameters."""
45
+ # Test with default header values
46
+ await client.get_header_parameter()
@@ -4,52 +4,79 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  import pytest
7
- from specs.azure.clientgenerator.core.clientlocation.aio import ClientLocationClient
7
+ from specs.azure.clientgenerator.core.clientlocation.parameter.aio import MoveMethodParameterToClient
8
+ from specs.azure.clientgenerator.core.clientlocation.subclient.aio import MoveToExistingSubClient
9
+ from specs.azure.clientgenerator.core.clientlocation.newsubclient.aio import MoveToNewSubClient
10
+ from specs.azure.clientgenerator.core.clientlocation.rootclient.aio import MoveToRootClient
8
11
 
9
12
 
10
13
  @pytest.fixture
11
- async def client():
12
- async with ClientLocationClient(storage_account="testaccount") as client:
14
+ async def move_method_parameter_to_client():
15
+ async with MoveMethodParameterToClient(storage_account="testaccount") as client:
16
+ yield client
17
+
18
+
19
+ @pytest.fixture
20
+ async def move_to_existing_sub_client():
21
+ async with MoveToExistingSubClient() as client:
22
+ yield client
23
+
24
+
25
+ @pytest.fixture
26
+ async def move_to_new_sub_client():
27
+ async with MoveToNewSubClient() as client:
28
+ yield client
29
+
30
+
31
+ @pytest.fixture
32
+ async def move_to_root_client():
33
+ async with MoveToRootClient() as client:
13
34
  yield client
14
35
 
15
36
 
16
37
  @pytest.mark.asyncio
17
- async def test_get_health_status(client: ClientLocationClient):
18
- await client.get_health_status()
38
+ async def test_move_method_parameter_to_client_blob_operations_get_blob(
39
+ move_method_parameter_to_client: MoveMethodParameterToClient,
40
+ ):
41
+ await move_method_parameter_to_client.blob_operations.get_blob(container="testcontainer", blob="testblob.txt")
19
42
 
20
43
 
21
44
  @pytest.mark.asyncio
22
- async def test_archive_operations_archive_product(client: ClientLocationClient):
23
- await client.archive_operations.archive_product()
45
+ async def test_move_to_existing_sub_client_user_operations_get_user(
46
+ move_to_existing_sub_client: MoveToExistingSubClient,
47
+ ):
48
+ await move_to_existing_sub_client.user_operations.get_user()
24
49
 
25
50
 
26
51
  @pytest.mark.asyncio
27
- async def test_move_to_existing_sub_client_admin_operations_get_admin_info(client: ClientLocationClient):
28
- await client.move_to_existing_sub_client.admin_operations.get_admin_info()
52
+ async def test_move_to_existing_sub_client_admin_operations_delete_user(
53
+ move_to_existing_sub_client: MoveToExistingSubClient,
54
+ ):
55
+ await move_to_existing_sub_client.admin_operations.delete_user()
29
56
 
30
57
 
31
58
  @pytest.mark.asyncio
32
- async def test_move_to_existing_sub_client_admin_operations_delete_user(client: ClientLocationClient):
33
- await client.move_to_existing_sub_client.admin_operations.delete_user()
59
+ async def test_move_to_existing_sub_client_admin_operations_get_admin_info(
60
+ move_to_existing_sub_client: MoveToExistingSubClient,
61
+ ):
62
+ await move_to_existing_sub_client.admin_operations.get_admin_info()
34
63
 
35
64
 
36
65
  @pytest.mark.asyncio
37
- async def test_move_to_existing_sub_client_user_operations_get_user(client: ClientLocationClient):
38
- await client.move_to_existing_sub_client.user_operations.get_user()
66
+ async def test_move_to_new_sub_client_product_operations_list_products(move_to_new_sub_client: MoveToNewSubClient):
67
+ await move_to_new_sub_client.product_operations.list_products()
39
68
 
40
69
 
41
70
  @pytest.mark.asyncio
42
- async def test_move_to_new_sub_client_product_operations_list_products(client: ClientLocationClient):
43
- await client.move_to_new_sub_client.product_operations.list_products()
71
+ async def test_move_to_new_sub_client_archive_operations_archive_product(move_to_new_sub_client: MoveToNewSubClient):
72
+ await move_to_new_sub_client.archive_operations.archive_product()
44
73
 
45
74
 
46
75
  @pytest.mark.asyncio
47
- async def test_move_to_root_client_resource_operations_get_resource(client: ClientLocationClient):
48
- await client.move_to_root_client.resource_operations.get_resource()
76
+ async def test_move_to_root_client_resource_operations_get_resource(move_to_root_client: MoveToRootClient):
77
+ await move_to_root_client.resource_operations.get_resource()
49
78
 
50
79
 
51
80
  @pytest.mark.asyncio
52
- async def test_move_method_parameter_to_client_blob_operations_get_blob(client: ClientLocationClient):
53
- await client.move_method_parameter_to_client.blob_operations.get_blob(
54
- container="testcontainer", blob="testblob.txt"
55
- )
81
+ async def test_move_to_root_client_get_health_status(move_to_root_client: MoveToRootClient):
82
+ await move_to_root_client.get_health_status()
@@ -0,0 +1,110 @@
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.core.exceptions import HttpResponseError
8
+ from azure.resourcemanager.multiservice.combined.aio import CombinedClient
9
+ from azure.resourcemanager.multiservice.combined.models import VirtualMachine, Disk
10
+
11
+
12
+ @pytest.fixture
13
+ async def client(credential, authentication_policy):
14
+ """Create a Combined async client for testing."""
15
+ return CombinedClient(
16
+ credential=credential,
17
+ subscription_id="00000000-0000-0000-0000-000000000000",
18
+ base_url="http://localhost:3000",
19
+ authentication_policy=authentication_policy,
20
+ polling_interval=0.1, # Speed up tests by reducing polling interval
21
+ )
22
+
23
+
24
+ @pytest.mark.asyncio
25
+ async def test_virtual_machines_get(client):
26
+ resource_group_name = "test-rg"
27
+ vm_name = "vm1"
28
+
29
+ with pytest.raises(HttpResponseError):
30
+ await client.virtual_machines.get(
31
+ resource_group_name=resource_group_name,
32
+ vm_name=vm_name,
33
+ api_version="av1", # invalid api version shall raise error
34
+ )
35
+
36
+ result = await client.virtual_machines.get(resource_group_name=resource_group_name, vm_name=vm_name)
37
+
38
+ assert result is not None
39
+ assert isinstance(result, VirtualMachine)
40
+ assert result.name == vm_name
41
+
42
+
43
+ @pytest.mark.asyncio
44
+ async def test_virtual_machines_create_or_update(client):
45
+ resource_group_name = "test-rg"
46
+ vm_name = "vm1"
47
+
48
+ vm_resource = VirtualMachine(location="eastus", properties={})
49
+
50
+ with pytest.raises(HttpResponseError):
51
+ poller = await client.virtual_machines.begin_create_or_update(
52
+ resource_group_name=resource_group_name,
53
+ vm_name=vm_name,
54
+ resource=vm_resource,
55
+ api_version="av1", # invalid api version shall raise error
56
+ )
57
+ await poller.result()
58
+
59
+ poller = await client.virtual_machines.begin_create_or_update(
60
+ resource_group_name=resource_group_name, vm_name=vm_name, resource=vm_resource
61
+ )
62
+
63
+ result = await poller.result()
64
+ assert result is not None
65
+ assert isinstance(result, VirtualMachine)
66
+ assert result.location == "eastus"
67
+
68
+
69
+ @pytest.mark.asyncio
70
+ async def test_disks_get(client):
71
+ resource_group_name = "test-rg"
72
+ disk_name = "disk1"
73
+ with pytest.raises(HttpResponseError):
74
+ await client.disks.get(
75
+ resource_group_name=resource_group_name,
76
+ disk_name=disk_name,
77
+ api_version="av1", # invalid api version shall raise error
78
+ )
79
+
80
+ result = await client.disks.get(resource_group_name=resource_group_name, disk_name=disk_name)
81
+
82
+ assert result is not None
83
+ assert isinstance(result, Disk)
84
+ assert result.name == disk_name
85
+
86
+
87
+ @pytest.mark.asyncio
88
+ async def test_disks_create_or_update(client):
89
+ resource_group_name = "test-rg"
90
+ disk_name = "disk1"
91
+
92
+ disk_resource = Disk(location="eastus", properties={})
93
+
94
+ with pytest.raises(HttpResponseError):
95
+ poller = await client.disks.begin_create_or_update(
96
+ resource_group_name=resource_group_name,
97
+ disk_name=disk_name,
98
+ resource=disk_resource,
99
+ api_version="av1", # invalid api version shall raise error
100
+ )
101
+ await poller.result()
102
+
103
+ poller = await client.disks.begin_create_or_update(
104
+ resource_group_name=resource_group_name, disk_name=disk_name, resource=disk_resource
105
+ )
106
+
107
+ result = await poller.result()
108
+ assert result is not None
109
+ assert isinstance(result, Disk)
110
+ assert result.location == "eastus"
@@ -151,3 +151,36 @@ async def test_complex_with_http_part(client: MultiPartClient):
151
151
  @pytest.mark.asyncio
152
152
  async def test_http_parts_non_string_float(client: MultiPartClient):
153
153
  await client.form_data.http_parts.non_string.float(models.FloatRequest(temperature=0.5))
154
+
155
+
156
+ @pytest.mark.asyncio
157
+ async def test_with_wire_name(client: MultiPartClient):
158
+ await client.form_data.with_wire_name(
159
+ models.MultiPartRequestWithWireName(
160
+ identifier="123",
161
+ image=open(str(JPG), "rb"),
162
+ )
163
+ )
164
+
165
+
166
+ @pytest.mark.asyncio
167
+ async def test_optional_parts(client: MultiPartClient):
168
+ # First time with only id
169
+ await client.form_data.optional_parts(
170
+ models.MultiPartOptionalRequest(
171
+ id="123",
172
+ )
173
+ )
174
+ # Second time with only profileImage
175
+ await client.form_data.optional_parts(
176
+ models.MultiPartOptionalRequest(
177
+ profile_image=open(str(JPG), "rb"),
178
+ )
179
+ )
180
+ # Third time with both id and profileImage
181
+ await client.form_data.optional_parts(
182
+ models.MultiPartOptionalRequest(
183
+ id="123",
184
+ profile_image=open(str(JPG), "rb"),
185
+ )
186
+ )
@@ -0,0 +1,31 @@
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.core.exceptions import HttpResponseError
8
+ from service.multiservice.aio import CombinedClient
9
+ from service.multiservice.models import VersionsA, VersionsB
10
+
11
+
12
+ @pytest.fixture
13
+ def client():
14
+ """Fixture that creates a CombinedClient for testing."""
15
+ return CombinedClient(endpoint="http://localhost:3000")
16
+
17
+
18
+ @pytest.mark.asyncio
19
+ async def test_service_multi_service_foo(client):
20
+ with pytest.raises(HttpResponseError):
21
+ await client.foo.test(api_version=VersionsA.AV1)
22
+
23
+ await client.foo.test()
24
+
25
+
26
+ @pytest.mark.asyncio
27
+ async def test_service_multi_service_bar(client):
28
+ with pytest.raises(HttpResponseError):
29
+ await client.bar.test(api_version=VersionsB.BV1)
30
+
31
+ await client.bar.test()
@@ -40,3 +40,21 @@ async def test_model(client: SpecialWordsClient, special_words):
40
40
  @pytest.mark.asyncio
41
41
  async def test_model_properties(client: SpecialWordsClient):
42
42
  await client.model_properties.same_as_model(models.SameAsModel(same_as_model="ok"))
43
+
44
+
45
+ @pytest.mark.asyncio
46
+ async def test_model_properties_dict_methods(client: SpecialWordsClient):
47
+ await client.model_properties.dict_methods(
48
+ body=models.DictMethods(
49
+ keys_property="ok",
50
+ items_property="ok",
51
+ values_property="ok",
52
+ popitem_property="ok",
53
+ clear_property="ok",
54
+ update_property="ok",
55
+ setdefault_property="ok",
56
+ pop_property="ok",
57
+ get_property="ok",
58
+ copy_property="ok",
59
+ )
60
+ )
@@ -154,3 +154,18 @@ def test_optional_body_provider_post_with_body(client):
154
154
  )
155
155
  assert result.total_allowed == 100
156
156
  assert result.status == "Changed to requested allowance"
157
+
158
+
159
+ def test_lro_paging_begin_post_paging_lro(client):
160
+ result = client.lro_paging.begin_post_paging_lro(
161
+ resource_group_name=RESOURCE_GROUP_NAME,
162
+ product_name="default",
163
+ ).result()
164
+ items = list(result)
165
+ assert len(items) == 2
166
+ assert items[0].name == "product1"
167
+ assert items[0].properties.product_id == "product1"
168
+ assert items[0].properties.provisioning_state == "Succeeded"
169
+ assert items[1].name == "product2"
170
+ assert items[1].properties.product_id == "product2"
171
+ assert items[1].properties.provisioning_state == "Succeeded"
@@ -0,0 +1,42 @@
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.clientdefaultvalue import ClientDefaultValueClient
8
+ from specs.azure.clientgenerator.core.clientdefaultvalue.models import ModelWithDefaultValues
9
+
10
+
11
+ @pytest.fixture
12
+ def client():
13
+ with ClientDefaultValueClient() as client:
14
+ yield client
15
+
16
+
17
+ def test_put_model_property(client: ClientDefaultValueClient):
18
+ """Test case 1: @clientDefaultValue for model property."""
19
+ body = ModelWithDefaultValues(name="test")
20
+ result = client.put_model_property(body=body)
21
+ assert result.name == "test"
22
+ assert result.timeout == 30
23
+ assert result.tier == "standard"
24
+ assert result.retry is True
25
+
26
+
27
+ def test_get_operation_parameter(client: ClientDefaultValueClient):
28
+ """Test case 2: @clientDefaultValue for operation parameter."""
29
+ # Test with only required parameter (name), defaults should be applied
30
+ client.get_operation_parameter(name="test")
31
+
32
+
33
+ def test_get_path_parameter(client: ClientDefaultValueClient):
34
+ """Test case 3: @clientDefaultValue for first path segment."""
35
+ # Test with only required segment2, segment1 should use default
36
+ client.get_path_parameter(segment2="segment2")
37
+
38
+
39
+ def test_get_header_parameter(client: ClientDefaultValueClient):
40
+ """Test case 4: @clientDefaultValue for header parameters."""
41
+ # Test with default header values
42
+ client.get_header_parameter()