1
0
Fork 0
mirror of https://github.com/EDeev/declaude.git synced 2026-10-07 20:49:57 +03:00
declaude/tests/test_build.py
Egor Deev f5fa349815 Тесты: защита ссылок, экранирование, рендер Markdown, сборка архива и командная строка
20 тестов на тестовом экспорте tests/fixtures (вымышленные чаты и проект).
2026-10-02 20:38:58 +00:00

55 lines
2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
import shutil
from pathlib import Path
import pytest
from declaude import DataLoader, MappingManager, SiteBuilder
from declaude.cli import main
FIXTURE = Path(__file__).parent / "fixtures" / "backup"
@pytest.fixture
def archive(tmp_path):
loader = DataLoader(FIXTURE)
loader.load()
mapping = MappingManager(tmp_path / "mapping.json")
mapping.load()
mapping.assign("c-1", "p-1")
SiteBuilder(tmp_path / "out", loader, mapping).build_all()
return tmp_path / "out"
def test_full_build_creates_all_pages(archive):
for rel in ("index.html", "all_conversations.html", "projects/p-1/index.html",
"conversations/c-1.html", "conversations/c-2.html", "conversations/c-3.html",
"assets/style.css", "assets/app.js"):
assert (archive / rel).is_file(), rel
def test_conversation_page_content(archive):
page = (archive / "conversations" / "c-1.html").read_text(encoding="utf-8")
assert "Нормализация до 3НФ" in page
assert "<table" in page
assert 'href="https://www.postgresql.org/docs/"' in page
assert "javascript:" not in page
assert "<script>alert" not in page
def test_project_page_lists_assigned_conversation(archive):
page = (archive / "projects" / "p-1" / "index.html").read_text(encoding="utf-8")
assert "Курсовая по базам данных" in page
assert "c-1.html" in page and "c-2.html" not in page
def test_cli_build_and_map(tmp_path, monkeypatch):
src = tmp_path / "backup"
shutil.copytree(FIXTURE, src)
out, mp = tmp_path / "out", tmp_path / "mapping.json"
monkeypatch.setattr("sys.argv", ["declaude", "--build", "--source", str(src), "--output", str(out), "--mapping", str(mp)])
main()
assert (out / "index.html").is_file()
monkeypatch.setattr("sys.argv", ["declaude", "--map", "c-2", "p-1", "--source", str(src), "--output", str(out), "--mapping", str(mp)])
main()
assert json.loads(mp.read_text(encoding="utf-8")).get("c-2") == "p-1"