Skip to content

Commit 8a53c37

Browse files
authored
[python] Fix nightly build (#9604)
PR summary: - Fix nightly build nightly build failure is caused by spector case about Http.File: #9513. Before complete design for Http.File, we skip those test cases for now - Add some test cases
1 parent 0cf4490 commit 8a53c37

File tree

14 files changed

+266
-20
lines changed

14 files changed

+266
-20
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
Add test case

packages/http-client-python/eng/scripts/ci/regenerate.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const argv = parseArgs({
2222
});
2323

2424
// Add this near the top with other constants
25-
const SKIP_SPECS: string[] = [];
25+
const SKIP_SPECS: string[] = ["type/file"];
2626

2727
// Get the directory of the current file
2828
const PLUGIN_DIR = argv.values.pluginDir
@@ -49,8 +49,14 @@ const AZURE_EMITTER_OPTIONS: Record<string, Record<string, string> | Record<stri
4949
"azure/client-generator-core/api-version": {
5050
namespace: "specs.azure.clientgenerator.core.apiversion",
5151
},
52-
"azure/client-generator-core/client-initialization": {
53-
namespace: "specs.azure.clientgenerator.core.clientinitialization",
52+
"azure/client-generator-core/client-initialization/default": {
53+
namespace: "specs.azure.clientgenerator.core.clientinitialization.default",
54+
},
55+
"azure/client-generator-core/client-initialization/individually": {
56+
namespace: "specs.azure.clientgenerator.core.clientinitialization.individually",
57+
},
58+
"azure/client-generator-core/client-initialization/individuallyParent": {
59+
namespace: "specs.azure.clientgenerator.core.clientinitialization.individuallyparent",
5460
},
5561
"azure/client-generator-core/client-location": {
5662
namespace: "specs.azure.clientgenerator.core.clientlocation",
@@ -279,6 +285,10 @@ const EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, st
279285
"package-name": "typetest-discriminatedunion",
280286
namespace: "typetest.discriminatedunion",
281287
},
288+
"type/file": {
289+
"package-name": "typetest-file",
290+
namespace: "typetest.file",
291+
},
282292
documentation: {
283293
"package-name": "specs-documentation",
284294
namespace: "specs.documentation",

packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_initialization_async.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
# license information.
55
# --------------------------------------------------------------------------
66
import pytest
7-
from specs.azure.clientgenerator.core.clientinitialization.aio import (
7+
from specs.azure.clientgenerator.core.clientinitialization.default.aio import (
88
HeaderParamClient,
99
MultipleParamsClient,
1010
MixedParamsClient,
1111
PathParamClient,
1212
ParamAliasClient,
13-
ParentClient,
1413
)
15-
from specs.azure.clientgenerator.core.clientinitialization.models import Input
14+
from specs.azure.clientgenerator.core.clientinitialization.default.models import Input
1615

1716

1817
@pytest.mark.asyncio

packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,33 @@ async def test_optional_parts(client: MultiPartClient):
184184
profile_image=open(str(JPG), "rb"),
185185
)
186186
)
187+
188+
189+
@pytest.mark.asyncio
190+
async def test_file_upload_file_specific_content_type(client: MultiPartClient):
191+
await client.form_data.file.upload_file_specific_content_type(
192+
models.UploadFileSpecificContentTypeRequest(
193+
file=("image.png", open(str(PNG), "rb"), "image/png"),
194+
)
195+
)
196+
197+
198+
@pytest.mark.asyncio
199+
async def test_file_upload_file_required_filename(client: MultiPartClient):
200+
await client.form_data.file.upload_file_required_filename(
201+
models.UploadFileRequiredFilenameRequest(
202+
file=("image.png", open(str(PNG), "rb"), "image/png"),
203+
)
204+
)
205+
206+
207+
@pytest.mark.asyncio
208+
async def test_file_upload_file_array(client: MultiPartClient):
209+
await client.form_data.file.upload_file_array(
210+
models.UploadFileArrayRequest(
211+
files=[
212+
("image.png", open(str(PNG), "rb"), "image/png"),
213+
("image.png", open(str(PNG), "rb"), "image/png"),
214+
],
215+
)
216+
)

packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_initialization.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
from specs.azure.clientgenerator.core.clientinitialization import (
6+
from specs.azure.clientgenerator.core.clientinitialization.default import (
77
HeaderParamClient,
88
MultipleParamsClient,
99
MixedParamsClient,
1010
PathParamClient,
1111
ParamAliasClient,
12-
ParentClient,
1312
)
14-
from specs.azure.clientgenerator.core.clientinitialization.models import Input
13+
from specs.azure.clientgenerator.core.clientinitialization.default.models import Input
1514

1615

1716
def test_header_param_client():

packages/http-client-python/generator/test/azure/mock_api_tests/test_payload_multipart.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,30 @@ def test_optional_parts(client: MultiPartClient):
169169
profile_image=open(str(JPG), "rb"),
170170
)
171171
)
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+
)

packages/http-client-python/generator/test/azure/requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ azure-mgmt-core==1.6.0
77
-e ./generated/azure-client-generator-core-api-version-header
88
-e ./generated/azure-client-generator-core-api-version-path
99
-e ./generated/azure-client-generator-core-api-version-query
10-
-e ./generated/azure-client-generator-core-client-initialization
10+
-e ./generated/azure-client-generator-core-client-initialization-default
11+
-e ./generated/azure-client-generator-core-client-initialization-individually
12+
-e ./generated/azure-client-generator-core-client-initialization-individuallyparent
1113
-e ./generated/azure-client-generator-core-deserialize-empty-string-as-null
1214
-e ./generated/azure-client-generator-core-flatten-property
1315
-e ./generated/azure-client-generator-core-hierarchy-building
@@ -82,6 +84,7 @@ azure-mgmt-core==1.6.0
8284
-e ./generated/typetest-dictionary
8385
-e ./generated/typetest-enum-extensible
8486
-e ./generated/typetest-enum-fixed
87+
# -e ./generated/typetest-file
8588
-e ./generated/typetest-model-enumdiscriminator
8689
-e ./generated/typetest-model-nesteddiscriminator
8790
-e ./generated/typetest-model-notdiscriminated
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_payload_multipart_async.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from payload.multipart import models
99
from payload.multipart.aio import MultiPartClient
1010
from payload.multipart.formdata.httpparts.nonstring.models import FloatRequest
11+
from payload.multipart.formdata.file import models as file_models
1112

1213
JPG = Path(__file__).parent.parent / "data/image.jpg"
1314
PNG = Path(__file__).parent.parent / "data/image.png"
@@ -185,3 +186,33 @@ async def test_optional_parts(client: MultiPartClient):
185186
profile_image=open(str(JPG), "rb"),
186187
)
187188
)
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+
)

0 commit comments

Comments
 (0)