feat: add offline waterbody source crosswalk
This commit is contained in:
@@ -10,13 +10,15 @@ from rf4_research.community_sources import (
|
||||
parse_rf4db_waterbodies,
|
||||
parse_rf4db_waterbody_detail,
|
||||
parse_rf4map_point,
|
||||
parse_rf4map_waterbodies,
|
||||
parse_rf4posts_spot,
|
||||
parse_rf4stat_fishing,
|
||||
parse_rf4stat_posts,
|
||||
parse_rf4stat_waterbodies,
|
||||
)
|
||||
from rf4_research.waterbody_crosswalk import (
|
||||
CanonicalWaterbody, WaterbodyIdentity, missing_external_ids,
|
||||
suggest_waterbody_crosswalk,
|
||||
identities_from_candidates, suggest_waterbody_crosswalk,
|
||||
)
|
||||
|
||||
|
||||
@@ -69,6 +71,48 @@ def test_parses_rf4db_waterbody_catalog_without_inventing_image_roles() -> None:
|
||||
assert rows[1].image_url == "https://rf4db.com/game/maps/level_000_cottage.webp"
|
||||
|
||||
|
||||
def test_parses_rf4map_waterbody_directory_as_secondary_candidates() -> None:
|
||||
rows = parse_rf4map_waterbodies(fixture("rf4map_waterbodies_sample.html"))
|
||||
|
||||
assert [(row.source_external_id, row.name, row.fish_species_count) for row in rows] == [
|
||||
("12", "р. Нижняя Тунгуска", 38),
|
||||
("16", "оз. Комариное", None),
|
||||
]
|
||||
assert rows[0].source_system == "rf4map-waterbodies"
|
||||
assert rows[0].source_url == "https://rf4map.ru/lakes/12"
|
||||
|
||||
|
||||
def test_rf4map_waterbody_directory_rejects_unrelated_html() -> None:
|
||||
with pytest.raises(CommunityParseError, match="RF4MAP waterbody directory not found"):
|
||||
parse_rf4map_waterbodies("<html></html>")
|
||||
|
||||
|
||||
def test_parses_rf4stat_waterbody_directory_metrics() -> None:
|
||||
rows = parse_rf4stat_waterbodies(fixture("rf4stat_waterbodies_sample.html"))
|
||||
|
||||
assert [(row.source_external_id, row.name, row.catches_count, row.fish_species_count, row.bait_count, row.spot_count) for row in rows] == [
|
||||
("1", "Mosquito Lake", 254, 20, 42, 9),
|
||||
("19", "Elk Lake", 520, 19, 121, 11),
|
||||
]
|
||||
assert rows[0].source_url == "https://en.rf4-stat.ru/locations/location/1"
|
||||
|
||||
|
||||
def test_rf4stat_waterbody_directory_rejects_unrelated_html() -> None:
|
||||
with pytest.raises(CommunityParseError, match="RF4-STAT waterbody directory not found"):
|
||||
parse_rf4stat_waterbodies("<html></html>")
|
||||
|
||||
|
||||
def test_secondary_candidates_convert_to_crosswalk_identities_only() -> None:
|
||||
candidates = parse_rf4map_waterbodies(fixture("rf4map_waterbodies_sample.html"))
|
||||
|
||||
identities = identities_from_candidates(candidates)
|
||||
|
||||
assert identities == [
|
||||
WaterbodyIdentity("rf4map-waterbodies", "12", "р. Нижняя Тунгуска"),
|
||||
WaterbodyIdentity("rf4map-waterbodies", "16", "оз. Комариное"),
|
||||
]
|
||||
|
||||
|
||||
def test_rf4db_waterbody_catalog_rejects_unrelated_html() -> None:
|
||||
with pytest.raises(CommunityParseError, match="waterbody cards not found"):
|
||||
parse_rf4db_waterbodies("<html></html>")
|
||||
|
||||
Reference in New Issue
Block a user