Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: internal
packages:
- "@autorest/python"
- "@azure-tools/typespec-python"
---

Add test cases for flatten property with read-only properties (putFlattenReadOnlyModel and putFlattenUnknownModel scenarios).
2 changes: 1 addition & 1 deletion packages/autorest.python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
"dependencies": {
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MTM1Ny9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MjQwMi9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz",
"@autorest/system-requirements": "~1.0.2",
"fs-extra": "~11.2.0",
"tsx": "^4.21.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"js-yaml": "~4.1.0",
"semver": "~7.6.2",
"tsx": "^4.21.0",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MTM1Ny9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MjQwMi9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz",
"fs-extra": "~11.2.0"
},
"devDependencies": {
Expand All @@ -86,7 +86,7 @@
"@azure-tools/typespec-azure-rulesets": "~0.65.0",
"@azure-tools/typespec-autorest": "~0.65.0",
"@azure-tools/typespec-client-generator-core": "~0.65.3",
"@azure-tools/azure-http-specs": "0.1.0-alpha.38-dev.2",
"@azure-tools/azure-http-specs": "0.1.0-alpha.38-dev.6",
"@typespec/http-specs": "0.1.0-alpha.33-dev.2",
"@typespec/spector": "0.1.0-alpha.23",
"@typespec/spec-api": "0.1.0-alpha.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
"specs.azure.clientgenerator.core.flattenproperty.models.ChildFlattenModel": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.ChildFlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.models.ChildModel": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.ChildModel",
"specs.azure.clientgenerator.core.flattenproperty.models.FlattenModel": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.FlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.models.FlattenUnknownModel": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.FlattenUnknownModel",
"specs.azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.NestedFlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.models.Solution": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.Solution",
"specs.azure.clientgenerator.core.flattenproperty.models.SolutionProperties": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.SolutionProperties",
"specs.azure.clientgenerator.core.flattenproperty.FlattenPropertyClient.put_flatten_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putFlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.aio.FlattenPropertyClient.put_flatten_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putFlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.FlattenPropertyClient.put_nested_flatten_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putNestedFlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.aio.FlattenPropertyClient.put_nested_flatten_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putNestedFlattenModel"
"specs.azure.clientgenerator.core.flattenproperty.aio.FlattenPropertyClient.put_nested_flatten_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putNestedFlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.FlattenPropertyClient.put_flatten_unknown_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putFlattenUnknownModel",
"specs.azure.clientgenerator.core.flattenproperty.aio.FlattenPropertyClient.put_flatten_unknown_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putFlattenUnknownModel",
"specs.azure.clientgenerator.core.flattenproperty.FlattenPropertyClient.put_flatten_read_only_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putFlattenReadOnlyModel",
"specs.azure.clientgenerator.core.flattenproperty.aio.FlattenPropertyClient.put_flatten_read_only_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putFlattenReadOnlyModel"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,25 @@ def test_put_nested_flatten_model(self, flattenproperty_endpoint):

# please add some check logic here by yourself
# ...

@FlattenPropertyPreparer()
@recorded_by_proxy
def test_put_flatten_unknown_model(self, flattenproperty_endpoint):
client = self.create_client(endpoint=flattenproperty_endpoint)
response = client.put_flatten_unknown_model(
input={"name": "str", "properties": {}},
)

# please add some check logic here by yourself
# ...

@FlattenPropertyPreparer()
@recorded_by_proxy
def test_put_flatten_read_only_model(self, flattenproperty_endpoint):
client = self.create_client(endpoint=flattenproperty_endpoint)
response = client.put_flatten_read_only_model(
body={"name": "str", "properties": {"content": "str", "solutionId": "str", "title": "str"}},
)

# please add some check logic here by yourself
# ...
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,25 @@ async def test_put_nested_flatten_model(self, flattenproperty_endpoint):

# please add some check logic here by yourself
# ...

@FlattenPropertyPreparer()
@recorded_by_proxy_async
async def test_put_flatten_unknown_model(self, flattenproperty_endpoint):
client = self.create_async_client(endpoint=flattenproperty_endpoint)
response = await client.put_flatten_unknown_model(
input={"name": "str", "properties": {}},
)

# please add some check logic here by yourself
# ...

@FlattenPropertyPreparer()
@recorded_by_proxy_async
async def test_put_flatten_read_only_model(self, flattenproperty_endpoint):
client = self.create_async_client(endpoint=flattenproperty_endpoint)
response = await client.put_flatten_read_only_model(
body={"name": "str", "properties": {"content": "str", "solutionId": "str", "title": "str"}},
)

# please add some check logic here by yourself
# ...
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,44 @@ def build_flatten_property_put_nested_flatten_model_request( # pylint: disable=
return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs)


def build_flatten_property_put_flatten_unknown_model_request( # pylint: disable=name-too-long
**kwargs: Any,
) -> HttpRequest:
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})

