Integration test: API facts endpoints (FastAPI TestClient + Redis)#2411
Open
berendt wants to merge 2 commits into
Open
Integration test: API facts endpoints (FastAPI TestClient + Redis)#2411berendt wants to merge 2 commits into
berendt wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 throughfastapi.testclient.TestClientagainst the live Redis exercises the API↔Redisread 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)
Add httpx to dev dependencies for FastAPI TestClient —
fastapi.testclient.TestClientneeds
httpxas its transport. Addshttpx = "==0.28.1"to[dev-packages]and regenerates
Pipfile.locksopipenv install --dev --deploykeepsverifying the lock in CI. The lock diff adds only
httpxand its transitives(
httpcore,h11,anyio,sniffio,idna,certifi,typing-extensions)to
develop; no runtime pins move.Add integration tests for inventory facts API endpoints — new module
tests/integration/test_api_facts.py. Each test seeds the exactansible_facts<host>key (UUID-based host) and deletes it in teardown.Covers every Scope item from the issue:
countandfrom_cacheflag;Notes
osism.apiwires the event bridge to Redis at import time, so theimport is deferred into the
clientfixture — fine in the integration envwhere Redis is up (and the suite is skipped without it).
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
tests/integrationwith a live Redis (playbooks/test-integration.yml,OSISM_REQUIRE_REDIS=1). Per repo convention the tests run in CI, not locally.pipenv verify(lock in sync) andflake8on the new file.Closes #2406
Implemented by planwerk-review f1c04d7 with Claude:claude-opus-4-8