@typespec/http-client-python 0.6.3 → 0.6.5

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 (70) hide show
  1. package/emitter/temp/tsconfig.tsbuildinfo +1 -1
  2. package/eng/scripts/ci/regenerate.ts +25 -8
  3. package/eng/scripts/setup/__pycache__/venvtools.cpython-38.pyc +0 -0
  4. package/generator/build/lib/pygen/codegen/models/code_model.py +4 -0
  5. package/generator/build/lib/pygen/codegen/models/combined_type.py +4 -3
  6. package/generator/build/lib/pygen/codegen/models/credential_types.py +4 -0
  7. package/generator/build/lib/pygen/codegen/models/operation.py +8 -2
  8. package/generator/build/lib/pygen/codegen/models/operation_group.py +26 -1
  9. package/generator/build/lib/pygen/codegen/models/paging_operation.py +1 -1
  10. package/generator/build/lib/pygen/codegen/models/property.py +2 -2
  11. package/generator/build/lib/pygen/codegen/serializers/__init__.py +12 -2
  12. package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +5 -1
  13. package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +2 -1
  14. package/generator/build/lib/pygen/codegen/serializers/operation_groups_serializer.py +1 -0
  15. package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +4 -4
  16. package/generator/build/lib/pygen/codegen/templates/operation_groups_container.py.jinja2 +2 -0
  17. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  18. package/generator/pygen/codegen/models/code_model.py +4 -0
  19. package/generator/pygen/codegen/models/combined_type.py +4 -3
  20. package/generator/pygen/codegen/models/credential_types.py +4 -0
  21. package/generator/pygen/codegen/models/operation.py +8 -2
  22. package/generator/pygen/codegen/models/operation_group.py +26 -1
  23. package/generator/pygen/codegen/models/paging_operation.py +1 -1
  24. package/generator/pygen/codegen/models/property.py +2 -2
  25. package/generator/pygen/codegen/serializers/__init__.py +12 -2
  26. package/generator/pygen/codegen/serializers/builder_serializer.py +5 -1
  27. package/generator/pygen/codegen/serializers/model_serializer.py +2 -1
  28. package/generator/pygen/codegen/serializers/operation_groups_serializer.py +1 -0
  29. package/generator/pygen/codegen/templates/operation_group.py.jinja2 +4 -4
  30. package/generator/pygen/codegen/templates/operation_groups_container.py.jinja2 +2 -0
  31. package/generator/test/azure/mock_api_tests/conftest.py +57 -1
  32. package/generator/test/azure/mock_api_tests/data/image.jpg +0 -0
  33. package/generator/test/azure/mock_api_tests/data/image.png +0 -0
  34. package/generator/test/generic_mock_api_tests/conftest.py +0 -43
  35. package/generator/test/unbranded/mock_api_tests/asynctests/test_encode_duration_async.py +63 -0
  36. package/generator/test/unbranded/mock_api_tests/asynctests/test_encode_numeric_async.py +35 -0
  37. package/generator/test/unbranded/mock_api_tests/asynctests/test_parameters_basic_async.py +24 -0
  38. package/generator/test/unbranded/mock_api_tests/asynctests/test_parameters_spread_async.py +76 -0
  39. package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_content_negotiation_async.py +37 -0
  40. package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_multipart_async.py +154 -0
  41. package/generator/test/unbranded/mock_api_tests/asynctests/test_serialization_encoded_name_json_async.py +24 -0
  42. package/generator/test/unbranded/mock_api_tests/asynctests/test_special_words_async.py +43 -0
  43. package/generator/test/unbranded/mock_api_tests/conftest.py +57 -0
  44. package/generator/test/unbranded/mock_api_tests/data/image.jpg +0 -0
  45. package/generator/test/unbranded/mock_api_tests/data/image.png +0 -0
  46. package/generator/test/unbranded/mock_api_tests/test_encode_duration.py +60 -0
  47. package/generator/test/unbranded/mock_api_tests/test_encode_numeric.py +32 -0
  48. package/generator/test/unbranded/mock_api_tests/test_parameters_basic.py +22 -0
  49. package/generator/test/unbranded/mock_api_tests/test_parameters_spread.py +66 -0
  50. package/generator/test/unbranded/mock_api_tests/test_payload_content_negotiation.py +33 -0
  51. package/generator/test/unbranded/mock_api_tests/test_payload_multipart.py +141 -0
  52. package/generator/test/unbranded/mock_api_tests/test_serialization_encoded_name_json.py +22 -0
  53. package/generator/test/unbranded/mock_api_tests/test_special_words.py +39 -0
  54. package/package.json +23 -23
  55. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_encode_duration_async.py +0 -0
  56. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_encode_numeric_async.py +0 -0
  57. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_parameters_basic_async.py +0 -0
  58. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_parameters_spread_async.py +0 -0
  59. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_payload_content_negotiation_async.py +0 -0
  60. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_payload_multipart_async.py +0 -0
  61. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_serialization_encoded_name_json_async.py +0 -0
  62. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_special_words_async.py +0 -0
  63. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_encode_duration.py +0 -0
  64. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_encode_numeric.py +0 -0
  65. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_parameters_basic.py +0 -0
  66. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_parameters_spread.py +0 -0
  67. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_payload_content_negotiation.py +0 -0
  68. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_payload_multipart.py +0 -0
  69. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_serialization_encoded_name_json.py +0 -0
  70. /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_special_words.py +0 -0
@@ -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})
@@ -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"))
@@ -9,6 +9,9 @@ import signal
9
9
  import pytest
10
10
  import re
11
11
  from pathlib import Path
