sync
This commit is contained in:
@@ -8,11 +8,16 @@ from rf4_research.community_sources import (
|
||||
parse_rf4db_catches,
|
||||
parse_rf4db_detail,
|
||||
parse_rf4db_waterbodies,
|
||||
parse_rf4db_waterbody_detail,
|
||||
parse_rf4map_point,
|
||||
parse_rf4posts_spot,
|
||||
parse_rf4stat_fishing,
|
||||
parse_rf4stat_posts,
|
||||
)
|
||||
from rf4_research.waterbody_crosswalk import (
|
||||
CanonicalWaterbody, WaterbodyIdentity, missing_external_ids,
|
||||
suggest_waterbody_crosswalk,
|
||||
)
|
||||
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
@@ -74,6 +79,65 @@ def test_rf4db_waterbody_catalog_rejects_partial_results() -> None:
|
||||
parse_rf4db_waterbodies(fixture("rf4db_waterbodies_sample.html"))
|
||||
|
||||
|
||||
def test_parses_rf4db_waterbody_detail_without_assigning_media_roles() -> None:
|
||||
row = parse_rf4db_waterbody_detail(
|
||||
fixture("rf4db_waterbody_detail_sample.html"),
|
||||
source_url="https://rf4db.com/ru/maps/level_001_mosquito",
|
||||
)
|
||||
|
||||
assert (row.source_external_id, row.name) == ("level_001_mosquito", "оз. Комариное")
|
||||
assert row.description == "Большое озеро с каменистыми берегами."
|
||||
assert row.aliases == ("Комариное",)
|
||||
assert row.fish_species == ("Щука", "Окунь")
|
||||
assert row.fish_external_ids == ("pike", "perch")
|
||||
assert row.image_urls == (
|
||||
"https://oss.rf4db.com/game/maps/level_001_mosquito.webp",
|
||||
"https://rf4db.com/game/maps/level_001_mosquito-depth.webp",
|
||||
)
|
||||
assert row.point_urls == ("https://rf4db.com/ru/maps/level_001_mosquito/spots/12-34",)
|
||||
|
||||
|
||||
def test_parses_live_waterbody_fish_links_without_fish_media() -> None:
|
||||
row = parse_rf4db_waterbody_detail(
|
||||
fixture("rf4db_waterbody_detail_live_sample.html"),
|
||||
source_url="https://rf4db.com/ru/maps/level_000_home",
|
||||
)
|
||||
assert row.fish_species == ("Лягушка", "Ротан", "Окунь")
|
||||
assert row.fish_external_ids == ("frog", "a.sleeper", "perch")
|
||||
assert row.image_urls == (
|
||||
"https://oss.rf4db.com/game/maps/level_000_home.png",
|
||||
"https://oss.rf4db.com/game/paper_maps_webp/map_level_000_home.webp",
|
||||
)
|
||||
|
||||
|
||||
def test_rf4db_waterbody_detail_rejects_missing_fish_list() -> None:
|
||||
with pytest.raises(CommunityParseError, match="detail not found or incomplete"):
|
||||
parse_rf4db_waterbody_detail(
|
||||
"<main><h1>Озеро</h1></main>",
|
||||
source_url="https://rf4db.com/ru/maps/level_001_mosquito",
|
||||
)
|
||||
|
||||
|
||||
def test_waterbody_crosswalk_only_suggests_unique_exact_matches() -> None:
|
||||
canonical = [
|
||||
CanonicalWaterbody("mosquito", "оз. Комариное", ("Комариное",)),
|
||||
CanonicalWaterbody("ambiguous-a", "Большое озеро"),
|
||||
CanonicalWaterbody("ambiguous-b", "Другое", ("Большое озеро",)),
|
||||
]
|
||||
rows = suggest_waterbody_crosswalk(canonical, [
|
||||
WaterbodyIdentity("rf4db", "level_001_mosquito", "КОМАРИНОЕ"),
|
||||
WaterbodyIdentity("rf4map", "16", "Большое озеро"),
|
||||
WaterbodyIdentity("rf4-posts", "lake-x", "Норвежское море"),
|
||||
])
|
||||
assert [(row.status, row.canonical_keys) for row in rows] == [
|
||||
("exact", ("mosquito",)), ("ambiguous", ()), ("unmatched", ()),
|
||||
]
|
||||
|
||||
|
||||
def test_missing_source_ids_are_diagnostic_not_withdrawals() -> None:
|
||||
assert missing_external_ids({"16", "17", "18"}, {"16"}) == ("17", "18")
|
||||
|
||||
|
||||
def test_parses_rf4stat_fishing_rows() -> None:
|
||||
row = parse_rf4stat_fishing(
|
||||
fixture("rf4stat_fishing_sample.html"),
|
||||
@@ -82,6 +146,7 @@ def test_parses_rf4stat_fishing_rows() -> None:
|
||||
|
||||
assert (row.source_system, row.source_external_id) == ("rf4stat-fishing", "123")
|
||||
assert (row.x, row.y, row.weight_g) == (71, 92, 11_584)
|
||||
assert row.coordinate_raw == "71:92"
|
||||
assert row.published_at == datetime(2026, 9, 3, 11, 27, tzinfo=timezone.utc)
|
||||
assert (row.player_name, row.clip, row.fishing_style) == ("Игрок", "35", "Донная")
|
||||
|
||||
@@ -91,6 +156,7 @@ def test_parses_rf4stat_posts_without_using_locked_coordinates() -> None:
|
||||
|
||||
assert (row.source_system, row.source_external_id) == ("rf4stat-post", "456:0")
|
||||
assert (row.x, row.y, row.weight_g) == (None, None, 4_321)
|
||||
assert row.coordinate_raw == "XX:XX"
|
||||
assert row.evidence_urls == ("https://img.example.test/proof.jpg",)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user