Keep active crewed missions on launches page

This commit is contained in:
Edward Betts 2026-02-21 16:00:52 +00:00
parent 7cced919a2
commit a275683f90
2 changed files with 261 additions and 4 deletions

View file

@ -2,7 +2,13 @@
import deepdiff
import pytest
from agenda.thespacedevs import format_launch_changes
from datetime import datetime, timezone
from agenda.thespacedevs import (
format_launch_changes,
is_active_crewed_spaceflight,
is_crewed_spaceflight,
)
# --- Helper Functions for Tests ---
@ -458,7 +464,9 @@ def test_mission_name_change():
old_launch = {"name": "Starship | Flight 9"}
new_launch = {"name": "Starship | Flight 10"}
diff = deepdiff.DeepDiff(old_launch, new_launch)
expected = "• Mission name changed from 'Starship | Flight 9' to 'Starship | Flight 10'"
expected = (
"• Mission name changed from 'Starship | Flight 9' to 'Starship | Flight 10'"
)
assert format_launch_changes(diff) == expected
@ -610,3 +618,60 @@ def test_multiple_changes():
assert len(result_lines) == len(expected_changes)
for expected_line in expected_changes:
assert expected_line in result_lines
def test_is_crewed_spaceflight_uses_human_rated() -> None:
"""Crewed flight detection should use human-rated spacecraft config."""
flight = {
"spacecraft": {"spacecraft_config": {"human_rated": True}},
"launch": {"mission": {"type": "Communications"}},
}
assert is_crewed_spaceflight(flight)
def test_is_active_crewed_spaceflight_future_mission_end() -> None:
"""Crewed flight with mission end in the future should be active."""
now = datetime(2026, 2, 21, 12, 0, tzinfo=timezone.utc)
flight = {
"mission_end": "2026-02-22T12:00:00Z",
"spacecraft": {
"in_space": True,
"spacecraft_config": {"human_rated": True},
},
"launch": {
"net": "2026-02-20T10:00:00Z",
"mission": {"type": "Human Exploration"},
},
"landing": {"success": None},
}
assert is_active_crewed_spaceflight(flight, now)
def test_is_active_crewed_spaceflight_ended_mission() -> None:
"""Crewed flight should be inactive after mission end time."""
now = datetime(2026, 2, 21, 12, 0, tzinfo=timezone.utc)
flight = {
"mission_end": "2026-02-21T09:00:00Z",
"spacecraft": {
"in_space": False,
"spacecraft_config": {"human_rated": True},
},
"launch": {"net": "2026-02-20T10:00:00Z", "mission": {"type": "Tourism"}},
"landing": {"success": True},
}
assert not is_active_crewed_spaceflight(flight, now)
def test_is_active_crewed_spaceflight_excludes_future_launches() -> None:
"""Crewed flight record should not be active before launch."""
now = datetime(2026, 2, 21, 12, 0, tzinfo=timezone.utc)
flight = {
"mission_end": None,
"spacecraft": {
"in_space": True,
"spacecraft_config": {"human_rated": True},
},
"launch": {"net": "2026-02-22T10:00:00Z", "mission": {"type": "Tourism"}},
"landing": {"success": None},
}
assert not is_active_crewed_spaceflight(flight, now)