Skip to content

[Daxia] [ FastAPI ] Add FastAPITestClient auth helpers#7233

Closed
daxia778 wants to merge 1 commit into
UnsafeLabs:mainfrom
daxia778:daxia/fastapi-testclient-804
Closed

[Daxia] [ FastAPI ] Add FastAPITestClient auth helpers#7233
daxia778 wants to merge 1 commit into
UnsafeLabs:mainfrom
daxia778:daxia/fastapi-testclient-804

Conversation

@daxia778

Copy link
Copy Markdown

/claim #804

Summary

  • Add an opt-in FastAPITestClient subclass while keeping TestClient as the unchanged Starlette export.
  • Add bearer and basic authentication helpers plus reset_auth() for clearing auth state.
  • Add ws_connect() for WebSocket tests with custom headers and subprotocols.
  • Add assert_status() to issue a request and raise a helpful assertion message when the status differs.

Demo

https://github.com/daxia778/Bounty-Hunters/releases/download/issue-804-demo-d87bb4f9/fastapi-testclient-804-demo-d87bb4f9.mp4

Validation

  • UV_PYTHON=<Python 3.12> uv run python -m pytest tests/test_fastapi_testclient.py -q
  • UV_PYTHON=<Python 3.12> uv run ruff check fastapi/testclient.py tests/test_fastapi_testclient.py
  • UV_PYTHON=<Python 3.12> uv run ruff format --check fastapi/testclient.py tests/test_fastapi_testclient.py
  • git diff --check

@github-actions

Copy link
Copy Markdown
Contributor

Unfortunately the changes in this PR didn't fully resolve the issue. Please rework your solution and submit a new pull request.

Make sure to review the acceptance criteria in the linked issue and verify all conditions are met before resubmitting. See CONTRIBUTING.md for guidelines.

@github-actions github-actions Bot closed this Jun 26, 2026
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