content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
accept = _headers.pop("Accept", "application/json")

# Construct URL
_url = "/azure/client-generator-core/flatten-property/flattenUnknownModel"

# Construct headers
if content_type is not None:
_headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
_headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs)


def build_flatten_property_put_flatten_read_only_model_request( # pylint: disable=name-too-long
**kwargs: Any,
) -> HttpRequest:
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})

content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
accept = _headers.pop("Accept", "application/json")

# Construct URL
_url = "/azure/client-generator-core/flatten-property/flattenReadOnlyModel"

# Construct headers
if content_type is not None:
_headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
_headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs)


class _FlattenPropertyClientOperationsMixin(
ClientMixinABC[PipelineClient[HttpRequest, HttpResponse], FlattenPropertyClientConfiguration]
):
Expand Down Expand Up @@ -319,3 +357,243 @@ def put_nested_flatten_model(
return cls(pipeline_response, deserialized, {}) # type: ignore

return deserialized # type: ignore

@overload
def put_flatten_unknown_model(
self, input: _models.FlattenUnknownModel, *, content_type: str = "application/json", **kwargs: Any
) -> _models.FlattenUnknownModel:
"""put_flatten_unknown_model.

:param input: Required.
:type input: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenUnknownModel
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/json".
:paramtype content_type: str
:return: FlattenUnknownModel. The FlattenUnknownModel is compatible with MutableMapping
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenUnknownModel
:raises ~azure.core.exceptions.HttpResponseError:
"""

@overload
def put_flatten_unknown_model(
self, input: JSON, *, content_type: str = "application/json", **kwargs: Any
) -> _models.FlattenUnknownModel:
"""put_flatten_unknown_model.

:param input: Required.
:type input: JSON
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/json".
:paramtype content_type: str
:return: FlattenUnknownModel. The FlattenUnknownModel is compatible with MutableMapping
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenUnknownModel
:raises ~azure.core.exceptions.HttpResponseError:
"""

@overload
def put_flatten_unknown_model(
self, input: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
) -> _models.FlattenUnknownModel:
"""put_flatten_unknown_model.

:param input: Required.
:type input: IO[bytes]
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
Default value is "application/json".
:paramtype content_type: str
:return: FlattenUnknownModel. The FlattenUnknownModel is compatible with MutableMapping
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenUnknownModel
:raises ~azure.core.exceptions.HttpResponseError:
"""

@distributed_trace
def put_flatten_unknown_model(
self, input: Union[_models.FlattenUnknownModel, JSON, IO[bytes]], **kwargs: Any
) -> _models.FlattenUnknownModel:
"""put_flatten_unknown_model.

:param input: Is one of the following types: FlattenUnknownModel, JSON, IO[bytes] Required.
:type input: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenUnknownModel or
JSON or IO[bytes]
:return: FlattenUnknownModel. The FlattenUnknownModel is compatible with MutableMapping
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenUnknownModel
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map: MutableMapping = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = kwargs.pop("params", {}) or {}

content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
cls: ClsType[_models.FlattenUnknownModel] = kwargs.pop("cls", None)

content_type = content_type or "application/json"
_content = None
if isinstance(input, (IOBase, bytes)):
_content = input
else:
_content = json.dumps(input, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore

_request = build_flatten_property_put_flatten_unknown_model_request(
content_type=content_type,
content=_content,
headers=_headers,
params=_params,
)
path_format_arguments = {
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
}
_request.url = self._client.format_url(_request.url, **path_format_arguments)

_decompress = kwargs.pop("decompress", True)
_stream = kwargs.pop("stream", False)
pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
_request, stream=_stream, **kwargs
)

response = pipeline_response.http_response

if response.status_code not in [200]:
if _stream:
try:
response.read() # Load the body in memory and close the socket
except (StreamConsumedError, StreamClosedError):
pass
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)

if _stream:
deserialized = response.iter_bytes() if _decompress else response.iter_raw()
else:
deserialized = _deserialize(_models.FlattenUnknownModel, response.json())

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore

return deserialized # type: ignore

@overload
def put_flatten_read_only_model(
self, body: _models.Solution, *, content_type: str = "application/json", **kwargs: Any
) -> _models.Solution:
"""put_flatten_read_only_model.

:param body: Required.
:type body: ~specs.azure.clientgenerator.core.flattenproperty.models.Solution
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/json".
:paramtype content_type: str
:return: Solution. The Solution is compatible with MutableMapping
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.Solution
:raises ~azure.core.exceptions.HttpResponseError:
"""

@overload
def put_flatten_read_only_model(
self, body: JSON, *, content_type: str = "application/json", **kwargs: Any
) -> _models.Solution:
"""put_flatten_read_only_model.

:param body: Required.
:type body: JSON
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/json".
:paramtype content_type: str
:return: Solution. The Solution is compatible with MutableMapping
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.Solution
:raises ~azure.core.exceptions.HttpResponseError:
"""

@overload
def put_flatten_read_only_model(
self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
) -> _models.Solution:
"""put_flatten_read_only_model.

:param body: Required.
:type body: IO[bytes]
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
Default value is "application/json".
:paramtype content_type: str
:return: Solution. The Solution is compatible with MutableMapping
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.Solution
:raises ~azure.core.exceptions.HttpResponseError:
"""

@distributed_trace
def put_flatten_read_only_model(
self, body: Union[_models.Solution, JSON, IO[bytes]], **kwargs: Any
) -> _models.Solution:
"""put_flatten_read_only_model.

:param body: Is one of the following types: Solution, JSON, IO[bytes] Required.
:type body: ~specs.azure.clientgenerator.core.flattenproperty.models.Solution or JSON or
IO[bytes]
:return: Solution. The Solution is compatible with MutableMapping
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.Solution
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map: MutableMapping = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = kwargs.pop("params", {}) or {}

content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
cls: ClsType[_models.Solution] = kwargs.pop("cls", None)

content_type = content_type or "application/json"
_content = None
if isinstance(body, (IOBase, bytes)):
_content = body
else:
_content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore

_request = build_flatten_property_put_flatten_read_only_model_request(
content_type=content_type,
content=_content,
headers=_headers,
params=_params,
)
path_format_arguments = {
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
}
_request.url = self._client.format_url(_request.url, **path_format_arguments)

_decompress = kwargs.pop("decompress", True)
_stream = kwargs.pop("stream", False)
pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
_request, stream=_stream, **kwargs
)

response = pipeline_response.http_response

if response.status_code not in [200]:
if _stream:
try:
response.read() # Load the body in memory and close the socket
except (StreamConsumedError, StreamClosedError):
pass
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)

if _stream:
deserialized = response.iter_bytes() if _decompress else response.iter_raw()
else:
deserialized = _deserialize(_models.Solution, response.json())

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore

return deserialized # type: ignore
Loading
Loading