Consolidate to single GraphQL call; show indirect trains; fix price formatting
Replace two-step Eurostar fetch (HTML timetable + GraphQL prices) with a single GraphQL call that returns timing, train numbers, prices, and seats. Support indirect services (e.g. Amsterdam) by joining multi-leg train numbers with ' + ' and keeping the earliest arrival per departure time. Fix half-pound prices by casting displayPrice to float instead of int. Wrap each train number segment in white-space:nowrap so 'ES 9132 + ER 9363' never breaks mid-segment. Format Eurostar prices with two decimal places. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
05eec29b7d
commit
c22a3ea0fc
5 changed files with 182 additions and 320 deletions
|
|
@ -16,25 +16,21 @@ def _stub_data(monkeypatch, prices=None):
|
|||
{'depart_bristol': '07:00', 'arrive_paddington': '08:45', 'headcode': '1A23'},
|
||||
],
|
||||
)
|
||||
p = (prices or {}).get('10:01', {})
|
||||
monkeypatch.setattr(
|
||||
app_module.eurostar_scraper,
|
||||
'fetch',
|
||||
lambda destination, travel_date, user_agent: [
|
||||
lambda destination, travel_date: [
|
||||
{
|
||||
'depart_st_pancras': '10:01',
|
||||
'arrive_destination': '13:34',
|
||||
'destination': destination,
|
||||
'train_number': 'ES 9014',
|
||||
'price': p.get('price') if isinstance(p, dict) else None,
|
||||
'seats': p.get('seats') if isinstance(p, dict) else None,
|
||||
},
|
||||
],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
app_module.eurostar_scraper,
|
||||
'timetable_url',
|
||||
lambda destination: f'https://example.test/{destination.lower().replace(" ", "-")}',
|
||||
)
|
||||
_prices = prices if prices is not None else {}
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: _prices)
|
||||
|
||||
|
||||
def test_index_shows_fixed_departure_and_destination_radios():
|
||||
|
|
@ -96,7 +92,6 @@ def test_results_title_and_social_meta_include_destination(monkeypatch):
|
|||
def test_results_marks_trips_within_five_minutes_of_fastest_and_slowest(monkeypatch):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key, ttl=None: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: {})
|
||||
monkeypatch.setattr(
|
||||
app_module.rtt_scraper,
|
||||
'fetch',
|
||||
|
|
@ -111,44 +106,14 @@ def test_results_marks_trips_within_five_minutes_of_fastest_and_slowest(monkeypa
|
|||
monkeypatch.setattr(
|
||||
app_module.eurostar_scraper,
|
||||
'fetch',
|
||||
lambda destination, travel_date, user_agent: [
|
||||
{
|
||||
'depart_st_pancras': '09:30',
|
||||
'arrive_destination': '11:50',
|
||||
'destination': destination,
|
||||
'train_number': 'ES 1001',
|
||||
},
|
||||
{
|
||||
'depart_st_pancras': '09:40',
|
||||
'arrive_destination': '12:00',
|
||||
'destination': destination,
|
||||
'train_number': 'ES 1002',
|
||||
},
|
||||
{
|
||||
'depart_st_pancras': '09:50',
|
||||
'arrive_destination': '12:20',
|
||||
'destination': destination,
|
||||
'train_number': 'ES 1003',
|
||||
},
|
||||
{
|
||||
'depart_st_pancras': '10:00',
|
||||
'arrive_destination': '12:35',
|
||||
'destination': destination,
|
||||
'train_number': 'ES 1004',
|
||||
},
|
||||
{
|
||||
'depart_st_pancras': '10:10',
|
||||
'arrive_destination': '12:45',
|
||||
'destination': destination,
|
||||
'train_number': 'ES 1005',
|
||||
},
|
||||
lambda destination, travel_date: [
|
||||
{'depart_st_pancras': '09:30', 'arrive_destination': '11:50', 'destination': destination, 'train_number': 'ES 1001', 'price': None, 'seats': None},
|
||||
{'depart_st_pancras': '09:40', 'arrive_destination': '12:00', 'destination': destination, 'train_number': 'ES 1002', 'price': None, 'seats': None},
|
||||
{'depart_st_pancras': '09:50', 'arrive_destination': '12:20', 'destination': destination, 'train_number': 'ES 1003', 'price': None, 'seats': None},
|
||||
{'depart_st_pancras': '10:00', 'arrive_destination': '12:35', 'destination': destination, 'train_number': 'ES 1004', 'price': None, 'seats': None},
|
||||
{'depart_st_pancras': '10:10', 'arrive_destination': '12:45', 'destination': destination, 'train_number': 'ES 1005', 'price': None, 'seats': None},
|
||||
],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
app_module.eurostar_scraper,
|
||||
'timetable_url',
|
||||
lambda destination: f'https://example.test/{destination.lower().replace(" ", "-")}',
|
||||
)
|
||||
client = _client()
|
||||
|
||||
resp = client.get('/results/paris/2026-04-10?min_connection=60&max_connection=120')
|
||||
|
|
@ -168,7 +133,6 @@ def test_results_marks_trips_within_five_minutes_of_fastest_and_slowest(monkeypa
|
|||
def test_results_shows_unreachable_morning_eurostar_services(monkeypatch):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key, ttl=None: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: {})
|
||||
monkeypatch.setattr(
|
||||
app_module.rtt_scraper,
|
||||
'fetch',
|
||||
|
|
@ -179,32 +143,12 @@ def test_results_shows_unreachable_morning_eurostar_services(monkeypatch):
|
|||
monkeypatch.setattr(
|
||||
app_module.eurostar_scraper,
|
||||
'fetch',
|
||||
lambda destination, travel_date, user_agent: [
|
||||
{
|
||||
'depart_st_pancras': '09:30',
|
||||
'arrive_destination': '12:00',
|
||||
'destination': destination,
|
||||
'train_number': 'ES 9001',
|
||||
},
|
||||
{
|
||||
'depart_st_pancras': '10:15',
|
||||
'arrive_destination': '13:40',
|
||||
'destination': destination,
|
||||
'train_number': 'ES 9002',
|
||||
},
|
||||
{
|
||||
'depart_st_pancras': '12:30',
|
||||
'arrive_destination': '15:55',
|
||||
'destination': destination,
|
||||
'train_number': 'ES 9003',
|
||||
},
|
||||
lambda destination, travel_date: [
|
||||
{'depart_st_pancras': '09:30', 'arrive_destination': '12:00', 'destination': destination, 'train_number': 'ES 9001', 'price': None, 'seats': None},
|
||||
{'depart_st_pancras': '10:15', 'arrive_destination': '13:40', 'destination': destination, 'train_number': 'ES 9002', 'price': None, 'seats': None},
|
||||
{'depart_st_pancras': '12:30', 'arrive_destination': '15:55', 'destination': destination, 'train_number': 'ES 9003', 'price': None, 'seats': None},
|
||||
],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
app_module.eurostar_scraper,
|
||||
'timetable_url',
|
||||
lambda destination: f'https://example.test/{destination.lower().replace(" ", "-")}',
|
||||
)
|
||||
client = _client()
|
||||
|
||||
resp = client.get('/results/paris/2026-04-10?min_connection=60&max_connection=120')
|
||||
|
|
@ -234,7 +178,6 @@ def test_results_shows_eurostar_price_and_total(monkeypatch):
|
|||
def test_results_can_show_only_unreachable_morning_services(monkeypatch):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key, ttl=None: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: {})
|
||||
monkeypatch.setattr(
|
||||
app_module.rtt_scraper,
|
||||
'fetch',
|
||||
|
|
@ -245,20 +188,10 @@ def test_results_can_show_only_unreachable_morning_services(monkeypatch):
|
|||
monkeypatch.setattr(
|
||||
app_module.eurostar_scraper,
|
||||
'fetch',
|
||||
lambda destination, travel_date, user_agent: [
|
||||
{
|
||||
'depart_st_pancras': '09:30',
|
||||
'arrive_destination': '12:00',
|
||||
'destination': destination,
|
||||
'train_number': 'ES 9001',
|
||||
},
|
||||
lambda destination, travel_date: [
|
||||
{'depart_st_pancras': '09:30', 'arrive_destination': '12:00', 'destination': destination, 'train_number': 'ES 9001', 'price': None, 'seats': None},
|
||||
],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
app_module.eurostar_scraper,
|
||||
'timetable_url',
|
||||
lambda destination: f'https://example.test/{destination.lower().replace(" ", "-")}',
|
||||
)
|
||||
client = _client()
|
||||
|
||||
resp = client.get('/results/paris/2026-04-10?min_connection=60&max_connection=120')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue