58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""Live tests against the real Confluence instance using CONFLUENCE_PAT from .env.
|
|
|
|
These hit the network. They run when .env has valid credentials and are
|
|
skipped otherwise.
|
|
"""
|
|
import pytest
|
|
|
|
from confluence_crawler.config import get_config
|
|
from confluence_crawler.crawler import ConfluenceCrawler
|
|
|
|
try:
|
|
CFG = get_config()
|
|
except RuntimeError:
|
|
CFG = None
|
|
|
|
pytestmark = [
|
|
pytest.mark.live,
|
|
pytest.mark.skipif(CFG is None, reason="CONFLUENCE_PAT/CONFLUENCE_URL not set in .env"),
|
|
]
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def crawler():
|
|
return ConfluenceCrawler(CFG["url"], CFG["pat"])
|
|
|
|
|
|
def test_authentication_and_list_spaces(crawler):
|
|
"""PAT auth works and at least one space is visible (bounded fetch)."""
|
|
spaces = crawler.list_spaces(limit=25, max_spaces=25)
|
|
assert spaces, "no spaces visible with this PAT (check permissions)"
|
|
assert all("key" in s and "name" in s for s in spaces)
|
|
|
|
|
|
def test_get_pages_bounded(crawler):
|
|
"""Manual pagination fetches pages with body + version (max 5)."""
|
|
pages = crawler.get_pages("WEBOSAUTO", max_pages=5)
|
|
assert pages, "no pages returned for WEBOSAUTO"
|
|
for p in pages:
|
|
assert p.get("type") == "page"
|
|
assert p.get("body", {}).get("storage", {}).get("value"), f"no body for page {p.get('id')}"
|
|
|
|
|
|
def test_crawl_space_bounded(crawler, tmp_path):
|
|
"""Crawl a bounded number of pages and verify .md files + manifest."""
|
|
paths = crawler.crawl_space("WEBOSAUTO", tmp_path, max_pages=5)
|
|
assert len(paths) == 5
|
|
for p in paths:
|
|
assert p.suffix == ".md"
|
|
text = p.read_text(encoding="utf-8")
|
|
assert text.strip(), f"empty markdown file: {p}"
|
|
assert text.startswith("---"), f"missing front matter: {p}"
|
|
manifest = tmp_path / "manifest.json"
|
|
assert manifest.exists()
|
|
import json
|
|
entries = json.loads(manifest.read_text(encoding="utf-8"))
|
|
assert len(entries) == 5
|
|
assert all("url" in e and "file" in e for e in entries)
|