fix: enforce community cooldown per site
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from rf4_research.community_cli import enforce_fetch_interval, mark_fetch
|
||||
from rf4_research import community_cli
|
||||
from rf4_research.community_cli import enforce_fetch_interval, fetch_site_key, mark_fetch
|
||||
|
||||
|
||||
def test_fetch_cooldown_is_persistent_per_source(tmp_path: Path) -> None:
|
||||
@@ -13,3 +15,19 @@ def test_fetch_cooldown_is_persistent_per_source(tmp_path: Path) -> None:
|
||||
enforce_fetch_interval("rf4map-point", state_file=state_file, now=1_000)
|
||||
enforce_fetch_interval("rf4posts-spot", state_file=state_file, now=1_000)
|
||||
enforce_fetch_interval("rf4map-point", state_file=state_file, now=2_800)
|
||||
|
||||
|
||||
def test_fetch_site_key_groups_endpoints_and_normalizes_www() -> None:
|
||||
assert fetch_site_key("https://rf4-stat.ru/fishing/") == "rf4-stat.ru"
|
||||
assert fetch_site_key("https://www.rf4-stat.ru/posts/") == "rf4-stat.ru"
|
||||
|
||||
|
||||
def test_failed_fetch_still_reserves_site_cooldown(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
state_file = tmp_path / "fetch-state.json"
|
||||
|
||||
def fail(_url: str) -> str:
|
||||
raise OSError("offline")
|
||||
|
||||
monkeypatch.setattr(community_cli, "fetch_html", fail)
|
||||
assert community_cli.main(["rf4db", "--state-file", str(state_file)]) == 1
|
||||
assert "download.rf4db.com" in json.loads(state_file.read_text(encoding="utf-8"))
|
||||
|
||||
Reference in New Issue
Block a user