36 lines
2.1 KiB
Python
36 lines
2.1 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
from rf4_research.media_cli import media_queue_plan
|
|
|
|
|
|
def test_queue_plan_prioritizes_entity_gaps_and_respects_domain_cooldown(tmp_path: Path) -> None:
|
|
root = tmp_path / "media"
|
|
root.mkdir()
|
|
(root / "catalog-baseline.json").write_text(json.dumps({
|
|
"verified_at": "2026-09-12",
|
|
"entities": {
|
|
"fish": {"count": 2}, "waterbody": {"count": 1}, "tackle": {"count": None},
|
|
},
|
|
}), encoding="utf-8")
|
|
(root / "manifest.json").write_text(json.dumps({"version": 1, "assets": [
|
|
{"status": "queued", "asset_url": "https://rf4map.ru/tackle.png", "source_page": "https://rf4map.ru/fishes", "entity_type": "tackle", "label": "Катушка", "external_id": "3"},
|
|
{"status": "queued", "asset_url": "https://rf4map.ru/fish.png", "source_page": "https://rf4map.ru/fishes", "entity_type": "fish", "label": "Щука", "external_id": "2"},
|
|
{"status": "queued", "asset_url": "https://rf4map.ru/water.png", "source_page": "https://rf4map.ru/maps", "entity_type": "waterbody", "label": "Ладога", "external_id": "1"},
|
|
{"status": "queued", "asset_url": "https://rf4-posts.com/fish.png", "source_page": "https://rf4-posts.com/fishes", "entity_type": "fish", "label": "Ёрш", "external_id": "4"},
|
|
{"status": "approved", "asset_url": "https://rf4map.ru/approved.png", "source_page": "https://rf4map.ru/fishes", "entity_type": "fish", "label": "Окунь", "entity_key": "perch"},
|
|
]}), encoding="utf-8")
|
|
state = tmp_path / "state.json"
|
|
state.write_text(json.dumps({"rf4map.ru": 1000}), encoding="utf-8")
|
|
|
|
plan = media_queue_plan(root, state, now=2000)
|
|
|
|
assert plan["network_requests"] == 0
|
|
assert plan["queued_total"] == 4
|
|
assert plan["domains"]["rf4map.ru"]["ready"] is False
|
|
assert plan["domains"]["rf4map.ru"]["retry_in_seconds"] == 800
|
|
assert plan["domains"]["rf4map.ru"]["queued_by_type"] == {"fish": 1, "tackle": 1, "waterbody": 1}
|
|
assert plan["domains"]["rf4map.ru"]["next_asset"]["entity_type"] == "waterbody"
|
|
assert plan["domains"]["rf4-posts.com"]["ready"] is True
|
|
assert plan["exact_catalog_gaps_known"] is False
|