Files
rail-game/backend/tests/test_models.py
zwitschi c2927f2f60 feat: Enhance track model and import functionality
- Added new fields to TrackModel: status, is_bidirectional, and coordinates.
- Updated network service to handle new track attributes and geometry extraction.
- Introduced CLI scripts for importing and loading tracks from OpenStreetMap.
- Implemented normalization of track elements to ensure valid geometries.
- Enhanced tests for track model, network service, and import/load scripts.
- Updated frontend to accommodate new track attributes and improve route computation.
- Documented OSM ingestion process in architecture and runtime views.
2025-10-11 19:54:10 +02:00

56 lines
1.4 KiB
Python

from datetime import datetime, timezone
from backend.app.models import StationModel, TrackModel, TrainModel
def _now() -> datetime:
return datetime.now(timezone.utc)
def test_station_model_round_trip() -> None:
timestamp = _now()
station = StationModel(
id="station-1",
name="Central",
latitude=52.52,
longitude=13.405,
created_at=timestamp,
updated_at=timestamp,
)
assert station.name == "Central"
assert station.model_dump()["id"] == "station-1"
def test_track_model_properties() -> None:
timestamp = _now()
track = TrackModel(
id="track-1",
start_station_id="station-1",
end_station_id="station-2",
length_meters=1500.0,
max_speed_kph=120.0,
status="operational",
is_bidirectional=True,
coordinates=[(52.52, 13.405), (52.6, 13.5)],
created_at=timestamp,
updated_at=timestamp,
)
assert track.length_meters > 0
assert track.start_station_id != track.end_station_id
assert len(track.coordinates) == 2
def test_train_model_operating_tracks() -> None:
timestamp = _now()
train = TrainModel(
id="train-1",
designation="Express",
capacity=350,
max_speed_kph=200.0,
operating_track_ids=["track-1", "track-2"],
created_at=timestamp,
updated_at=timestamp,
)
assert train.capacity >= 0
assert len(train.operating_track_ids) == 2