"""Connector parsing and classification on fixtures — never hits the network.""" from __future__ import annotations from pathlib import Path from satelliteindex import registry from satelliteindex.connectors.orbital.celestrak.gp import parse_omm from satelliteindex.connectors.orbital.celestrak.satcat import CelesTrakSatcatConnector from satelliteindex.ids import normalize_name, satellite_slug, slugify from satelliteindex.registry.reference import LAUNCH_SITES, OWNER_CODES, SATCAT_STATUS from satelliteindex.services.classify import Classifier, object_type_from_name FIX = Path(__file__).parent / "fixtures" def test_parse_omm_stations(): recs = parse_omm((FIX / "celestrak_stations.json").read_text()) assert len(recs) >= 10 iss = next(r for r in recs if r["norad"] == 25544) assert iss["cospar"] == "1998-067A" and iss["epoch"].tzinfo is not None assert 15 < iss["mean_motion"] < 16 def test_parse_satcat_head(): rows = CelesTrakSatcatConnector().parse((FIX / "satcat_head.csv").read_text()) assert len(rows) >= 150 sputnik = next(r for r in rows if r["norad"] == 2) assert sputnik["type"] == "PAYLOAD" and sputnik["owner"] == "CIS" and sputnik["decay"] is not None and sputnik["site"] == "TYMSC" assert SATCAT_STATUS[sputnik["ops"]] == "DECAYED" assert all(r["owner"] in OWNER_CODES for r in rows if r["owner"]) assert all(r["site"] in LAUNCH_SITES for r in rows if r["site"]) def test_registry_patterns(): assert registry.match_constellation("STARLINK-32001").slug == "starlink" assert registry.match_constellation("ONEWEB-0123").slug == "oneweb" assert registry.match_constellation("NAVSTAR 81 (USA 343)").slug == "gps" assert registry.match_constellation("ISS (ZARYA)").slug == "iss" assert registry.match_constellation("COSMOS 2576").slug == "cosmos" assert registry.match_constellation("GALAXY 37 (HORIZONS 4)").slug == "intelsat" assert registry.match_constellation("FLOCK 4X-12").slug == "planet-flock" assert registry.match_constellation("RANDOM OBJECT 42") is None assert registry.match_mission("NOAA 19") == "weather" assert registry.match_mission("LANDSAT 9") == "earth-observation" assert registry.match_mission("HST") == "science" def test_classifier_offline(): clf = Classifier(constellation_ids={"starlink": "con_1", "gps": "con_2"}, constellation_ops={"starlink": "org_spacex", "gps": "org_ussf"}, org_ids={"spacex": "org_spacex", "us-space-force": "org_ussf"}, owner_map={"US": ("US", None), "SES": ("LU", "org_ses")}) out = clf.classify("STARLINK-1007", "US", "PAYLOAD") assert out == {"constellation_id": "con_1", "operator_id": "org_spacex", "country_code": "US", "mission_type": "communications", "method": "name_pattern"} out = clf.classify("SES-17", "SES", "PAYLOAD") assert out["operator_id"] == "org_ses" and out["country_code"] == "LU" out = clf.classify("SL-16 R/B", "CIS", "ROCKET_BODY") assert out["mission_type"] == "rocket-body" and out["constellation_id"] is None assert object_type_from_name("ISS (ZARYA)", "PAYLOAD") == "STATION" assert object_type_from_name("STARLINK-1", "PAYLOAD") == "PAYLOAD" def test_ids_and_slugs(): assert slugify("ISS (ZARYA)") == "iss-zarya" assert satellite_slug("ISS (ZARYA)", 25544) == "iss-zarya-25544" assert normalize_name("Space Exploration Technologies Corp.") == "SPACE EXPLORATION TECHNOLOGIES CORP" assert slugify("Ñusat-1 (Fresco)") == "nusat-1-fresco"