Add respx support for mocking httpx requests#2973
Conversation
Implement MockVWSForHttpx context manager using respx to intercept httpx requests to Vuforia APIs. Reuses existing handler logic by converting httpx.Request to requests.PreparedRequest. Includes 13 tests covering real_http parameter, response delays, custom URLs, and database management. Adds httpx and respx as core dependencies. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add noqa comment to suppress C416 ruff error while keeping dict comprehension to satisfy pyrefly type checking requirements. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Convert httpx.Request directly to RequestData, removing the PreparedRequest intermediate. This eliminates the requests library dependency from the respx module and removes all type suppression comments (type: ignore, noqa). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b74aa80 to
4db463e
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| path=request.url.raw_path.decode(encoding="ascii"), | ||
| headers=request.headers, | ||
| body=request.content, | ||
| ) |
There was a problem hiding this comment.
Lowercase httpx headers break case-sensitive dict lookups
High Severity
_to_request_data passes request.headers (an httpx.Headers object) directly as RequestData.headers. httpx normalizes all header keys to lowercase internally. Multiple downstream handler functions convert these headers to a regular dict via dict(request_headers) and then perform case-sensitive lookups like .get("Content-Type", ""), .get("Authorization"), .get("Date", ""), and .get("Content-Length", ...). Since dict(httpx.Headers(...)) produces lowercase keys (e.g., "content-type"), these lookups always return the default value instead of the actual header. This breaks database matching, authentication validation, and other header checks, making the mock non-functional for properly authenticated requests.
Document the new httpx/respx mock backend in README, index, getting-started, mock-api-reference, and a new httpx-example.rst file. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>


Summary
Add support for mocking httpx requests using the respx library, providing a parallel implementation to the existing MockVWS (which uses the responses library for mocking requests library calls).
MockVWSForHttpxcontext manager class with full feature parity toMockVWShttpx.Requestdirectly toRequestData, with noPreparedRequestintermediateImplementation Details
New Files
src/mock_vws/_respx_mock_server/__init__.py- Package initializationsrc/mock_vws/_respx_mock_server/decorators.py- MainMockVWSForHttpxclass and request conversion utilitiestests/mock_vws/test_respx_mock_usage.py- Comprehensive test suite (13 tests)Changes to Existing Files
src/mock_vws/__init__.py- Export newMockVWSForHttpxclasspyproject.toml- Add httpx and respx dependenciesspelling_private_dict.txt- Add new library names to spelling dictionaryTest Plan
🤖 Generated with Claude Code
Note
Medium Risk
Additive but introduces new runtime dependencies and a new request-interception path (
respx/httpx) where routing/timeout behavior could differ from the existingrequestsmock.Overview
Adds first-class support for mocking Vuforia API calls made with
httpxby introducingMockVWSForHttpx(built onrespx) alongside the existingrequests/responses-basedMockVWS.The new context manager wires existing VWS/VWQ route handlers into
respx, supports configurable base URLs, optional passthrough (real_http), and deterministic response delays (including timeout simulation). Documentation and API reference are updated withhttpxexamples, and a new test suite validates key behaviors;httpx/respxare added as project dependencies.Written by Cursor Bugbot for commit 503c2d5. This will update automatically on new commits. Configure here.