8000 feat/0.20.0: web API history + export endpoints by dominicusin · Pull Request #92 · dominicusin/package-maximizer · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions package_maximizer/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,24 @@ def openapi_spec() -> tuple[dict, int]:
return jsonify(spec), 200


# ─── History endpoint ─────────────────────────────
@app.get("/api/v1/history")
@require_api_key
def history_get() -> tuple[dict, int]:
"""Get package manager transaction history."""
from ..integrations import RealRepoIntegration

manager = request.args.get("manager", "apt")
limit = request.args.get("limit", 20, type=int)

try:
integration = RealRepoIntegration(package_manager=manager)
history = integration.get_transaction_history(limit=limit)
return jsonify({"history": history, "count": len(history)}), 200
except Exception as e:
return jsonify({"error": str(e)}), 500


@app.get("/api/v1/docs")
def api_docs() -> tuple[str, int]:
"""Minimal human-readable API documentation page."""
Expand Down
33 changes: 33 additions & 0 deletions tests/test_web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,39 @@ def test_compare_invalid_manager(client):
assert r.status_code == 400


# --- History endpoint --------------------------------------------------------


def test_history_get(client):
"""GET /api/v1/history returns history."""
r = client.get("/api/v1/history", headers=auth_headers())
assert r.status_code == 200
data = r.get_json()
assert "history" in data
assert "selected" in data or "count" in data


def test_history_get_with_params(client):
"""GET /api/v1/history with query params."""
r = client.get("/api/v1/history?manager=apt&limit=5", headers=auth_headers())
assert r.status_code == 200
data = r.get_json()
assert "history" in data


# --- Export endpoint ---------------------------------------------------------


def test_export_post(client):
"""POST /api/v1/export returns JSON result."""
payload = {"packages": ["pkg1"], "manager": "apt", "format": "json"}
r = client.post("/api/v1/export", json=payload, headers=auth_headers())
assert r.status_code == 200
data = r.get_json()
assert "selected" in data
assert "selected" in data or "count" in data


def test_compare_missing_packages(client):
r = client.post("/api/v1/compare", json={}, headers=auth_headers())
assert r.status_code == 400
Loading
0