diff --git a/TASKS.md b/TASKS.md index 85a1156..8bd2f63 100644 --- a/TASKS.md +++ b/TASKS.md @@ -18,7 +18,7 @@ - [x] Очистить документацию от сбоев форматирования Markdown ссылок. ## 5. Расширение тестов фракций -- [ ] Дописать интеграционные тесты для `get_recent_events`, `get_location` и работы с активами. +- [x] Дописать интеграционные тесты для `get_recent_events`, `get_location` и работы с активами. - [ ] Расширить тесты логики ходов фракций в `test_wwn_mechanics.py`. - [x] Добавлены setup-тесты для перезаписи тестовых файлов фракций (frontmatter и контент) для детерминированности среды. - [x] Убедиться, что текущий набор pytest проходит без ошибок (`pytest -v`). diff --git a/faction_turns/tests/test_faction_integration.py b/faction_turns/tests/test_faction_integration.py index 24a81fa..08b3426 100644 --- a/faction_turns/tests/test_faction_integration.py +++ b/faction_turns/tests/test_faction_integration.py @@ -7,7 +7,10 @@ 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 faction_utils import ( + get_faction, get_all_factions, get_recent_events, + get_location, get_assets_in_location, get_factions_in_location +) from vault_utils import BASE_URL, API_KEY, write_file # ----------------------------------------------- Faction Integration Tests ------------------------------------------------------------ @@ -63,3 +66,63 @@ def test_get_all_factions_integration(): fm_b = faction_b.get("frontmatter", {}) assert fm_b.get("wealth") == 4 assert fm_b.get("cunning") == 2 + + +def test_setup_test_locations(): + """Подготавливает тестовые файлы локаций и событий для тестов.""" + loc_a = { + "name": "Test_Location_A", + "travel-distance": {"[[Test_Location_B]]": 100} + } + write_file("TTRPG/Locations/Tests/Test_Location_A.md", loc_a, "# Location A") + + loc_b = { + "name": "Test_Location_B", + "travel-distance": {"[[Test_Location_A]]": 100} + } + write_file("TTRPG/Locations/Tests/Test_Location_B.md", loc_b, "# Location B") + + event = { + "name": "Test_Event_1", + "tags": ["event"] + } + write_file("События/Tests/Test_Event_1.md", event, "Event body") + +def test_get_location_integration(): + """Проверяет получение локации и парсинг расстояний.""" + loc = get_location("TTRPG/Locations/Tests/Test_Location_A.md") + assert loc is not None + assert loc.get("name") == "Test_Location_A" + assert loc.get("frontmatter", {}).get("travel-distance", {}).get("[[Test_Location_B]]") == 100 + +def test_get_recent_events_integration(): + """Проверяет получение списка недавних событий.""" + events = get_recent_events("События/Tests", tags_filter=["event"], max_count=5) + assert len(events) >= 1 + assert any(e.get("name") == "Test_Event_1" for e in events) + +def test_assets_and_factions_in_location_integration(): + """Проверяет поиск активов и фракций по локациям.""" + fm_c = { + "name": "Test_Faction_C", + "tags": ["faction"], + "locations": ["[[Test_Location_A]]"], + "assets": [ + {"name": "Asset1", "location": "[[Test_Location_A]]"}, + {"name": "Asset2", "location": "[[Test_Location_B]]"} + ] + } + write_file("Фракции/Tests/Test_Faction_C.md", fm_c, "# Test Faction C") + + faction = get_faction("Фракции/Tests/Test_Faction_C.md") + + # Test get_assets_in_location + assets_a = get_assets_in_location(faction, ["[[Test_Location_A]]"]) + assert len(assets_a) == 1 + assert assets_a[0]["name"] == "Asset1" + + # Test get_factions_in_location + factions = [faction] + factions_in_b = get_factions_in_location(factions, ["[[Test_Location_B]]"]) + assert len(factions_in_b) == 1 + assert factions_in_b[0].get("name") == "Test_Faction_C" \ No newline at end of file