Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ httpx==0.27.2
gtfs-realtime-bindings==1.0.0
aiosqlite==0.20.0
pytest==8.3.3
pytest-asyncio==0.24.0
ruff==0.6.4
black==24.8.0
20 changes: 11 additions & 9 deletions backend/services/gtfs_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ def parse_alerts(feed_message: gtfs_realtime_pb2.FeedMessage) -> List[Dict[str,
if entry:
active_periods.append(entry)

alerts.append({
"alert_id": alert_id,
"header_text": header,
"description_text": description,
"route_ids": route_ids,
"cause": cause,
"effect": effect,
"active_periods": active_periods,
})
alerts.append(
{
"alert_id": alert_id,
"header_text": header,
"description_text": description,
"route_ids": route_ids,
"cause": cause,
"effect": effect,
"active_periods": active_periods,
}
)

return alerts

Expand Down
3 changes: 3 additions & 0 deletions backend/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ def __init__(self) -> None:
"bearing": 90.0,
"speed": 10.0,
"timestamp": 1710000000,
"transport_type": None,
}
]
self._routes = {
"route-1": {
"route_id": "route-1",
"route_short_name": "1",
"route_color": "#123456",
"route_long_name": None,
"route_text_color": None,
}
}
self._stops = {
Expand Down
34 changes: 23 additions & 11 deletions backend/tests/test_gtfs_db.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Tests for the SQLite static data cache layer (services/gtfs_db.py)."""

import json
import tempfile

import pytest

from services.gtfs_db import save_cached_static, load_cached_static, clear_cache
from services.gtfs_db import clear_cache, load_cached_static, save_cached_static


@pytest.fixture
Expand Down Expand Up @@ -40,7 +39,12 @@ def db_path():

SAMPLE_STOP_TIMES = {
"trip-1": [
{"stop_id": "A", "stop_sequence": 1, "arrival_time": "08:00:00", "departure_time": "08:05:00"},
{
"stop_id": "A",
"stop_sequence": 1,
"arrival_time": "08:00:00",
"departure_time": "08:05:00",
},
],
}

Expand Down Expand Up @@ -83,7 +87,9 @@ async def test_save_and_load(db_path):
@pytest.mark.asyncio
async def test_load_missing_url(db_path):
"""Load a feed URL that was never saved. Assert result is None."""
result = await load_cached_static("https://example.com/never-saved.zip", db_path=db_path)
result = await load_cached_static(
"https://example.com/never-saved.zip", db_path=db_path
)
assert result is None


Expand Down Expand Up @@ -152,8 +158,12 @@ async def test_save_without_optional_fields(db_path):
async def test_clear_cache_all(db_path):
"""Save two URLs, call clear_cache() with no feed_url argument. Load both
— both should return None."""
await save_cached_static("url1", {"r": {"id": "r"}}, {"s": {"id": "s"}}, db_path=db_path)
await save_cached_static("url2", {"r": {"id": "r"}}, {"s": {"id": "s"}}, db_path=db_path)
await save_cached_static(
"url1", {"r": {"id": "r"}}, {"s": {"id": "s"}}, db_path=db_path
)
await save_cached_static(
"url2", {"r": {"id": "r"}}, {"s": {"id": "s"}}, db_path=db_path
)

cleared = await clear_cache(db_path=db_path)
assert cleared is True
Expand All @@ -166,8 +176,12 @@ async def test_clear_cache_all(db_path):
async def test_clear_cache_single(db_path):
"""Save two URLs, call clear_cache(feed_url="url1"). "url1" should return
None, "url2" should still return data."""
await save_cached_static("url1", {"r": {"id": "r"}}, {"s": {"id": "s"}}, db_path=db_path)
await save_cached_static("url2", {"r": {"id": "r"}}, {"s": {"id": "s"}}, db_path=db_path)
await save_cached_static(
"url1", {"r": {"id": "r"}}, {"s": {"id": "s"}}, db_path=db_path
)
await save_cached_static(
"url2", {"r": {"id": "r"}}, {"s": {"id": "s"}}, db_path=db_path
)

cleared = await clear_cache(feed_url="url1", db_path=db_path)
assert cleared is True
Expand All @@ -180,7 +194,5 @@ async def test_clear_cache_single(db_path):
async def test_load_nonexistent_db():
"""Call load_cached_static with a path in a directory that doesn't exist.
The function should return None gracefully (catches exceptions internally)."""
result = await load_cached_static(
"url", db_path="/nonexistent/dir/cache.db"
)
result = await load_cached_static("url", db_path="/nonexistent/dir/cache.db")
assert result is None
Loading
Loading