Skip to content

Exercise FastAPI endpoints through TestClient and mock FreshRSS transport - #22

Closed
Skulldorom wants to merge 1 commit into
mainfrom
codex/add-testclient-fixture-for-health-checks
Closed

Exercise FastAPI endpoints through TestClient and mock FreshRSS transport#22
Skulldorom wants to merge 1 commit into
mainfrom
codex/add-testclient-fixture-for-health-checks

Conversation

@Skulldorom

Copy link
Copy Markdown
Owner

Motivation

  • Provide HTTP-level tests for the API so endpoints are validated through a TestClient instead of only calling functions directly.
  • Keep the FreshRSS transport boundary mocked while preserving focused unit tests for token parsing to make failures easier to diagnose.
  • Ensure category labels are safely encoded when placed into the upstream FreshRSS stream path.

Description

  • Add a reusable main_module fixture that imports the application under deterministic FRESHRSS_* environment variables and a test_client fixture that yields a TestClient for HTTP requests (tests/test_main.py).
  • Introduce install_freshrss_transport to stub only requests.post and requests.get, leaving the HTTP surface untouched and capturing outbound calls for assertions (tests/test_main.py).
  • Add HTTP-level tests for /health and /freshrss/unread covering default and explicit n and category parameters, invalid n values (validation), encoded category values, authentication caching (login once), upstream 502 serialization, and response JSON shape (tests/test_main.py).
  • Retain focused unit tests that exercise get_greader_token failure cases (failed login and missing Auth= line) while mocking only the transport (tests/test_main.py).
  • Percent-encode FreshRSS category labels before embedding them in the upstream stream path by importing and using quote from urllib.parse in main.py.

Testing

  • Ran python -m py_compile main.py tests/test_main.py which succeeded.
  • Ran git diff --check which found no issues during the change validation step.
  • Attempted uv run pytest -q but test collection could not start because starlette.testclient requires the optional httpx2 package and the environment could not fetch packages from PyPI, so pytest could not be executed here.
  • Attempted to add httpx2 to dev dependencies with the runtime tooling, but package installation failed due to lack of network access, so full test execution was not possible in this environment.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db527ea78a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/test_main.py
from fastapi import HTTPException
import requests
from fastapi import HTTPException
from fastapi.testclient import TestClient

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add TestClient's required transport dependency

With the dependencies installed by .github/workflows/docker.yml via uv sync --frozen, this import fails during test collection because Starlette's TestClient requires the httpx2 package, while the locked dev dependencies include only pytest. I reproduced the resulting RuntimeError with .venv/bin/pytest -q; therefore every CI test run fails before executing a test, and the dependent Docker publishing job is blocked. Add the required TestClient dependency to pyproject.toml and regenerate uv.lock.

Useful? React with 👍 / 👎.

@Skulldorom

Copy link
Copy Markdown
Owner Author

Superseded by #25 — all four PRs merged with conflict resolution and review fixes applied.

@Skulldorom Skulldorom closed this Jul 20, 2026
@Skulldorom
Skulldorom deleted the codex/add-testclient-fixture-for-health-checks branch July 20, 2026 10:01
Skulldorom added a commit that referenced this pull request Jul 20, 2026
merge: consolidate PRs #20, #21, #22, #23 with review fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant