Skip to content

Integration test: API facts endpoints (FastAPI TestClient + Redis)#2411

Open
berendt wants to merge 2 commits into
mainfrom
implement/issue-2406-api-facts-integration-test
Open

Integration test: API facts endpoints (FastAPI TestClient + Redis)#2411
berendt wants to merge 2 commits into
mainfrom
implement/issue-2406-api-facts-integration-test

Conversation

@berendt

@berendt berendt commented Jun 19, 2026

Copy link
Copy Markdown
Member

What

Integration coverage for the read-only inventory-facts HTTP endpoints, which
read straight from Redis:

  • GET /v1/inventory/hosts/{host}/facts (osism/api.py:927)
  • GET /v1/inventory/hosts/{host}/facts/{fact} (osism/api.py:966)

Both call utils.redis.get("ansible_facts{host}"). Driving them through
fastapi.testclient.TestClient against the live Redis exercises the API↔Redis
read path end-to-end. The suite is skipped automatically when Redis is not
reachable, like the other modules under tests/integration/.

Part of #2400. Follow-up to #2368.

Changes (in commit order)

  1. Add httpx to dev dependencies for FastAPI TestClientfastapi.testclient.TestClient
    needs httpx as its transport. Adds httpx = "==0.28.1" to [dev-packages]
    and regenerates Pipfile.lock so pipenv install --dev --deploy keeps
    verifying the lock in CI. The lock diff adds only httpx and its transitives
    (httpcore, h11, anyio, sniffio, idna, certifi, typing-extensions)
    to develop; no runtime pins move.

  2. Add integration tests for inventory facts API endpoints — new module
    tests/integration/test_api_facts.py. Each test seeds the exact
    ansible_facts<host> key (UUID-based host) and deletes it in teardown.
    Covers every Scope item from the issue:

    • parsed facts returned with the correct count and from_cache flag;
    • a single fact value;
    • unknown fact → 404;
    • unknown host → 404 (both endpoints);
    • malformed JSON in Redis → 500.

Notes

  • Importing osism.api wires the event bridge to Redis at import time, so the
    import is deferred into the client fixture — fine in the integration env
    where Redis is up (and the suite is skipped without it).
  • The README "Running integration tests" overview sentence is shared by all
    Meta: Extend Celery/Redis integration tests (Tier 1 + Tier 2) #2400 siblings; it is intentionally left untouched here to avoid per-issue
    merge churn. The existing warning block already covers the per-run UUID keys.

Test plan

  • CI runs tests/integration with a live Redis (playbooks/test-integration.yml,
    OSISM_REQUIRE_REDIS=1). Per repo convention the tests run in CI, not locally.
  • Verified locally: pipenv verify (lock in sync) and flake8 on the new file.

Closes #2406


Implemented by planwerk-review f1c04d7 with Claude:claude-opus-4-8

berendt added 2 commits June 19, 2026 20:03
The integration tests drive the FastAPI app through
fastapi.testclient.TestClient, which requires httpx as its transport.
Add it to [dev-packages] and re-lock so that pipenv install --dev
--deploy keeps verifying the lock in CI.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Christian Berendt <berendt@osism.tech>
Drive the read-only GET /v1/inventory/hosts/{host}/facts and
.../facts/{fact} endpoints through fastapi.testclient.TestClient
against the live Redis. The endpoints read the ansible_facts<host>
cache key directly, so each test seeds that exact key and removes it
in teardown.

Coverage: parsed facts with the correct count, a single fact value,
404 for an unknown fact, 404 for an unknown host on both endpoints,
and 500 for malformed JSON in the cache.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Christian Berendt <berendt@osism.tech>

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@berendt berendt requested a review from ideaship June 19, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

Integration test: API facts endpoints (FastAPI TestClient + Redis)

2 participants