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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/python-nightly-fix-2026-1-9-5-47-21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/http-client-python"
---

Add test case
16 changes: 13 additions & 3 deletions packages/http-client-python/eng/scripts/ci/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const argv = parseArgs({
});

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

// Get the directory of the current file
const PLUGIN_DIR = argv.values.pluginDir
Expand All @@ -49,8 +49,14 @@ const AZURE_EMITTER_OPTIONS: Record<string, Record<string, string> | Record<stri
"azure/client-generator-core/api-version": {
namespace: "specs.azure.clientgenerator.core.apiversion",
},
"azure/client-generator-core/client-initialization": {
namespace: "specs.azure.clientgenerator.core.clientinitialization",
"azure/client-generator-core/client-initialization/default": {
namespace: "specs.azure.clientgenerator.core.clientinitialization.default",
},
"azure/client-generator-core/client-initialization/individually": {
namespace: "specs.azure.clientgenerator.core.clientinitialization.individually",
},
"azure/client-generator-core/client-initialization/individuallyParent": {
namespace: "specs.azure.clientgenerator.core.clientinitialization.individuallyparent",
},
"azure/client-generator-core/client-location": {
namespace: "specs.azure.clientgenerator.core.clientlocation",
Expand Down Expand Up @@ -279,6 +285,10 @@ const EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, st
"package-name": "typetest-discriminatedunion",
namespace: "typetest.discriminatedunion",
},
"type/file": {
"package-name": "typetest-file",
namespace: "typetest.file",
},
documentation: {
"package-name": "specs-documentation",
namespace: "specs.documentation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
# license information.
# --------------------------------------------------------------------------
import pytest
from specs.azure.clientgenerator.core.clientinitialization.aio import (
from specs.azure.clientgenerator.core.clientinitialization.default.aio import (
HeaderParamClient,
MultipleParamsClient,
MixedParamsClient,
PathParamClient,
ParamAliasClient,
ParentClient,
)
from specs.azure.clientgenerator.core.clientinitialization.models import Input
from specs.azure.clientgenerator.core.clientinitialization.default.models import Input


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,33 @@ async def test_optional_parts(client: MultiPartClient):
profile_image=open(str(JPG), "rb"),
)
)


@pytest.mark.asyncio
async def test_file_upload_file_specific_content_type(client: MultiPartClient):
await client.form_data.file.upload_file_specific_content_type(
models.UploadFileSpecificContentTypeRequest(
file=("image.png", open(str(PNG), "rb"), "image/png"),
)
)


@pytest.mark.asyncio
async def test_file_upload_file_required_filename(client: MultiPartClient):
await client.form_data.file.upload_file_required_filename(
models.UploadFileRequiredFilenameRequest(
file=("image.png", open(str(PNG), "rb"), "image/png"),
)
)


@pytest.mark.asyncio
async def test_file_upload_file_array(client: MultiPartClient):
await client.form_data.file.upload_file_array(
models.UploadFileArrayRequest(
files=[
("image.png", open(str(PNG), "rb"), "image/png"),
("image.png", open(str(PNG), "rb"), "image/png"),
],
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from specs.azure.clientgenerator.core.clientinitialization import (
from specs.azure.clientgenerator.core.clientinitialization.default import (
HeaderParamClient,
MultipleParamsClient,
MixedParamsClient,
PathParamClient,
ParamAliasClient,
ParentClient,
)
from specs.azure.clientgenerator.core.clientinitialization.models import Input
from specs.azure.clientgenerator.core.clientinitialization.default.models import Input


def test_header_param_client():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,30 @@ def test_optional_parts(client: MultiPartClient):
profile_image=open(str(JPG), "rb"),
)
)


def test_file_upload_file_specific_content_type(client: MultiPartClient):
client.form_data.file.upload_file_specific_content_type(
models.UploadFileSpecificContentTypeRequest(
file=("image.png", open(str(PNG), "rb"), "image/png"),
)
)


def test_file_upload_file_required_filename(client: MultiPartClient):
client.form_data.file.upload_file_required_filename(
models.UploadFileRequiredFilenameRequest(
file=("image.png", open(str(PNG), "rb"), "image/png"),
)
)


def test_file_upload_file_array(client: MultiPartClient):
client.form_data.file.upload_file_array(
models.UploadFileArrayRequest(
files=[
("image.png", open(str(PNG), "rb"), "image/png"),
("image.png", open(str(PNG), "rb"), "image/png"),
],
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ azure-mgmt-core==1.6.0
-e ./generated/azure-client-generator-core-api-version-header
-e ./generated/azure-client-generator-core-api-version-path
-e ./generated/azure-client-generator-core-api-version-query
-e ./generated/azure-client-generator-core-client-initialization
-e ./generated/azure-client-generator-core-client-initialization-default
-e ./generated/azure-client-generator-core-client-initialization-individually
-e ./generated/azure-client-generator-core-client-initialization-individuallyparent
-e ./generated/azure-client-generator-core-deserialize-empty-string-as-null
-e ./generated/azure-client-generator-core-flatten-property
-e ./generated/azure-client-generator-core-hierarchy-building
Expand Down Expand Up @@ -82,6 +84,7 @@ azure-mgmt-core==1.6.0
-e ./generated/typetest-dictionary
-e ./generated/typetest-enum-extensible
-e ./generated/typetest-enum-fixed
# -e ./generated/typetest-file
-e ./generated/typetest-model-enumdiscriminator
-e ./generated/typetest-model-nesteddiscriminator
-e ./generated/typetest-model-notdiscriminated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# after we support Http.File case, enable these tests again


# import json

# import pytest
# from typetest.file.aio import FileClient


# @pytest.fixture
# async def client():
# async with FileClient(endpoint="http://localhost:3000") as client:
# yield client


# @pytest.mark.asyncio
# async def test_upload_file_specific_content_type(client: FileClient, png_data: bytes):
# await client.body.upload_file_specific_content_type(png_data)


# # Do not support this case for now
# # @pytest.mark.asyncio
# # async def test_upload_file_json_content_type(client: FileClient):
# # await client.body.upload_file_json_content_type(json.dumps({"message": "test file content"}).encode())


# # although result is expected but actually there is deserialization issue
# # @pytest.mark.asyncio
# # async def test_download_file_json_content_type(client: FileClient):
# # result = await client.body.download_file_json_content_type()
# # assert result == {"message": "test file content"}


# @pytest.mark.asyncio
# async def test_download_file_specific_content_type(client: FileClient, png_data: bytes):
# result = b"".join([d async for d in (await client.body.download_file_specific_content_type())])
# assert result == png_data


# @pytest.mark.asyncio
# async def test_download_file_multiple_content_types(client: FileClient, png_data: bytes):
# result = b"".join([d async for d in (await client.body.download_file_multiple_content_types())])
# assert result == png_data


# @pytest.mark.asyncio
# async def test_upload_file_default_content_type(client: FileClient, png_data: bytes):
# await client.body.upload_file_default_content_type(png_data, content_type="image/png")


# @pytest.mark.asyncio
# async def test_download_file_default_content_type(client: FileClient, png_data: bytes):
# result = b"".join([d async for d in (await client.body.download_file_default_content_type())])
# assert result == png_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

# after we support Http.File case, enable these tests again

# import json

# import pytest
# from typetest.file import FileClient


# @pytest.fixture
# def client():
# with FileClient(endpoint="http://localhost:3000") as client:
# yield client


# def test_upload_file_specific_content_type(client: FileClient, png_data: bytes):
# client.body.upload_file_specific_content_type(png_data)


# # Do not support this case for now
# # def test_upload_file_json_content_type(client: FileClient):
# # client.body.upload_file_json_content_type(json.dumps({"message": "test file content"}).encode())


# # although result is expected but actually there is deserialization issue
# # def test_download_file_json_content_type(client: FileClient):
# # result = client.body.download_file_json_content_type()
# # assert result == {"message": "test file content"}


# def test_download_file_specific_content_type(client: FileClient, png_data: bytes):
# result = b"".join(client.body.download_file_specific_content_type())
# assert result == png_data


# def test_download_file_multiple_content_types(client: FileClient, png_data: bytes):
# result = b"".join(client.body.download_file_multiple_content_types())
# assert result == png_data


# def test_upload_file_default_content_type(client: FileClient, png_data: bytes):
# client.body.upload_file_default_content_type(png_data, content_type="image/png")


# def test_download_file_default_content_type(client: FileClient, png_data: bytes):
# result = b"".join(client.body.download_file_default_content_type())
# assert result == png_data
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from payload.multipart import models
from payload.multipart.aio import MultiPartClient
from payload.multipart.formdata.httpparts.nonstring.models import FloatRequest
from payload.multipart.formdata.file import models as file_models

JPG = Path(__file__).parent.parent / "data/image.jpg"
PNG = Path(__file__).parent.parent / "data/image.png"
Expand Down Expand Up @@ -185,3 +186,33 @@ async def test_optional_parts(client: MultiPartClient):
profile_image=open(str(JPG), "rb"),
)
)


@pytest.mark.asyncio
async def test_file_upload_file_specific_content_type(client: MultiPartClient):
await client.form_data.file.upload_file_specific_content_type(
file_models.UploadFileSpecificContentTypeRequest(
file=("image.png", open(str(PNG), "rb"), "image/png"),
)
)


@pytest.mark.asyncio
async def test_file_upload_file_required_filename(client: MultiPartClient):
await client.form_data.file.upload_file_required_filename(
file_models.UploadFileRequiredFilenameRequest(
file=("image.png", open(str(PNG), "rb"), "image/png"),
)
)


@pytest.mark.asyncio
async def test_file_upload_file_array(client: MultiPartClient):
await client.form_data.file.upload_file_array(
file_models.UploadFileArrayRequest(
files=[
("image.png", open(str(PNG), "rb"), "image/png"),
("image.png", open(str(PNG), "rb"), "image/png"),
],
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
from payload.multipart import MultiPartClient, models
from payload.multipart.formdata.httpparts.nonstring.models import FloatRequest
from payload.multipart.formdata.file import models as file_models

JPG = Path(__file__).parent / "data/image.jpg"
PNG = Path(__file__).parent / "data/image.png"
Expand Down Expand Up @@ -170,3 +171,30 @@ def test_optional_parts(client: MultiPartClient):
profile_image=open(str(JPG), "rb"),
)
)


def test_file_upload_file_specific_content_type(client: MultiPartClient):
client.form_data.file.upload_file_specific_content_type(
file_models.UploadFileSpecificContentTypeRequest(
file=("image.png", open(str(PNG), "rb"), "image/png"),
)
)


def test_file_upload_file_required_filename(client: MultiPartClient):
client.form_data.file.upload_file_required_filename(
file_models.UploadFileRequiredFilenameRequest(
file=("image.png", open(str(PNG), "rb"), "image/png"),
)
)


def test_file_upload_file_array(client: MultiPartClient):
client.form_data.file.upload_file_array(
file_models.UploadFileArrayRequest(
files=[
("image.png", open(str(PNG), "rb"), "image/png"),
("image.png", open(str(PNG), "rb"), "image/png"),
],
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
-e ./generated/typetest-dictionary
-e ./generated/typetest-enum-extensible
-e ./generated/typetest-enum-fixed
# -e ./generated/typetest-file
-e ./generated/typetest-model-enumdiscriminator
-e ./generated/typetest-model-nesteddiscriminator
-e ./generated/typetest-model-notdiscriminated
Expand Down
Loading
Loading