#!/usr/bin/env python3 """Test Agent: pipeline test — verify learn/articles/cron data pipeline endpoints.""" import json import subprocess import pytest BASE_URL = "http://127.0.0.1:5001" def _curl_status_body(path): r = subprocess.run( ["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}", f"{BASE_URL}{path}"], capture_output=True, text=True, timeout=10, ) status = int(r.stdout.strip() or 0) r2 = subprocess.run( ["curl", "-s", f"{BASE_URL}{path}"], capture_output=True, text=True, timeout=10, ) try: body = json.loads(r2.stdout) if r2.stdout.strip() else {} except Exception: body = {"_raw": r2.stdout[:200]} return status, body ENDPOINTS = [ "/api/cron/list", "/api/learn-queue", "/api/articles", "/api/reports", "/api/learn-results", ] @pytest.mark.parametrize("ep", ENDPOINTS) def test_pipeline_endpoint_returns_200(ep): status, _ = _curl_status_body(ep) assert status == 200, f"{ep} status={status}" @pytest.mark.parametrize("ep", ENDPOINTS) def test_pipeline_endpoint_returns_ok_true(ep): _, data = _curl_status_body(ep) assert data.get("ok") is True, f"{ep} body={data}" @pytest.mark.parametrize("ep", ENDPOINTS) def test_pipeline_endpoint_returns_list(ep): _, data = _curl_status_body(ep) assert isinstance(data.get("data"), list), f"{ep} data type={type(data.get('data'))}" if __name__ == "__main__": pytest.main([__file__, "-v"])