Skip to content

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

Description

@berendt

Part of #2400. Follow-up to #2368. Requires the shared httpx prerequisite (see the meta issue).

What

Cover the 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 path end-to-end.

Scope

  • Seed ansible_facts<host> in Redis → GET .../facts returns 200 with the parsed facts and correct count.
  • Single fact: GET .../facts/{fact} returns the value; unknown fact → 404.
  • Unknown host (no key) → 404.
  • Malformed JSON in Redis → 500.

Notes / Where

New file tests/integration/test_api_facts.py. Importing osism.api wires the event bridge to Redis at import time — fine in the integration env where Redis is up (and the suite is skipped without it). Add httpx to [dev-packages] in Pipfile (TestClient needs it). Clean up seeded keys per test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions