Skip to content

Add respx support for mocking httpx requests#2973

Merged
adamtheturtle merged 7 commits intomainfrom
adamtheturtle/add-respx-support
Feb 22, 2026
Merged

Add respx support for mocking httpx requests#2973
adamtheturtle merged 7 commits intomainfrom
adamtheturtle/add-respx-support

Conversation

@adamtheturtle
Copy link
Member

@adamtheturtle adamtheturtle commented Feb 21, 2026

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).

  • Implement MockVWSForHttpx context manager class with full feature parity to MockVWS
  • Convert httpx.Request directly to RequestData, with no PreparedRequest intermediate
  • Add comprehensive test suite with 13 tests covering all major functionality
  • Support all existing configuration options (custom base URLs, response delays, image matchers, etc.)

Implementation Details

New Files

  • src/mock_vws/_respx_mock_server/__init__.py - Package initialization
  • src/mock_vws/_respx_mock_server/decorators.py - Main MockVWSForHttpx class and request conversion utilities
  • tests/mock_vws/test_respx_mock_usage.py - Comprehensive test suite (13 tests)

Changes to Existing Files

  • src/mock_vws/__init__.py - Export new MockVWSForHttpx class
  • pyproject.toml - Add httpx and respx dependencies
  • spelling_private_dict.txt - Add new library names to spelling dictionary

Test Plan

  • All 13 tests pass
  • TestRealHTTP: Verify mocking blocks non-VWS requests, real_http flag allows passthrough
  • TestResponseDelay: Verify response delays and timeout handling
  • TestCustomBaseURLs: Verify custom base URL configuration
  • TestAddDatabase: Verify cloud and VuMark database addition
  • TestVWSEndpoints: Verify VWS endpoint functionality

🤖 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 existing requests mock.

Overview
Adds first-class support for mocking Vuforia API calls made with httpx by introducing MockVWSForHttpx (built on respx) alongside the existing requests/responses-based MockVWS.

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 with httpx examples, and a new test suite validates key behaviors; httpx/respx are added as project dependencies.

Written by Cursor Bugbot for commit 503c2d5. This will update automatically on new commits. Configure here.

adamtheturtle and others added 5 commits February 21, 2026 08:56
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>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

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,
)
Copy link

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

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>
@adamtheturtle adamtheturtle merged commit 2d1cfa6 into main Feb 22, 2026
12 checks passed
@adamtheturtle adamtheturtle deleted the adamtheturtle/add-respx-support branch February 22, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant