@typespec/http-client-python 0.6.2 → 0.6.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.
- package/eng/scripts/ci/regenerate.ts +25 -8
- package/eng/scripts/setup/__pycache__/venvtools.cpython-38.pyc +0 -0
- package/generator/build/lib/pygen/codegen/models/code_model.py +4 -0
- package/generator/build/lib/pygen/codegen/models/combined_type.py +4 -3
- package/generator/build/lib/pygen/codegen/models/credential_types.py +4 -0
- package/generator/build/lib/pygen/codegen/models/operation.py +8 -2
- package/generator/build/lib/pygen/codegen/models/operation_group.py +26 -1
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +1 -1
- package/generator/build/lib/pygen/codegen/models/property.py +2 -2
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +12 -2
- package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +2 -2
- package/generator/build/lib/pygen/codegen/serializers/operation_groups_serializer.py +1 -0
- package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +4 -4
- package/generator/build/lib/pygen/codegen/templates/operation_groups_container.py.jinja2 +2 -0
- package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +2 -68
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/models/code_model.py +4 -0
- package/generator/pygen/codegen/models/combined_type.py +4 -3
- package/generator/pygen/codegen/models/credential_types.py +4 -0
- package/generator/pygen/codegen/models/operation.py +8 -2
- package/generator/pygen/codegen/models/operation_group.py +26 -1
- package/generator/pygen/codegen/models/paging_operation.py +1 -1
- package/generator/pygen/codegen/models/property.py +2 -2
- package/generator/pygen/codegen/serializers/__init__.py +12 -2
- package/generator/pygen/codegen/serializers/model_serializer.py +2 -2
- package/generator/pygen/codegen/serializers/operation_groups_serializer.py +1 -0
- package/generator/pygen/codegen/templates/operation_group.py.jinja2 +4 -4
- package/generator/pygen/codegen/templates/operation_groups_container.py.jinja2 +2 -0
- package/generator/pygen/codegen/templates/serialization.py.jinja2 +2 -68
- package/generator/test/azure/mock_api_tests/conftest.py +57 -1
- package/generator/test/azure/mock_api_tests/data/image.jpg +0 -0
- package/generator/test/azure/mock_api_tests/data/image.png +0 -0
- package/generator/test/generic_mock_api_tests/conftest.py +0 -43
- package/generator/test/unbranded/mock_api_tests/asynctests/test_encode_duration_async.py +63 -0
- package/generator/test/unbranded/mock_api_tests/asynctests/test_encode_numeric_async.py +35 -0
- package/generator/test/unbranded/mock_api_tests/asynctests/test_parameters_basic_async.py +24 -0
- package/generator/test/unbranded/mock_api_tests/asynctests/test_parameters_spread_async.py +76 -0
- package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_content_negotiation_async.py +37 -0
- package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_multipart_async.py +154 -0
- package/generator/test/unbranded/mock_api_tests/asynctests/test_serialization_encoded_name_json_async.py +24 -0
- package/generator/test/unbranded/mock_api_tests/asynctests/test_special_words_async.py +43 -0
- package/generator/test/unbranded/mock_api_tests/conftest.py +57 -0
- package/generator/test/unbranded/mock_api_tests/data/image.jpg +0 -0
- package/generator/test/unbranded/mock_api_tests/data/image.png +0 -0
- package/generator/test/unbranded/mock_api_tests/test_encode_duration.py +60 -0
- package/generator/test/unbranded/mock_api_tests/test_encode_numeric.py +32 -0
- package/generator/test/unbranded/mock_api_tests/test_parameters_basic.py +22 -0
- package/generator/test/unbranded/mock_api_tests/test_parameters_spread.py +66 -0
- package/generator/test/unbranded/mock_api_tests/test_payload_content_negotiation.py +33 -0
- package/generator/test/unbranded/mock_api_tests/test_payload_multipart.py +141 -0
- package/generator/test/unbranded/mock_api_tests/test_serialization_encoded_name_json.py +22 -0
- package/generator/test/unbranded/mock_api_tests/test_special_words.py +39 -0
- package/package.json +1 -1
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_encode_duration_async.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_encode_numeric_async.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_parameters_basic_async.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_parameters_spread_async.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_payload_content_negotiation_async.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_payload_multipart_async.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_serialization_encoded_name_json_async.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_special_words_async.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_encode_duration.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_encode_numeric.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_parameters_basic.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_parameters_spread.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_payload_content_negotiation.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_payload_multipart.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_serialization_encoded_name_json.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_special_words.py +0 -0
|
@@ -184,73 +184,7 @@ try:
|
|
|
184
184
|
except NameError:
|
|
185
185
|
_long_type = int
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
class UTC(datetime.tzinfo):
|
|
189
|
-
"""Time Zone info for handling UTC"""
|
|
190
|
-
|
|
191
|
-
def utcoffset(self, dt):
|
|
192
|
-
"""UTF offset for UTC is 0.
|
|
193
|
-
|
|
194
|
-
:param datetime.datetime dt: The datetime
|
|
195
|
-
:returns: The offset
|
|
196
|
-
:rtype: datetime.timedelta
|
|
197
|
-
"""
|
|
198
|
-
return datetime.timedelta(0)
|
|
199
|
-
|
|
200
|
-
def tzname(self, dt):
|
|
201
|
-
"""Timestamp representation.
|
|
202
|
-
|
|
203
|
-
:param datetime.datetime dt: The datetime
|
|
204
|
-
:returns: The timestamp representation
|
|
205
|
-
:rtype: str
|
|
206
|
-
"""
|
|
207
|
-
return "Z"
|
|
208
|
-
|
|
209
|
-
def dst(self, dt):
|
|
210
|
-
"""No daylight saving for UTC.
|
|
211
|
-
|
|
212
|
-
:param datetime.datetime dt: The datetime
|
|
213
|
-
:returns: The daylight saving time
|
|
214
|
-
:rtype: datetime.timedelta
|
|
215
|
-
"""
|
|
216
|
-
return datetime.timedelta(hours=1)
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
try:
|
|
220
|
-
from datetime import timezone as _FixedOffset # type: ignore
|
|
221
|
-
except ImportError: # Python 2.7
|
|
222
|
-
|
|
223
|
-
class _FixedOffset(datetime.tzinfo): # type: ignore
|
|
224
|
-
"""Fixed offset in minutes east from UTC.
|
|
225
|
-
Copy/pasted from Python doc
|
|
226
|
-
:param datetime.timedelta offset: offset in timedelta format
|
|
227
|
-
"""
|
|
228
|
-
|
|
229
|
-
def __init__(self, offset) -> None:
|
|
230
|
-
self.__offset = offset
|
|
231
|
-
|
|
232
|
-
def utcoffset(self, dt):
|
|
233
|
-
return self.__offset
|
|
234
|
-
|
|
235
|
-
def tzname(self, dt):
|
|
236
|
-
return str(self.__offset.total_seconds() / 3600)
|
|
237
|
-
|
|
238
|
-
def __repr__(self):
|
|
239
|
-
return "<FixedOffset {}>".format(self.tzname(None))
|
|
240
|
-
|
|
241
|
-
def dst(self, dt):
|
|
242
|
-
return datetime.timedelta(0)
|
|
243
|
-
|
|
244
|
-
def __getinitargs__(self):
|
|
245
|
-
return (self.__offset,)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
try:
|
|
249
|
-
from datetime import timezone
|
|
250
|
-
|
|
251
|
-
TZ_UTC = timezone.utc
|
|
252
|
-
except ImportError:
|
|
253
|
-
TZ_UTC = UTC() # type: ignore
|
|
187
|
+
TZ_UTC = datetime.timezone.utc
|
|
254
188
|
|
|
255
189
|
_FLATTEN = re.compile(r"(?<!\\)\.")
|
|
256
190
|
|
|
@@ -2050,7 +1984,7 @@ class Deserializer:
|
|
|
2050
1984
|
try:
|
|
2051
1985
|
parsed_date = email.utils.parsedate_tz(attr) # type: ignore
|
|
2052
1986
|
date_obj = datetime.datetime(
|
|
2053
|
-
*parsed_date[:6], tzinfo=
|
|
1987
|
+
*parsed_date[:6], tzinfo=datetime.timezone(datetime.timedelta(minutes=(parsed_date[9] or 0) / 60))
|
|
2054
1988
|
)
|
|
2055
1989
|
if not date_obj.tzinfo:
|
|
2056
1990
|
date_obj = date_obj.astimezone(tz=TZ_UTC)
|
|
@@ -8,9 +8,11 @@ import subprocess
|
|
|
8
8
|
import signal
|
|
9
9
|
import pytest
|
|
10
10
|
import re
|
|
11
|
-
from typing import Literal
|
|
11
|
+
from typing import Literal, List
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
|
|
14
|
+
FILE_FOLDER = Path(__file__).parent
|
|
15
|
+
|
|
14
16
|
|
|
15
17
|
def start_server_process():
|
|
16
18
|
azure_http_path = Path(os.path.dirname(__file__)) / Path("../../../../node_modules/@azure-tools/azure-http-specs")
|
|
@@ -149,3 +151,57 @@ def authentication_policy():
|
|
|
149
151
|
from azure.core.pipeline.policies import SansIOHTTPPolicy
|
|
150
152
|
|
|
151
153
|
return SansIOHTTPPolicy()
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
SPECIAL_WORDS = [
|
|
157
|
+
"and",
|
|
158
|
+
"as",
|
|
159
|
+
"assert",
|
|
160
|
+
"async",
|
|
161
|
+
"await",
|
|
162
|
+
"break",
|
|
163
|
+
"class",
|
|
164
|
+
"constructor",
|
|
165
|
+
"continue",
|
|
166
|
+
"def",
|
|
167
|
+
"del",
|
|
168
|
+
"elif",
|
|
169
|
+
"else",
|
|
170
|
+
"except",
|
|
171
|
+
"exec",
|
|
172
|
+
"finally",
|
|
173
|
+
"for",
|
|
174
|
+
"from",
|
|
175
|
+
"global",
|
|
176
|
+
"if",
|
|
177
|
+
"import",
|
|
178
|
+
"in",
|
|
179
|
+
"is",
|
|
180
|
+
"lambda",
|
|
181
|
+
"not",
|
|
182
|
+
"or",
|
|
183
|
+
"pass",
|
|
184
|
+
"raise",
|
|
185
|
+
"return",
|
|
186
|
+
"try",
|
|
187
|
+
"while",
|
|
188
|
+
"with",
|
|
189
|
+
"yield",
|
|
190
|
+
]
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@pytest.fixture
|
|
194
|
+
def special_words() -> List[str]:
|
|
195
|
+
return SPECIAL_WORDS
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
@pytest.fixture
|
|
199
|
+
def png_data() -> bytes:
|
|
200
|
+
with open(str(FILE_FOLDER / "data/image.png"), "rb") as file_in:
|
|
201
|
+
return file_in.read()
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@pytest.fixture
|
|
205
|
+
def jpg_data() -> bytes:
|
|
206
|
+
with open(str(FILE_FOLDER / "data/image.jpg"), "rb") as file_in:
|
|
207
|
+
return file_in.read()
|
|
Binary file
|
|
Binary file
|
|
@@ -9,7 +9,6 @@ import signal
|
|
|
9
9
|
import pytest
|
|
10
10
|
import importlib
|
|
11
11
|
from pathlib import Path
|
|
12
|
-
from typing import List
|
|
13
12
|
|
|
14
13
|
FILE_FOLDER = Path(__file__).parent
|
|
15
14
|
|
|
@@ -64,48 +63,6 @@ def key_credential(core_library):
|
|
|
64
63
|
return core_library.credentials.ServiceKeyCredential
|
|
65
64
|
|
|
66
65
|
|
|
67
|
-
SPECIAL_WORDS = [
|
|
68
|
-
"and",
|
|
69
|
-
"as",
|
|
70
|
-
"assert",
|
|
71
|
-
"async",
|
|
72
|
-
"await",
|
|
73
|
-
"break",
|
|
74
|
-
"class",
|
|
75
|
-
"constructor",
|
|
76
|
-
"continue",
|
|
77
|
-
"def",
|
|
78
|
-
"del",
|
|
79
|
-
"elif",
|
|
80
|
-
"else",
|
|
81
|
-
"except",
|
|
82
|
-
"exec",
|
|
83
|
-
"finally",
|
|
84
|
-
"for",
|
|
85
|
-
"from",
|
|
86
|
-
"global",
|
|
87
|
-
"if",
|
|
88
|
-
"import",
|
|
89
|
-
"in",
|
|
90
|
-
"is",
|
|
91
|
-
"lambda",
|
|
92
|
-
"not",
|
|
93
|
-
"or",
|
|
94
|
-
"pass",
|
|
95
|
-
"raise",
|
|
96
|
-
"return",
|
|
97
|
-
"try",
|
|
98
|
-
"while",
|
|
99
|
-
"with",
|
|
100
|
-
"yield",
|
|
101
|
-
]
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
@pytest.fixture
|
|
105
|
-
def special_words() -> List[str]:
|
|
106
|
-
return SPECIAL_WORDS
|
|
107
|
-
|
|
108
|
-
|
|
109
66
|
@pytest.fixture
|
|
110
67
|
def png_data() -> bytes:
|
|
111
68
|
with open(str(FILE_FOLDER / "data/image.png"), "rb") as file_in:
|
|
@@ -0,0 +1,63 @@
|
|
|
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 datetime
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from encode.duration.aio import DurationClient
|
|
10
|
+
from encode.duration.property.models import (
|
|
11
|
+
Int32SecondsDurationProperty,
|
|
12
|
+
ISO8601DurationProperty,
|
|
13
|
+
FloatSecondsDurationProperty,
|
|
14
|
+
DefaultDurationProperty,
|
|
15
|
+
FloatSecondsDurationArrayProperty,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.fixture
|
|
20
|
+
async def client():
|
|
21
|
+
async with DurationClient() as client:
|
|
22
|
+
yield client
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.mark.asyncio
|
|
26
|
+
async def test_query(client: DurationClient):
|
|
27
|
+
await client.query.default(input=datetime.timedelta(days=40))
|
|
28
|
+
await client.query.iso8601(input=datetime.timedelta(days=40))
|
|
29
|
+
await client.query.int32_seconds(input=36)
|
|
30
|
+
await client.query.int32_seconds_array(input=[36, 47])
|
|
31
|
+
await client.query.float_seconds(input=35.625)
|
|
32
|
+
await client.query.float64_seconds(input=35.625)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.asyncio
|
|
36
|
+
async def test_property(client: DurationClient):
|
|
37
|
+
result = await client.property.default(DefaultDurationProperty(value=datetime.timedelta(days=40)))
|
|
38
|
+
assert result.value == datetime.timedelta(days=40)
|
|
39
|
+
result = await client.property.default(DefaultDurationProperty(value="P40D"))
|
|
40
|
+
assert result.value == datetime.timedelta(days=40)
|
|
41
|
+
result = await client.property.iso8601(ISO8601DurationProperty(value=datetime.timedelta(days=40)))
|
|
42
|
+
assert result.value == datetime.timedelta(days=40)
|
|
43
|
+
result = await client.property.iso8601(ISO8601DurationProperty(value="P40D"))
|
|
44
|
+
assert result.value == datetime.timedelta(days=40)
|
|
45
|
+
result = await client.property.int32_seconds(Int32SecondsDurationProperty(value=36))
|
|
46
|
+
assert result.value == 36
|
|
47
|
+
result = await client.property.float_seconds(FloatSecondsDurationProperty(value=35.625))
|
|
48
|
+
assert abs(result.value - 35.625) < 0.0001
|
|
49
|
+
result = await client.property.float64_seconds(FloatSecondsDurationProperty(value=35.625))
|
|
50
|
+
assert abs(result.value - 35.625) < 0.0001
|
|
51
|
+
result = await client.property.float_seconds_array(FloatSecondsDurationArrayProperty(value=[35.625, 46.75]))
|
|
52
|
+
assert abs(result.value[0] - 35.625) < 0.0001
|
|
53
|
+
assert abs(result.value[1] - 46.75) < 0.0001
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@pytest.mark.asyncio
|
|
57
|
+
async def test_header(client: DurationClient):
|
|
58
|
+
await client.header.default(duration=datetime.timedelta(days=40))
|
|
59
|
+
await client.header.iso8601(duration=datetime.timedelta(days=40))
|
|
60
|
+
await client.header.iso8601_array(duration=[datetime.timedelta(days=40), datetime.timedelta(days=50)])
|
|
61
|
+
await client.header.int32_seconds(duration=36)
|
|
62
|
+
await client.header.float_seconds(duration=35.625)
|
|
63
|
+
await client.header.float64_seconds(duration=35.625)
|
|
@@ -0,0 +1,35 @@
|
|
|
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 encode.numeric.aio import NumericClient
|
|
8
|
+
from encode.numeric.property import models
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture
|
|
12
|
+
async def client():
|
|
13
|
+
async with NumericClient() as client:
|
|
14
|
+
yield client
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.mark.asyncio
|
|
18
|
+
async def test_safeint_as_string(client: NumericClient):
|
|
19
|
+
result = await client.property.safeint_as_string(models.SafeintAsStringProperty(value=10000000000))
|
|
20
|
+
assert result.value == 10000000000
|
|
21
|
+
assert result["value"] == "10000000000"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@pytest.mark.asyncio
|
|
25
|
+
async def test_uint32_as_string_optional(client: NumericClient):
|
|
26
|
+
result = await client.property.uint32_as_string_optional(models.Uint32AsStringProperty(value=1))
|
|
27
|
+
assert result.value == 1
|
|
28
|
+
assert result["value"] == "1"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@pytest.mark.asyncio
|
|
32
|
+
async def test_uint8_as_string_optional(client: NumericClient):
|
|
33
|
+
result = await client.property.uint8_as_string(models.Uint32AsStringProperty(value=255))
|
|
34
|
+
assert result.value == 255
|
|
35
|
+
assert result["value"] == "255"
|
|
@@ -0,0 +1,24 @@
|
|
|
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 parameters.basic.aio import BasicClient
|
|
8
|
+
from parameters.basic.explicitbody.models import User
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture
|
|
12
|
+
async def client():
|
|
13
|
+
async with BasicClient() as client:
|
|
14
|
+
yield client
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.mark.asyncio
|
|
18
|
+
async def test_explicit_simple(client: BasicClient):
|
|
19
|
+
await client.explicit_body.simple(User(name="foo"))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.mark.asyncio
|
|
23
|
+
async def test_implicit_simple(client: BasicClient):
|
|
24
|
+
await client.implicit_body.simple(name="foo")
|
|
@@ -0,0 +1,76 @@
|
|
|
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 parameters.spread.aio import SpreadClient
|
|
8
|
+
from parameters.spread.model.models import BodyParameter
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture
|
|
12
|
+
async def client():
|
|
13
|
+
async with SpreadClient() as client:
|
|
14
|
+
yield client
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.mark.asyncio
|
|
18
|
+
async def test_model_body(client: SpreadClient):
|
|
19
|
+
await client.model.spread_as_request_body(name="foo")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.mark.asyncio
|
|
23
|
+
async def test_model_composite_request_only_with_body(client: SpreadClient):
|
|
24
|
+
await client.model.spread_composite_request_only_with_body(BodyParameter(name="foo"))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.mark.asyncio
|
|
28
|
+
async def test_model_composite_request_without_body(client: SpreadClient):
|
|
29
|
+
await client.model.spread_composite_request_without_body(name="foo", test_header="bar")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.mark.asyncio
|
|
33
|
+
async def test_model_composite_request(client: SpreadClient):
|
|
34
|
+
await client.model.spread_composite_request(name="foo", body=BodyParameter(name="foo"), test_header="bar")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.mark.asyncio
|
|
38
|
+
async def test_model_composite_request_mix(client: SpreadClient):
|
|
39
|
+
await client.model.spread_composite_request_mix(name="foo", prop="foo", test_header="bar")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@pytest.mark.asyncio
|
|
43
|
+
async def test_alias_body(client: SpreadClient):
|
|
44
|
+
await client.alias.spread_as_request_body(name="foo")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.asyncio
|
|
48
|
+
async def test_alias_parameter(client: SpreadClient):
|
|
49
|
+
await client.alias.spread_as_request_parameter("1", x_ms_test_header="bar", name="foo")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@pytest.mark.asyncio
|
|
53
|
+
async def test_alias_multiple_parameter(client: SpreadClient):
|
|
54
|
+
await client.alias.spread_with_multiple_parameters(
|
|
55
|
+
"1",
|
|
56
|
+
x_ms_test_header="bar",
|
|
57
|
+
required_string="foo",
|
|
58
|
+
required_int_list=[1, 2],
|
|
59
|
+
optional_string_list=["foo", "bar"],
|
|
60
|
+
optional_int=1,
|
|
61
|
+
)
|
|
62
|
+
await client.alias.spread_with_multiple_parameters(
|
|
63
|
+
"1",
|
|
64
|
+
{"requiredString": "foo", "optionalInt": 1, "requiredIntList": [1, 2], "optionalStringList": ["foo", "bar"]},
|
|
65
|
+
x_ms_test_header="bar",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@pytest.mark.asyncio
|
|
70
|
+
async def test_inner_model(client: SpreadClient):
|
|
71
|
+
await client.alias.spread_parameter_with_inner_model(id="1", x_ms_test_header="bar", body={"name": "foo"})
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@pytest.mark.asyncio
|
|
75
|
+
async def test_inner_alias(client: SpreadClient):
|
|
76
|
+
await client.alias.spread_parameter_with_inner_alias(id="1", x_ms_test_header="bar", body={"name": "foo", "age": 1})
|
package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_content_negotiation_async.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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 base64
|
|
7
|
+
import pytest
|
|
8
|
+
from payload.contentnegotiation.aio import ContentNegotiationClient
|
|
9
|
+
from payload.contentnegotiation.differentbody.models import PngImageAsJson
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.fixture
|
|
13
|
+
async def client():
|
|
14
|
+
async with ContentNegotiationClient(endpoint="http://localhost:3000") as client:
|
|
15
|
+
yield client
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.mark.asyncio
|
|
19
|
+
async def test_get_avatar_as_png(client: ContentNegotiationClient, png_data: bytes):
|
|
20
|
+
assert b"".join([d async for d in (await client.same_body.get_avatar_as_png())]) == png_data
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@pytest.mark.asyncio
|
|
24
|
+
async def test_get_avatar_as_jpeg(client: ContentNegotiationClient, jpg_data: bytes):
|
|
25
|
+
assert b"".join([d async for d in (await client.same_body.get_avatar_as_jpeg())]) == jpg_data
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.mark.asyncio
|
|
29
|
+
async def test_different_body_get_avatar_as_png(client: ContentNegotiationClient, png_data: bytes):
|
|
30
|
+
assert b"".join([d async for d in (await client.different_body.get_avatar_as_png())]) == png_data
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.asyncio
|
|
34
|
+
async def test_different_body_get_avatar_as_json(client: ContentNegotiationClient, png_data: bytes):
|
|
35
|
+
result = await client.different_body.get_avatar_as_json()
|
|
36
|
+
expected = PngImageAsJson(content=base64.b64encode(png_data).decode())
|
|
37
|
+
assert result == expected
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
from pathlib import Path
|
|
7
|
+
import pytest
|
|
8
|
+
from payload.multipart import models
|
|
9
|
+
from payload.multipart.aio import MultiPartClient
|
|
10
|
+
from payload.multipart.formdata.httpparts.nonstring.models import FloatRequest
|
|
11
|
+
|
|
12
|
+
JPG = Path(__file__).parent.parent / "data/image.jpg"
|
|
13
|
+
PNG = Path(__file__).parent.parent / "data/image.png"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.fixture
|
|
17
|
+
async def client():
|
|
18
|
+
async with MultiPartClient(endpoint="http://localhost:3000") as client:
|
|
19
|
+
yield client
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.mark.asyncio
|
|
23
|
+
async def test_anonymous_model(client: MultiPartClient):
|
|
24
|
+
await client.form_data.anonymous_model({"profileImage": open(str(JPG), "rb")})
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.mark.asyncio
|
|
28
|
+
async def test_basic(client: MultiPartClient):
|
|
29
|
+
await client.form_data.basic(
|
|
30
|
+
models.MultiPartRequest(
|
|
31
|
+
id="123",
|
|
32
|
+
profile_image=open(str(JPG), "rb"),
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.mark.asyncio
|
|
38
|
+
async def test_binary_array_parts(client: MultiPartClient):
|
|
39
|
+
await client.form_data.binary_array_parts(
|
|
40
|
+
models.BinaryArrayPartsRequest(
|
|
41
|
+
id="123",
|
|
42
|
+
pictures=[
|
|
43
|
+
open(str(PNG), "rb"),
|
|
44
|
+
open(str(PNG), "rb"),
|
|
45
|
+
],
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@pytest.mark.asyncio
|
|
51
|
+
async def test_check_file_name_and_content_type(client: MultiPartClient):
|
|
52
|
+
await client.form_data.check_file_name_and_content_type(
|
|
53
|
+
models.MultiPartRequest(
|
|
54
|
+
id="123",
|
|
55
|
+
profile_image=("hello.jpg", open(str(JPG), "rb"), "image/jpg"),
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@pytest.mark.asyncio
|
|
61
|
+
async def test_complex(client: MultiPartClient):
|
|
62
|
+
await client.form_data.file_array_and_basic(
|
|
63
|
+
models.ComplexPartsRequest(
|
|
64
|
+
id="123",
|
|
65
|
+
address=models.Address(city="X"),
|
|
66
|
+
pictures=[
|
|
67
|
+
open(str(PNG), "rb"),
|
|
68
|
+
open(str(PNG), "rb"),
|
|
69
|
+
],
|
|
70
|
+
profile_image=open(str(JPG), "rb"),
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@pytest.mark.asyncio
|
|
76
|
+
async def test_json_part(client: MultiPartClient):
|
|
77
|
+
await client.form_data.json_part(
|
|
78
|
+
models.JsonPartRequest(
|
|
79
|
+
address=models.Address(city="X"),
|
|
80
|
+
profile_image=open(str(JPG), "rb"),
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@pytest.mark.asyncio
|
|
86
|
+
async def test_multi_binary_parts(client: MultiPartClient):
|
|
87
|
+
await client.form_data.multi_binary_parts(
|
|
88
|
+
models.MultiBinaryPartsRequest(
|
|
89
|
+
profile_image=open(str(JPG), "rb"),
|
|
90
|
+
picture=open(str(PNG), "rb"),
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
await client.form_data.multi_binary_parts(
|
|
94
|
+
models.MultiBinaryPartsRequest(
|
|
95
|
+
profile_image=open(str(JPG), "rb"),
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@pytest.mark.asyncio
|
|
101
|
+
async def test_file_with_http_part_specific_content_type(client: MultiPartClient):
|
|
102
|
+
await client.form_data.http_parts.content_type.image_jpeg_content_type(
|
|
103
|
+
models.FileWithHttpPartSpecificContentTypeRequest(
|
|
104
|
+
profile_image=("hello.jpg", open(str(JPG), "rb"), "image/jpg"),
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@pytest.mark.asyncio
|
|
110
|
+
async def test_file_with_http_part_required_content_type(client: MultiPartClient):
|
|
111
|
+
await client.form_data.http_parts.content_type.required_content_type(
|
|
112
|
+
models.FileWithHttpPartRequiredContentTypeRequest(
|
|
113
|
+
profile_image=open(str(JPG), "rb"),
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@pytest.mark.asyncio
|
|
119
|
+
async def test_file_with_http_part_optional_content_type(client: MultiPartClient):
|
|
120
|
+
# call twice: one with content type, one without
|
|
121
|
+
await client.form_data.http_parts.content_type.optional_content_type(
|
|
122
|
+
models.FileWithHttpPartOptionalContentTypeRequest(
|
|
123
|
+
profile_image=("hello.jpg", open(str(JPG), "rb").read()),
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
await client.form_data.http_parts.content_type.optional_content_type(
|
|
127
|
+
models.FileWithHttpPartOptionalContentTypeRequest(
|
|
128
|
+
profile_image=("hello.jpg", open(str(JPG), "rb").read(), "application/octet-stream"),
|
|
129
|
+
)
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@pytest.mark.asyncio
|
|
134
|
+
async def test_complex_with_http_part(client: MultiPartClient):
|
|
135
|
+
await client.form_data.http_parts.json_array_and_file_array(
|
|
136
|
+
models.ComplexHttpPartsModelRequest(
|
|
137
|
+
id="123",
|
|
138
|
+
previous_addresses=[
|
|
139
|
+
models.Address(city="Y"),
|
|
140
|
+
models.Address(city="Z"),
|
|
141
|
+
],
|
|
142
|
+
address=models.Address(city="X"),
|
|
143
|
+
pictures=[
|
|
144
|
+
open(str(PNG), "rb"),
|
|
145
|
+
open(str(PNG), "rb"),
|
|
146
|
+
],
|
|
147
|
+
profile_image=open(str(JPG), "rb"),
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@pytest.mark.asyncio
|
|
153
|
+
async def test_http_parts_non_string_float(client: MultiPartClient):
|
|
154
|
+
await client.form_data.http_parts.non_string.float(FloatRequest(temperature=0.5))
|
|
@@ -0,0 +1,24 @@
|
|
|
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 serialization.encodedname.json.aio import JsonClient
|
|
8
|
+
from serialization.encodedname.json.property import models
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture
|
|
12
|
+
async def client():
|
|
13
|
+
async with JsonClient() as client:
|
|
14
|
+
yield client
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.mark.asyncio
|
|
18
|
+
async def test_property_send(client: JsonClient):
|
|
19
|
+
await client.property.send(models.JsonEncodedNameModel(default_name=True))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.mark.asyncio
|
|
23
|
+
async def test_property_get(client: JsonClient):
|
|
24
|
+
assert (await client.property.get()).default_name
|
|
@@ -0,0 +1,43 @@
|
|
|
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 specialwords.aio import SpecialWordsClient
|
|
8
|
+
from specialwords.models import models
|
|
9
|
+
from specialwords.modelproperties import models as model_properties_models
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.fixture
|
|
13
|
+
async def client():
|
|
14
|
+
async with SpecialWordsClient() as client:
|
|
15
|
+
yield client
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.mark.asyncio
|
|
19
|
+
async def test_operations(client: SpecialWordsClient, special_words):
|
|
20
|
+
for sw in special_words:
|
|
21
|
+
suffix = "" if sw == "constructor" else "_method"
|
|
22
|
+
await getattr(client.operations, sw + suffix)()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.mark.asyncio
|
|
26
|
+
async def test_parameter(client: SpecialWordsClient, special_words):
|
|
27
|
+
for sw in special_words:
|
|
28
|
+
suffix = "" if sw == "constructor" else "_parameter"
|
|
29
|
+
await getattr(client.parameters, "with_" + sw)(**{sw + suffix: "ok"})
|
|
30
|
+
await client.parameters.with_cancellation_token(cancellation_token="ok")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.asyncio
|
|
34
|
+
async def test_model(client: SpecialWordsClient, special_words):
|
|
35
|
+
for sw in special_words:
|
|
36
|
+
suffix = "" if sw == "constructor" else "Model"
|
|
37
|
+
model = getattr(models, sw.capitalize() + suffix)
|
|
38
|
+
await getattr(client.models, "with_" + sw)(model(name="ok"))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.mark.asyncio
|
|
42
|
+
async def test_model_properties(client: SpecialWordsClient):
|
|
43
|
+
await client.model_properties.same_as_model(model_properties_models.SameAsModel(same_as_model="ok"))
|