Skip to content

feat(http-client-python): add mock API tests for payload/head scenario#10420

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/add-test-case-for-pull-10194
Draft

feat(http-client-python): add mock API tests for payload/head scenario#10420
Copilot wants to merge 4 commits into
mainfrom
copilot/add-test-case-for-pull-10194

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Adds Python SDK mock API tests for the payload/head Spector scenario introduced in #10194 — a HEAD operation returning Content-Type and x-ms-meta response headers with no body.

Changes

  • package.json — Bumps @typespec/http-specs to 0.1.0-alpha.37 (stable version containing the payload/head spec)
  • mock_api/shared/test_payload_head.py + asynctests/test_payload_head_async.py — Sync and async tests placed in shared/ since both azure and unbranded flavors expose identical import paths and API surface

The tests cover two scenarios:

def test_content_type_header_in_response(client: HeadClient):
    assert client.content_type_header_in_response() is True

def test_content_type_header_in_response_with_cls(client: HeadClient):
    headers = client.content_type_header_in_response(cls=lambda x, y, z: z)
    assert headers["Content-Type"] == "text/plain; charset=utf-8"
    assert headers["x-ms-meta"] == "hello"

The scenario sends a HEAD request to /payload/head/content-type-header-in-response and expects a 200 response with Content-Type: text/plain; charset=utf-8 and x-ms-meta: hello headers. The cls variant verifies that response headers are correctly deserialized and accessible via the callback.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Apr 17, 2026
Copilot AI changed the title [WIP] Add test case for pull request 10194 feat(http-client-python): add mock API tests for payload/head scenario Apr 17, 2026
Copilot AI requested a review from msyyc April 17, 2026 23:00
@microsoft-github-policy-service microsoft-github-policy-service Bot added the stale Mark a PR that hasn't been recently updated and will be closed. label May 18, 2026
@msyyc
Copy link
Copy Markdown
Contributor

msyyc commented Jun 4, 2026

@copilot resolve the merge conflicts in this pull request

Comment on lines +126 to +128
"payload/head": {
namespace: "payload.head",
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I think the configuration is not needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the payload/head entry from regenerate-common.ts in commit 30d4da5.



def test_content_type_header_in_response(client: HeadClient):
assert client.content_type_header_in_response() is True
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is part of generated python sdk code:


        response_headers = {}
        response_headers["Content-Type"] = self._deserialize("str", response.headers.get("Content-Type"))
        response_headers["x-ms-meta"] = self._deserialize("str", response.headers.get("x-ms-meta"))

        if cls:
            return cls(pipeline_response, None, response_headers)  # type: ignore
        return 200 <= response.status_code <= 299

We could add test case to pass "cls" to check the response header.
@copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_content_type_header_in_response_with_cls (sync + async) in commit 30d4da5 that passes cls=lambda x, y, z: z and asserts both Content-Type and x-ms-meta headers from the response.

# Conflicts:
#	packages/http-client-python/package-lock.json
#	packages/http-client-python/package.json

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 4, 2026

@copilot resolve the merge conflicts in this pull request

Resolved. The conflicts in package.json and package-lock.json have been fixed by taking main's ~0.82.0 versions for @typespec/sse/streams/xml and using the stable @typespec/http-specs@0.1.0-alpha.37 (which already includes the payload/head spec). The branch is now merged with main.

…ce override; add cls header test

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot finished work on behalf of msyyc June 4, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python stale Mark a PR that hasn't been recently updated and will be closed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[python] add test case for https://github.com/microsoft/typespec/pull/10194

2 participants