from fastapi import FastAPI from fastapi.testclient import TestClient def test_crawl_returns_pages_and_links(monkeypatch): async def fake_fetch(url, timeout=10, retries=2): return "" async def fake_extract(html_text, include_images=False): return "content", "Title" async def fake_links(url, html_text, limit=100): if url.endswith("/start"): return ["https://example.com/next"] return [] monkeypatch.setattr("axon.routers.crawl.fetch_html", fake_fetch) monkeypatch.setattr("axon.routers.crawl.extract_html", fake_extract) monkeypatch.setattr("axon.routers.crawl.discover_links", fake_links) from axon.routers.crawl import router app = FastAPI() app.include_router(router) client = TestClient(app) resp = client.post("/crawl", json={"url": "https://example.com/start", "max_depth": 1}) assert resp.status_code == 200 data = resp.json() assert len(data["results"]) == 2 assert data["results"][0]["links"] == ["https://example.com/next"] def test_map_returns_discovered_urls(monkeypatch): async def fake_fetch(url, timeout=10, retries=2): return "" async def fake_links(url, html_text, limit=100): if url.endswith("/start"): return ["https://example.com/a", "https://other.com/b"] return [] monkeypatch.setattr("axon.routers.map.fetch_html", fake_fetch) monkeypatch.setattr("axon.routers.map.discover_links", fake_links) from axon.routers.map import router app = FastAPI() app.include_router(router) client = TestClient(app) resp = client.post("/map", json={"url": "https://example.com/start", "max_depth": 1}) assert resp.status_code == 200 data = resp.json() assert "https://example.com/start" in data["urls"] assert "https://example.com/a" in data["urls"] assert "https://other.com/b" not in data["urls"]