dnd5-scripts/faction_turns/tests/test_faction_integration.py

66 lines
2.7 KiB
Python
Raw 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 pytest
import sys
import requests
from pathlib import Path
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from faction_utils import get_faction, get_all_factions
from vault_utils import BASE_URL, API_KEY, write_file
# ----------------------------------------------- Faction Integration Tests ------------------------------------------------------------
def test_obsidian_connection():
"""Проверяет наличие связи с плагином Obsidian Local REST API."""
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
resp = requests.get(BASE_URL + "/", headers=headers, verify=False, proxies={"http": None, "https": None})
assert resp.status_code == 200, f"Expected 200, got {resp.status_code}. Response: {resp.text}"
def test_setup_test_factions():
"""Подготавливает тестовые файлы фракций, перезаписывая их содержимое для предсказуемости тестов."""
fm_a = {
"name": "Test_Faction_A",
"tags": ["faction"],
"force": 4,
"treasure": 10,
"assets": [{"name": "Asset1"}, {"name": "Asset2"}]
}
assert write_file("Фракции/Tests/Test_Faction_A.md", fm_a, "# Test Faction A\nФайл для автоматических тестов.") is True
fm_b = {
"name": "Test_Faction_B",
"tags": ["faction"],
"wealth": 4,
"cunning": 2
}
assert write_file("Фракции/Tests/Test_Faction_B.md", fm_b, "# Test Faction B\nФайл для автоматических тестов.") is True
def test_get_faction_integration():
"""Проверяет чтение конкретной тестовой фракции через vault_utils API."""
faction = get_faction("Фракции/Tests/Test_Faction_A.md")
assert faction is not None
assert faction.get("name") == "Test_Faction_A"
fm = faction.get("frontmatter", {})
assert fm.get("force") == 4
assert fm.get("treasure") == 10
assert len(fm.get("assets", [])) == 2
def test_get_all_factions_integration():
"""Проверяет загрузку списка тестовых фракций из директории Tests."""
factions = get_all_factions("Фракции/Tests")
assert len(factions) >= 2
names = [f.get("name") for f in factions]
assert "Test_Faction_A" in names
assert "Test_Faction_B" in names
faction_b = next(f for f in factions if f.get("name") == "Test_Faction_B")
fm_b = faction_b.get("frontmatter", {})
assert fm_b.get("wealth") == 4
assert fm_b.get("cunning") == 2