34 lines
986 B
Python
34 lines
986 B
Python
"""Unit tests for config loading from .env (CONFLUENCE_PAT / CONFLUENCE_URL)."""
|
|
import pytest
|
|
|
|
from confluence_crawler.config import get_config, get_pat, get_url
|
|
|
|
|
|
def test_pat_loaded_from_env():
|
|
pat = get_pat()
|
|
assert pat, "CONFLUENCE_PAT must be set in .env"
|
|
assert len(pat) >= 20, "PAT looks too short"
|
|
|
|
|
|
def test_url_loaded_from_env():
|
|
url = get_url()
|
|
assert url.startswith("https://"), f"CONFLUENCE_URL should be https, got {url!r}"
|
|
assert not url.endswith("/"), "CONFLUENCE_URL should not end with /"
|
|
|
|
|
|
def test_config_returns_both():
|
|
cfg = get_config()
|
|
assert cfg["pat"] and cfg["url"]
|
|
|
|
|
|
def test_missing_pat_raises(monkeypatch):
|
|
monkeypatch.delenv("CONFLUENCE_PAT", raising=False)
|
|
with pytest.raises(RuntimeError, match="CONFLUENCE_PAT"):
|
|
get_pat()
|
|
|
|
|
|
def test_missing_url_raises(monkeypatch):
|
|
monkeypatch.delenv("CONFLUENCE_URL", raising=False)
|
|
with pytest.raises(RuntimeError, match="CONFLUENCE_URL"):
|
|
get_url()
|