12
+ from typing import List
13
+
14
+ FILE_FOLDER = Path(__file__).parent
12
15
 
13
16
 
14
17
  def start_server_process():
@@ -33,3 +36,57 @@ def testserver():
33
36
  server = start_server_process()
34
37
  yield
35
38
  terminate_server_process(server)
39
+
40
+
41
+ SPECIAL_WORDS = [
42
+ "and",
43
+ "as",
44
+ "assert",
45
+ "async",
46
+ "await",
47
+ "break",
48
+ "class",
49
+ "constructor",
50
+ "continue",
51
+ "def",
52
+ "del",
53
+ "elif",
54
+ "else",
55
+ "except",
56
+ "exec",
57
+ "finally",
58
+ "for",
59
+ "from",
60
+ "global",
61
+ "if",
62
+ "import",
63
+ "in",
64
+ "is",
65
+ "lambda",
66
+ "not",
67
+ "or",
68
+ "pass",
69
+ "raise",
70
+ "return",
71
+ "try",
72
+ "while",
73
+ "with",
74
+ "yield",
75
+ ]
76
+
77
+
78
+ @pytest.fixture
79
+ def special_words() -> List[str]:
80
+ return SPECIAL_WORDS
81
+
82
+
83
+ @pytest.fixture
84
+ def png_data() -> bytes:
85
+ with open(str(FILE_FOLDER / "data/image.png"), "rb") as file_in:
86
+ return file_in.read()
87
+
88
+
89
+ @pytest.fixture
90
+ def jpg_data() -> bytes:
91
+ with open(str(FILE_FOLDER / "data/image.jpg"), "rb") as file_in:
92
+ return file_in.read()
@@ -0,0 +1,60 @@
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 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
+ def client():
21
+ with DurationClient() as client:
22
+ yield client
23
+
24
+
25
+ def test_query(client: DurationClient):
26
+ client.query.default(input=datetime.timedelta(days=40))
27
+ client.query.iso8601(input=datetime.timedelta(days=40))
28
+ client.query.int32_seconds(input=36)
29
+ client.query.int32_seconds_array(input=[36, 47])
30
+ client.query.float_seconds(input=35.625)
31
+ client.query.float64_seconds(input=35.625)
32
+
33
+
34
+ def test_property(client: DurationClient):
35
+ result = client.property.default(DefaultDurationProperty(value=datetime.timedelta(days=40)))
36
+ assert result.value == datetime.timedelta(days=40)
37
+ result = client.property.default(DefaultDurationProperty(value="P40D"))
38
+ assert result.value == datetime.timedelta(days=40)
39
+ result = client.property.iso8601(ISO8601DurationProperty(value=datetime.timedelta(days=40)))
40
+ assert result.value == datetime.timedelta(days=40)
41
+ result = client.property.iso8601(ISO8601DurationProperty(value="P40D"))
42
+ assert result.value == datetime.timedelta(days=40)
43
+ result = client.property.int32_seconds(Int32SecondsDurationProperty(value=36))
44
+ assert result.value == 36
45
+ result = client.property.float_seconds(FloatSecondsDurationProperty(value=35.625))
46
+ assert abs(result.value - 35.625) < 0.0001
47
+ result = client.property.float64_seconds(FloatSecondsDurationProperty(value=35.625))
48
+ assert abs(result.value - 35.625) < 0.0001
49
+ result = client.property.float_seconds_array(FloatSecondsDurationArrayProperty(value=[35.625, 46.75]))
50
+ assert abs(result.value[0] - 35.625) < 0.0001
51
+ assert abs(result.value[1] - 46.75) < 0.0001
52
+
53
+
54
+ def test_header(client: DurationClient):
55
+ client.header.default(duration=datetime.timedelta(days=40))
56
+ client.header.iso8601(duration=datetime.timedelta(days=40))
57
+ client.header.iso8601_array(duration=[datetime.timedelta(days=40), datetime.timedelta(days=50)])
58
+ client.header.int32_seconds(duration=36)
59
+ client.header.float_seconds(duration=35.625)
60
+ client.header.float64_seconds(duration=35.625)
@@ -0,0 +1,32 @@
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 import NumericClient
8
+ from encode.numeric.property import models
9
+
10
+
11
+ @pytest.fixture
12
+ def client():
13
+ with NumericClient() as client:
14
+ yield client
15
+
16
+
17
+ def test_safeint_as_string(client: NumericClient):
18
+ result = client.property.safeint_as_string(models.SafeintAsStringProperty(value=10000000000))
19
+ assert result.value == 10000000000
20
+ assert result["value"] == "10000000000"
21
+
22
+
23
+ def test_uint32_as_string_optional(client: NumericClient):
24
+ result = client.property.uint32_as_string_optional(models.Uint32AsStringProperty(value=1))
25
+ assert result.value == 1
26
+ assert result["value"] == "1"
27
+
28
+
29
+ def test_uint8_as_string_optional(client: NumericClient):
30
+ result = client.property.uint8_as_string(models.Uint32AsStringProperty(value=255))
31
+ assert result.value == 255
32
+ assert result["value"] == "255"
@@ -0,0 +1,22 @@
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 import BasicClient
8
+ from parameters.basic.explicitbody.models import User
9
+
10
+
11
+ @pytest.fixture
12
+ def client():
13
+ with BasicClient() as client:
14
+ yield client
15
+
16
+
17
+ def test_explicit_simple(client: BasicClient):
18
+ client.explicit_body.simple(User(name="foo"))
19
+
20
+
21
+ def test_implicit_simple(client: BasicClient):
22
+ client.implicit_body.simple(name="foo")