@typespec/http-client-python 0.27.0 → 0.27.2
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.
- package/dist/emitter/code-model.d.ts.map +1 -1
- package/dist/emitter/code-model.js +20 -15
- package/dist/emitter/code-model.js.map +1 -1
- package/dist/emitter/http.js +11 -1
- package/dist/emitter/http.js.map +1 -1
- package/dist/emitter/types.d.ts.map +1 -1
- package/dist/emitter/types.js +30 -11
- package/dist/emitter/types.js.map +1 -1
- package/emitter/src/code-model.ts +28 -21
- package/emitter/src/http.ts +10 -1
- package/emitter/src/types.ts +32 -11
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/ci/regenerate-common.ts +472 -0
- package/eng/scripts/ci/regenerate.ts +41 -427
- package/eng/scripts/setup/__pycache__/package_manager.cpython-311.pyc +0 -0
- package/eng/scripts/setup/__pycache__/venvtools.cpython-311.pyc +0 -0
- package/generator/build/lib/pygen/codegen/models/client.py +5 -5
- package/generator/build/lib/pygen/codegen/models/credential_types.py +1 -1
- package/generator/build/lib/pygen/codegen/models/enum_type.py +1 -1
- package/generator/build/lib/pygen/codegen/models/imports.py +2 -3
- package/generator/build/lib/pygen/codegen/models/lro_operation.py +1 -1
- package/generator/build/lib/pygen/codegen/models/model_type.py +2 -2
- package/generator/build/lib/pygen/codegen/models/operation.py +10 -6
- package/generator/build/lib/pygen/codegen/models/operation_group.py +1 -1
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +7 -3
- package/generator/build/lib/pygen/codegen/models/primitive_types.py +1 -1
- package/generator/build/lib/pygen/codegen/models/request_builder.py +1 -1
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +16 -7
- package/generator/build/lib/pygen/codegen/serializers/import_serializer.py +4 -31
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +8 -2
- package/generator/component-detection-pip-report.json +6 -6
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/models/client.py +5 -5
- package/generator/pygen/codegen/models/credential_types.py +1 -1
- package/generator/pygen/codegen/models/enum_type.py +1 -1
- package/generator/pygen/codegen/models/imports.py +2 -3
- package/generator/pygen/codegen/models/lro_operation.py +1 -1
- package/generator/pygen/codegen/models/model_type.py +2 -2
- package/generator/pygen/codegen/models/operation.py +10 -6
- package/generator/pygen/codegen/models/operation_group.py +1 -1
- package/generator/pygen/codegen/models/paging_operation.py +7 -3
- package/generator/pygen/codegen/models/primitive_types.py +1 -1
- package/generator/pygen/codegen/models/request_builder.py +1 -1
- package/generator/pygen/codegen/serializers/builder_serializer.py +16 -7
- package/generator/pygen/codegen/serializers/import_serializer.py +4 -31
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +8 -2
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py +12 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_initialization_async.py +2 -3
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_page_async.py +12 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_multi_service_older_versions_async.py +111 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_multi_service_shared_models_async.py +132 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py +30 -0
- package/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py +9 -0
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_initialization.py +2 -3
- package/generator/test/azure/mock_api_tests/test_azure_core_page.py +11 -0
- package/generator/test/azure/mock_api_tests/test_azure_resource_manager_multi_service_older_versions.py +107 -0
- package/generator/test/azure/mock_api_tests/test_azure_resource_manager_multi_service_shared_models.py +128 -0
- package/generator/test/azure/mock_api_tests/test_clear_output_folder.py +9 -0
- package/generator/test/azure/mock_api_tests/test_payload_multipart.py +27 -0
- package/generator/test/azure/requirements.txt +10 -2
- package/generator/test/generic_mock_api_tests/asynctests/test_encode_bytes_async.py +6 -1
- package/generator/test/generic_mock_api_tests/asynctests/test_payload_pageable_async.py +10 -5
- package/generator/test/generic_mock_api_tests/asynctests/test_payload_xml_async.py +30 -0
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_file_async.py +59 -0
- package/generator/test/generic_mock_api_tests/data/image.jpg +0 -0
- package/generator/test/generic_mock_api_tests/data/image.png +0 -0
- package/generator/test/generic_mock_api_tests/test_encode_bytes.py +6 -0
- package/generator/test/generic_mock_api_tests/test_payload_pageable.py +8 -4
- package/generator/test/generic_mock_api_tests/test_payload_xml.py +27 -0
- package/generator/test/generic_mock_api_tests/test_typetest_file.py +52 -0
- package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_multipart_async.py +31 -0
- package/generator/test/unbranded/mock_api_tests/test_payload_multipart.py +28 -0
- package/generator/test/unbranded/mock_api_tests/test_unbranded.py +9 -8
- package/generator/test/unbranded/requirements.txt +3 -1
- package/generator/test/unittests/test_model_base_serialization.py +161 -0
- package/package.json +38 -38
|
@@ -169,3 +169,30 @@ def test_optional_parts(client: MultiPartClient):
|
|
|
169
169
|
profile_image=open(str(JPG), "rb"),
|
|
170
170
|
)
|
|
171
171
|
)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def test_file_upload_file_specific_content_type(client: MultiPartClient):
|
|
175
|
+
client.form_data.file.upload_file_specific_content_type(
|
|
176
|
+
models.UploadFileSpecificContentTypeRequest(
|
|
177
|
+
file=("image.png", open(str(PNG), "rb"), "image/png"),
|
|
178
|
+
)
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def test_file_upload_file_required_filename(client: MultiPartClient):
|
|
183
|
+
client.form_data.file.upload_file_required_filename(
|
|
184
|
+
models.UploadFileRequiredFilenameRequest(
|
|
185
|
+
file=("image.png", open(str(PNG), "rb"), "image/png"),
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def test_file_upload_file_array(client: MultiPartClient):
|
|
191
|
+
client.form_data.file.upload_file_array(
|
|
192
|
+
models.UploadFileArrayRequest(
|
|
193
|
+
files=[
|
|
194
|
+
("image.png", open(str(PNG), "rb"), "image/png"),
|
|
195
|
+
("image.png", open(str(PNG), "rb"), "image/png"),
|
|
196
|
+
],
|
|
197
|
+
)
|
|
198
|
+
)
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
-e ../../
|
|
3
3
|
azure-mgmt-core==1.6.0
|
|
4
4
|
|
|
5
|
+
# === common azure dependencies across repos ===
|
|
5
6
|
# only for azure
|
|
6
7
|
-e ./generated/azure-client-generator-core-access
|
|
7
8
|
-e ./generated/azure-client-generator-core-api-version-header
|
|
8
9
|
-e ./generated/azure-client-generator-core-api-version-path
|
|
9
10
|
-e ./generated/azure-client-generator-core-api-version-query
|
|
10
|
-
-e ./generated/azure-client-generator-core-client-initialization
|
|
11
|
+
-e ./generated/azure-client-generator-core-client-initialization-default
|
|
12
|
+
-e ./generated/azure-client-generator-core-client-initialization-individually
|
|
13
|
+
-e ./generated/azure-client-generator-core-client-initialization-individuallyparent
|
|
11
14
|
-e ./generated/azure-client-generator-core-deserialize-empty-string-as-null
|
|
12
15
|
-e ./generated/azure-client-generator-core-flatten-property
|
|
13
16
|
-e ./generated/azure-client-generator-core-hierarchy-building
|
|
@@ -37,6 +40,8 @@ azure-mgmt-core==1.6.0
|
|
|
37
40
|
-e ./generated/azure-resource-manager-resources
|
|
38
41
|
-e ./generated/azure-resource-manager-method-subscription-id
|
|
39
42
|
-e ./generated/azure-resource-manager-multi-service
|
|
43
|
+
-e ./generated/azure-resource-manager-multi-service-older-versions
|
|
44
|
+
-e ./generated/azure-resource-manager-multi-service-shared-models
|
|
40
45
|
-e ./generated/azure-versioning-previewversion
|
|
41
46
|
-e ./generated/client-namespace
|
|
42
47
|
-e ./generated/azure-payload-pageable
|
|
@@ -51,8 +56,9 @@ azure-mgmt-core==1.6.0
|
|
|
51
56
|
-e ./generated/resiliency-srv-driven1
|
|
52
57
|
-e ./generated/resiliency-srv-driven2
|
|
53
58
|
-e ./generated/service-multi-service
|
|
59
|
+
# === end common azure dependencies across repos ===
|
|
54
60
|
|
|
55
|
-
# common test
|
|
61
|
+
# === common test dependencies across repos ===
|
|
56
62
|
-e ./generated/authentication-api-key
|
|
57
63
|
-e ./generated/authentication-http-custom
|
|
58
64
|
-e ./generated/authentication-noauth-union
|
|
@@ -80,6 +86,7 @@ azure-mgmt-core==1.6.0
|
|
|
80
86
|
-e ./generated/typetest-dictionary
|
|
81
87
|
-e ./generated/typetest-enum-extensible
|
|
82
88
|
-e ./generated/typetest-enum-fixed
|
|
89
|
+
# -e ./generated/typetest-file
|
|
83
90
|
-e ./generated/typetest-model-enumdiscriminator
|
|
84
91
|
-e ./generated/typetest-model-nesteddiscriminator
|
|
85
92
|
-e ./generated/typetest-model-notdiscriminated
|
|
@@ -116,3 +123,4 @@ azure-mgmt-core==1.6.0
|
|
|
116
123
|
-e ./generated/versioning-renamedfrom
|
|
117
124
|
-e ./generated/versioning-returntypechangedfrom
|
|
118
125
|
-e ./generated/versioning-typechangedfrom
|
|
126
|
+
# === end common test dependencies across repos ===
|
|
@@ -13,7 +13,6 @@ from encode.bytes.models import (
|
|
|
13
13
|
Base64urlArrayBytesProperty,
|
|
14
14
|
)
|
|
15
15
|
|
|
16
|
-
|
|
17
16
|
FILE_FOLDER = Path(__file__).parent.parent
|
|
18
17
|
|
|
19
18
|
|
|
@@ -98,6 +97,12 @@ async def test_header(client: BytesClient):
|
|
|
98
97
|
)
|
|
99
98
|
|
|
100
99
|
|
|
100
|
+
@pytest.fixture
|
|
101
|
+
def png_data() -> bytes:
|
|
102
|
+
with open(str(FILE_FOLDER / "data/image.png"), "rb") as file_in:
|
|
103
|
+
return file_in.read()
|
|
104
|
+
|
|
105
|
+
|
|
101
106
|
@pytest.mark.asyncio
|
|
102
107
|
async def test_request_body(client: BytesClient, png_data: bytes):
|
|
103
108
|
await client.request_body.default(
|
|
@@ -115,8 +115,13 @@ async def test_list_without_continuation(client: PageableClient):
|
|
|
115
115
|
assert_result(result)
|
|
116
116
|
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
@pytest.mark.asyncio
|
|
119
|
+
async def test_xml_pagination_list_with_continuation(client: PageableClient):
|
|
120
|
+
result = [p async for p in client.xml_pagination.list_with_continuation()]
|
|
121
|
+
assert_result(result)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@pytest.mark.asyncio
|
|
125
|
+
async def test_xml_pagination_list_with_next_link(client: PageableClient):
|
|
126
|
+
result = [p async for p in client.xml_pagination.list_with_next_link()]
|
|
127
|
+
assert_result(result)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
+
import datetime
|
|
6
7
|
import pytest
|
|
7
8
|
from payload.xml.aio import XmlClient
|
|
8
9
|
from payload.xml.models import (
|
|
@@ -18,6 +19,8 @@ from payload.xml.models import (
|
|
|
18
19
|
ModelWithText,
|
|
19
20
|
ModelWithDictionary,
|
|
20
21
|
ModelWithEncodedNames,
|
|
22
|
+
ModelWithEnum,
|
|
23
|
+
ModelWithDatetime,
|
|
21
24
|
)
|
|
22
25
|
|
|
23
26
|
|
|
@@ -117,3 +120,30 @@ async def test_model_with_encoded_names(client: XmlClient):
|
|
|
117
120
|
model = ModelWithEncodedNames(model_data=SimpleModel(name="foo", age=123), colors=["red", "green", "blue"])
|
|
118
121
|
assert await client.model_with_encoded_names_value.get() == model
|
|
119
122
|
await client.model_with_encoded_names_value.put(model)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@pytest.mark.asyncio
|
|
126
|
+
async def test_model_with_enum(client: XmlClient):
|
|
127
|
+
model = ModelWithEnum(status="success")
|
|
128
|
+
assert await client.model_with_enum_value.get() == model
|
|
129
|
+
await client.model_with_enum_value.put(model)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@pytest.mark.asyncio
|
|
133
|
+
async def test_model_with_datetime(client: XmlClient):
|
|
134
|
+
model = ModelWithDatetime(
|
|
135
|
+
rfc3339=datetime.datetime(2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc),
|
|
136
|
+
rfc7231=datetime.datetime(2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc),
|
|
137
|
+
)
|
|
138
|
+
result = await client.model_with_datetime_value.get()
|
|
139
|
+
assert result.rfc3339 == model.rfc3339
|
|
140
|
+
assert result.rfc7231 == model.rfc7231
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@pytest.mark.asyncio
|
|
144
|
+
async def test_xml_error_value(client: XmlClient, core_library):
|
|
145
|
+
with pytest.raises(core_library.exceptions.HttpResponseError) as ex:
|
|
146
|
+
await client.xml_error_value.get()
|
|
147
|
+
assert ex.value.status_code == 400
|
|
148
|
+
assert ex.value.model.message == "Something went wrong"
|
|
149
|
+
assert ex.value.model.code == 400
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
# after we support Http.File case, enable these tests again
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# import json
|
|
10
|
+
|
|
11
|
+
# import pytest
|
|
12
|
+
# from typetest.file.aio import FileClient
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# @pytest.fixture
|
|
16
|
+
# async def client():
|
|
17
|
+
# async with FileClient(endpoint="http://localhost:3000") as client:
|
|
18
|
+
# yield client
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# @pytest.mark.asyncio
|
|
22
|
+
# async def test_upload_file_specific_content_type(client: FileClient, png_data: bytes):
|
|
23
|
+
# await client.body.upload_file_specific_content_type(png_data)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# # Do not support this case for now
|
|
27
|
+
# # @pytest.mark.asyncio
|
|
28
|
+
# # async def test_upload_file_json_content_type(client: FileClient):
|
|
29
|
+
# # await client.body.upload_file_json_content_type(json.dumps({"message": "test file content"}).encode())
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# # although result is expected but actually there is deserialization issue
|
|
33
|
+
# # @pytest.mark.asyncio
|
|
34
|
+
# # async def test_download_file_json_content_type(client: FileClient):
|
|
35
|
+
# # result = await client.body.download_file_json_content_type()
|
|
36
|
+
# # assert result == {"message": "test file content"}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# @pytest.mark.asyncio
|
|
40
|
+
# async def test_download_file_specific_content_type(client: FileClient, png_data: bytes):
|
|
41
|
+
# result = b"".join([d async for d in (await client.body.download_file_specific_content_type())])
|
|
42
|
+
# assert result == png_data
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# @pytest.mark.asyncio
|
|
46
|
+
# async def test_download_file_multiple_content_types(client: FileClient, png_data: bytes):
|
|
47
|
+
# result = b"".join([d async for d in (await client.body.download_file_multiple_content_types())])
|
|
48
|
+
# assert result == png_data
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# @pytest.mark.asyncio
|
|
52
|
+
# async def test_upload_file_default_content_type(client: FileClient, png_data: bytes):
|
|
53
|
+
# await client.body.upload_file_default_content_type(png_data, content_type="image/png")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# @pytest.mark.asyncio
|
|
57
|
+
# async def test_download_file_default_content_type(client: FileClient, png_data: bytes):
|
|
58
|
+
# result = b"".join([d async for d in (await client.body.download_file_default_content_type())])
|
|
59
|
+
# assert result == png_data
|
|
Binary file
|
|
Binary file
|
|
@@ -95,6 +95,12 @@ def test_header(client: BytesClient):
|
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
|
|
98
|
+
@pytest.fixture
|
|
99
|
+
def png_data() -> bytes:
|
|
100
|
+
with open(str(FILE_FOLDER / "data/image.png"), "rb") as file_in:
|
|
101
|
+
return file_in.read()
|
|
102
|
+
|
|
103
|
+
|
|
98
104
|
def test_request_body(client: BytesClient, png_data: bytes):
|
|
99
105
|
client.request_body.default(
|
|
100
106
|
value=png_data,
|
|
@@ -83,7 +83,11 @@ def test_list_without_continuation(client: PageableClient):
|
|
|
83
83
|
assert_result(result)
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
def test_xml_pagination_list_with_continuation(client: PageableClient):
|
|
87
|
+
result = list(client.xml_pagination.list_with_continuation())
|
|
88
|
+
assert_result(result)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_xml_pagination_list_with_next_link(client: PageableClient):
|
|
92
|
+
result = list(client.xml_pagination.list_with_next_link())
|
|
93
|
+
assert_result(result)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
+
import datetime
|
|
6
7
|
import pytest
|
|
7
8
|
from payload.xml import XmlClient
|
|
8
9
|
from payload.xml.models import (
|
|
@@ -18,6 +19,8 @@ from payload.xml.models import (
|
|
|
18
19
|
ModelWithText,
|
|
19
20
|
ModelWithDictionary,
|
|
20
21
|
ModelWithEncodedNames,
|
|
22
|
+
ModelWithEnum,
|
|
23
|
+
ModelWithDatetime,
|
|
21
24
|
)
|
|
22
25
|
|
|
23
26
|
|
|
@@ -105,3 +108,27 @@ def test_model_with_encoded_names(client: XmlClient):
|
|
|
105
108
|
model = ModelWithEncodedNames(model_data=SimpleModel(name="foo", age=123), colors=["red", "green", "blue"])
|
|
106
109
|
assert client.model_with_encoded_names_value.get() == model
|
|
107
110
|
client.model_with_encoded_names_value.put(model)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_model_with_enum(client: XmlClient):
|
|
114
|
+
model = ModelWithEnum(status="success")
|
|
115
|
+
assert client.model_with_enum_value.get() == model
|
|
116
|
+
client.model_with_enum_value.put(model)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_model_with_datetime(client: XmlClient):
|
|
120
|
+
model = ModelWithDatetime(
|
|
121
|
+
rfc3339=datetime.datetime(2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc),
|
|
122
|
+
rfc7231=datetime.datetime(2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc),
|
|
123
|
+
)
|
|
124
|
+
result = client.model_with_datetime_value.get()
|
|
125
|
+
assert result.rfc3339 == model.rfc3339
|
|
126
|
+
assert result.rfc7231 == model.rfc7231
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def test_xml_error_value(client: XmlClient, core_library):
|
|
130
|
+
with pytest.raises(core_library.exceptions.HttpResponseError) as ex:
|
|
131
|
+
client.xml_error_value.get()
|
|
132
|
+
assert ex.value.status_code == 400
|
|
133
|
+
assert ex.value.model.message == "Something went wrong"
|
|
134
|
+
assert ex.value.model.code == 400
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
|
|
7
|
+
# after we support Http.File case, enable these tests again
|
|
8
|
+
|
|
9
|
+
# import json
|
|
10
|
+
|
|
11
|
+
# import pytest
|
|
12
|
+
# from typetest.file import FileClient
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# @pytest.fixture
|
|
16
|
+
# def client():
|
|
17
|
+
# with FileClient(endpoint="http://localhost:3000") as client:
|
|
18
|
+
# yield client
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# def test_upload_file_specific_content_type(client: FileClient, png_data: bytes):
|
|
22
|
+
# client.body.upload_file_specific_content_type(png_data)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# # Do not support this case for now
|
|
26
|
+
# # def test_upload_file_json_content_type(client: FileClient):
|
|
27
|
+
# # client.body.upload_file_json_content_type(json.dumps({"message": "test file content"}).encode())
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# # although result is expected but actually there is deserialization issue
|
|
31
|
+
# # def test_download_file_json_content_type(client: FileClient):
|
|
32
|
+
# # result = client.body.download_file_json_content_type()
|
|
33
|
+
# # assert result == {"message": "test file content"}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# def test_download_file_specific_content_type(client: FileClient, png_data: bytes):
|
|
37
|
+
# result = b"".join(client.body.download_file_specific_content_type())
|
|
38
|
+
# assert result == png_data
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# def test_download_file_multiple_content_types(client: FileClient, png_data: bytes):
|
|
42
|
+
# result = b"".join(client.body.download_file_multiple_content_types())
|
|
43
|
+
# assert result == png_data
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# def test_upload_file_default_content_type(client: FileClient, png_data: bytes):
|
|
47
|
+
# client.body.upload_file_default_content_type(png_data, content_type="image/png")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# def test_download_file_default_content_type(client: FileClient, png_data: bytes):
|
|
51
|
+
# result = b"".join(client.body.download_file_default_content_type())
|
|
52
|
+
# assert result == png_data
|
|
@@ -8,6 +8,7 @@ import pytest
|
|
|
8
8
|
from payload.multipart import models
|
|
9
9
|
from payload.multipart.aio import MultiPartClient
|
|
10
10
|
from payload.multipart.formdata.httpparts.nonstring.models import FloatRequest
|
|
11
|
+
from payload.multipart.formdata.file import models as file_models
|
|
11
12
|
|
|
12
13
|
JPG = Path(__file__).parent.parent / "data/image.jpg"
|
|
13
14
|
PNG = Path(__file__).parent.parent / "data/image.png"
|
|
@@ -185,3 +186,33 @@ async def test_optional_parts(client: MultiPartClient):
|
|
|
185
186
|
profile_image=open(str(JPG), "rb"),
|
|
186
187
|
)
|
|
187
188
|
)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
@pytest.mark.asyncio
|
|
192
|
+
async def test_file_upload_file_specific_content_type(client: MultiPartClient):
|
|
193
|
+
await client.form_data.file.upload_file_specific_content_type(
|
|
194
|
+
file_models.UploadFileSpecificContentTypeRequest(
|
|
195
|
+
file=("image.png", open(str(PNG), "rb"), "image/png"),
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@pytest.mark.asyncio
|
|
201
|
+
async def test_file_upload_file_required_filename(client: MultiPartClient):
|
|
202
|
+
await client.form_data.file.upload_file_required_filename(
|
|
203
|
+
file_models.UploadFileRequiredFilenameRequest(
|
|
204
|
+
file=("image.png", open(str(PNG), "rb"), "image/png"),
|
|
205
|
+
)
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
@pytest.mark.asyncio
|
|
210
|
+
async def test_file_upload_file_array(client: MultiPartClient):
|
|
211
|
+
await client.form_data.file.upload_file_array(
|
|
212
|
+
file_models.UploadFileArrayRequest(
|
|
213
|
+
files=[
|
|
214
|
+
("image.png", open(str(PNG), "rb"), "image/png"),
|
|
215
|
+
("image.png", open(str(PNG), "rb"), "image/png"),
|
|
216
|
+
],
|
|
217
|
+
)
|
|
218
|
+
)
|
|
@@ -7,6 +7,7 @@ from pathlib import Path
|
|
|
7
7
|
import pytest
|
|
8
8
|
from payload.multipart import MultiPartClient, models
|
|
9
9
|
from payload.multipart.formdata.httpparts.nonstring.models import FloatRequest
|
|
10
|
+
from payload.multipart.formdata.file import models as file_models
|
|
10
11
|
|
|
11
12
|
JPG = Path(__file__).parent / "data/image.jpg"
|
|
12
13
|
PNG = Path(__file__).parent / "data/image.png"
|
|
@@ -170,3 +171,30 @@ def test_optional_parts(client: MultiPartClient):
|
|
|
170
171
|
profile_image=open(str(JPG), "rb"),
|
|
171
172
|
)
|
|
172
173
|
)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def test_file_upload_file_specific_content_type(client: MultiPartClient):
|
|
177
|
+
client.form_data.file.upload_file_specific_content_type(
|
|
178
|
+
file_models.UploadFileSpecificContentTypeRequest(
|
|
179
|
+
file=("image.png", open(str(PNG), "rb"), "image/png"),
|
|
180
|
+
)
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def test_file_upload_file_required_filename(client: MultiPartClient):
|
|
185
|
+
client.form_data.file.upload_file_required_filename(
|
|
186
|
+
file_models.UploadFileRequiredFilenameRequest(
|
|
187
|
+
file=("image.png", open(str(PNG), "rb"), "image/png"),
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def test_file_upload_file_array(client: MultiPartClient):
|
|
193
|
+
client.form_data.file.upload_file_array(
|
|
194
|
+
file_models.UploadFileArrayRequest(
|
|
195
|
+
files=[
|
|
196
|
+
("image.png", open(str(PNG), "rb"), "image/png"),
|
|
197
|
+
("image.png", open(str(PNG), "rb"), "image/png"),
|
|
198
|
+
],
|
|
199
|
+
)
|
|
200
|
+
)
|
|
@@ -54,11 +54,12 @@ def test_sensitive_word():
|
|
|
54
54
|
check_folder = (Path(os.path.dirname(__file__)) / "../generated").resolve()
|
|
55
55
|
assert [] == check_sensitive_word(check_folder, "azure")
|
|
56
56
|
# after update spector, it shall also equal to []
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
expected = [
|
|
58
|
+
"authentication-oauth2",
|
|
59
|
+
"authentication-noauth-union",
|
|
60
|
+
"authentication-union",
|
|
61
|
+
"setuppy-authentication-union",
|
|
62
|
+
]
|
|
63
|
+
if (check_folder / "generation-subdir").exists():
|
|
64
|
+
expected.append("generation-subdir")
|
|
65
|
+
assert sorted(expected) == sorted(check_sensitive_word(check_folder, "microsoft"))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
-r ../dev_requirements.txt
|
|
2
2
|
-e ../../
|
|
3
3
|
|
|
4
|
-
# common test
|
|
4
|
+
# === common test dependencies across repos ===
|
|
5
5
|
-e ./generated/authentication-api-key
|
|
6
6
|
-e ./generated/authentication-http-custom
|
|
7
7
|
-e ./generated/authentication-noauth-union
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
-e ./generated/typetest-dictionary
|
|
30
30
|
-e ./generated/typetest-enum-extensible
|
|
31
31
|
-e ./generated/typetest-enum-fixed
|
|
32
|
+
# -e ./generated/typetest-file
|
|
32
33
|
-e ./generated/typetest-model-enumdiscriminator
|
|
33
34
|
-e ./generated/typetest-model-nesteddiscriminator
|
|
34
35
|
-e ./generated/typetest-model-notdiscriminated
|
|
@@ -65,3 +66,4 @@
|
|
|
65
66
|
-e ./generated/versioning-renamedfrom
|
|
66
67
|
-e ./generated/versioning-returntypechangedfrom
|
|
67
68
|
-e ./generated/versioning-typechangedfrom
|
|
69
|
+
# === end common test dependencies across repos ===
|
|
@@ -4743,3 +4743,164 @@ def test_dictionary_set_datetime():
|
|
|
4743
4743
|
assert dict_ref1 is dict_ref2
|
|
4744
4744
|
assert isinstance(dict_ref1["start"], datetime)
|
|
4745
4745
|
assert isinstance(dict_ref2["start"], datetime)
|
|
4746
|
+
|
|
4747
|
+
|
|
4748
|
+
def test_eq_same_model_instances():
|
|
4749
|
+
"""Two model instances with the same data should be equal."""
|
|
4750
|
+
model1 = BasicResource(
|
|
4751
|
+
platform_update_domain_count=5,
|
|
4752
|
+
platform_fault_domain_count=3,
|
|
4753
|
+
virtual_machines=[],
|
|
4754
|
+
)
|
|
4755
|
+
model2 = BasicResource(
|
|
4756
|
+
platform_update_domain_count=5,
|
|
4757
|
+
platform_fault_domain_count=3,
|
|
4758
|
+
virtual_machines=[],
|
|
4759
|
+
)
|
|
4760
|
+
assert model1 == model2
|
|
4761
|
+
|
|
4762
|
+
|
|
4763
|
+
def test_eq_different_model_data():
|
|
4764
|
+
"""Two model instances with different data should not be equal."""
|
|
4765
|
+
model1 = BasicResource(
|
|
4766
|
+
platform_update_domain_count=5,
|
|
4767
|
+
platform_fault_domain_count=3,
|
|
4768
|
+
virtual_machines=[],
|
|
4769
|
+
)
|
|
4770
|
+
model2 = BasicResource(
|
|
4771
|
+
platform_update_domain_count=10,
|
|
4772
|
+
platform_fault_domain_count=3,
|
|
4773
|
+
virtual_machines=[],
|
|
4774
|
+
)
|
|
4775
|
+
assert model1 != model2
|
|
4776
|
+
|
|
4777
|
+
|
|
4778
|
+
def test_eq_model_constructed_from_dict():
|
|
4779
|
+
"""A model created via kwargs and a model created from a dict should be equal."""
|
|
4780
|
+
dict_response = {
|
|
4781
|
+
"platformUpdateDomainCount": 5,
|
|
4782
|
+
"platformFaultDomainCount": 3,
|
|
4783
|
+
"virtualMachines": [],
|
|
4784
|
+
}
|
|
4785
|
+
model_from_kwargs = BasicResource(
|
|
4786
|
+
platform_update_domain_count=5,
|
|
4787
|
+
platform_fault_domain_count=3,
|
|
4788
|
+
virtual_machines=[],
|
|
4789
|
+
)
|
|
4790
|
+
model_from_dict = BasicResource(dict_response)
|
|
4791
|
+
assert model_from_kwargs == model_from_dict
|
|
4792
|
+
|
|
4793
|
+
|
|
4794
|
+
def test_eq_model_equal_to_plain_dict():
|
|
4795
|
+
"""A model should be equal to a plain dict with matching data (backward compat)."""
|
|
4796
|
+
dict_response = {
|
|
4797
|
+
"platformUpdateDomainCount": 5,
|
|
4798
|
+
"platformFaultDomainCount": 3,
|
|
4799
|
+
"virtualMachines": [],
|
|
4800
|
+
}
|
|
4801
|
+
model = BasicResource(
|
|
4802
|
+
platform_update_domain_count=5,
|
|
4803
|
+
platform_fault_domain_count=3,
|
|
4804
|
+
virtual_machines=[],
|
|
4805
|
+
)
|
|
4806
|
+
assert model == dict_response
|
|
4807
|
+
|
|
4808
|
+
|
|
4809
|
+
def test_eq_model_not_equal_to_non_model_types():
|
|
4810
|
+
"""A model should not be equal to strings, ints, None, or lists."""
|
|
4811
|
+
model = BasicResource(
|
|
4812
|
+
platform_update_domain_count=5,
|
|
4813
|
+
platform_fault_domain_count=3,
|
|
4814
|
+
virtual_machines=[],
|
|
4815
|
+
)
|
|
4816
|
+
assert model != "some string"
|
|
4817
|
+
assert model != 42
|
|
4818
|
+
assert model != None # noqa: E711
|
|
4819
|
+
assert model != []
|
|
4820
|
+
assert model != True # noqa: E712
|
|
4821
|
+
|
|
4822
|
+
|
|
4823
|
+
def test_eq_different_model_types_same_data():
|
|
4824
|
+
"""Two different model types with the same underlying _data should be equal
|
|
4825
|
+
since isinstance checks against _MyMutableMapping, not the specific subclass."""
|
|
4826
|
+
model1 = Pet(name="test", species="dog")
|
|
4827
|
+
|
|
4828
|
+
class AnotherModel(Model):
|
|
4829
|
+
name: str = rest_field()
|
|
4830
|
+
species: str = rest_field()
|
|
4831
|
+
|
|
4832
|
+
@overload
|
|
4833
|
+
def __init__(self, *, name: str, species: str): ...
|
|
4834
|
+
|
|
4835
|
+
@overload
|
|
4836
|
+
def __init__(self, mapping: Mapping[str, Any], /): ...
|
|
4837
|
+
|
|
4838
|
+
def __init__(self, *args, **kwargs):
|
|
4839
|
+
super().__init__(*args, **kwargs)
|
|
4840
|
+
|
|
4841
|
+
model2 = AnotherModel(name="test", species="dog")
|
|
4842
|
+
assert model1 == model2
|
|
4843
|
+
|
|
4844
|
+
|
|
4845
|
+
def test_ne_is_inverse_of_eq():
|
|
4846
|
+
"""__ne__ should return the inverse of __eq__."""
|
|
4847
|
+
model1 = BasicResource(
|
|
4848
|
+
platform_update_domain_count=5,
|
|
4849
|
+
platform_fault_domain_count=3,
|
|
4850
|
+
virtual_machines=[],
|
|
4851
|
+
)
|
|
4852
|
+
model2 = BasicResource(
|
|
4853
|
+
platform_update_domain_count=5,
|
|
4854
|
+
platform_fault_domain_count=3,
|
|
4855
|
+
virtual_machines=[],
|
|
4856
|
+
)
|
|
4857
|
+
model3 = BasicResource(
|
|
4858
|
+
platform_update_domain_count=10,
|
|
4859
|
+
platform_fault_domain_count=3,
|
|
4860
|
+
virtual_machines=[],
|
|
4861
|
+
)
|
|
4862
|
+
assert not (model1 != model2)
|
|
4863
|
+
assert model1 != model3
|
|
4864
|
+
|
|
4865
|
+
|
|
4866
|
+
def test_eq_nested_models():
|
|
4867
|
+
"""Two models with identical nested model children should be equal."""
|
|
4868
|
+
model1 = OptionalModel(
|
|
4869
|
+
optional_str="hello",
|
|
4870
|
+
optional_time=datetime.time(11, 34, 56),
|
|
4871
|
+
optional_dict={
|
|
4872
|
+
"buddy": Pet(name="Buddy", species="Dog"),
|
|
4873
|
+
},
|
|
4874
|
+
optional_myself=OptionalModel(optional_str="inner"),
|
|
4875
|
+
)
|
|
4876
|
+
model2 = OptionalModel(
|
|
4877
|
+
optional_str="hello",
|
|
4878
|
+
optional_time=datetime.time(11, 34, 56),
|
|
4879
|
+
optional_dict={
|
|
4880
|
+
"buddy": Pet(name="Buddy", species="Dog"),
|
|
4881
|
+
},
|
|
4882
|
+
optional_myself=OptionalModel(optional_str="inner"),
|
|
4883
|
+
)
|
|
4884
|
+
assert model1 == model2
|
|
4885
|
+
|
|
4886
|
+
# Change the nested model's data — they should no longer be equal
|
|
4887
|
+
model2_different_inner = OptionalModel(
|
|
4888
|
+
optional_str="hello",
|
|
4889
|
+
optional_time=datetime.time(11, 34, 56),
|
|
4890
|
+
optional_dict={
|
|
4891
|
+
"buddy": Pet(name="Buddy", species="Dog"),
|
|
4892
|
+
},
|
|
4893
|
+
optional_myself=OptionalModel(optional_str="different"),
|
|
4894
|
+
)
|
|
4895
|
+
assert model1 != model2_different_inner
|
|
4896
|
+
|
|
4897
|
+
# Change the nested Pet — they should no longer be equal
|
|
4898
|
+
model2_different_pet = OptionalModel(
|
|
4899
|
+
optional_str="hello",
|
|
4900
|
+
optional_time=datetime.time(11, 34, 56),
|
|
4901
|
+
optional_dict={
|
|
4902
|
+
"buddy": Pet(name="Max", species="Cat"),
|
|
4903
|
+
},
|
|
4904
|
+
optional_myself=OptionalModel(optional_str="inner"),
|
|
4905
|
+
)
|
|
4906
|
+
assert model1 != model2_different_pet
|