Add return and inbound journey support
This commit is contained in:
parent
6ba71447ef
commit
9691632f65
12 changed files with 1687 additions and 486 deletions
|
|
@ -65,6 +65,17 @@ def test_search_redirects_to_results_with_selected_params():
|
|||
)
|
||||
|
||||
|
||||
def test_search_redirects_return_with_return_date():
|
||||
client = _client()
|
||||
|
||||
resp = client.get('/search?journey_type=return&destination=paris&travel_date=2026-04-10&return_date=2026-04-17&station_crs=BRI')
|
||||
|
||||
assert resp.status_code == 302
|
||||
assert resp.headers['Location'].endswith(
|
||||
'/results/BRI/paris/2026-04-10?journey_type=return&return_date=2026-04-17'
|
||||
)
|
||||
|
||||
|
||||
def test_results_shows_same_day_destination_switcher(monkeypatch):
|
||||
_stub_data(monkeypatch)
|
||||
client = _client()
|
||||
|
|
@ -290,6 +301,97 @@ def test_results_preloads_cached_advance_fares(monkeypatch):
|
|||
assert 'cachedAdvanceFares' in html
|
||||
|
||||
|
||||
def test_results_inbound_uses_reverse_legs(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.rtt_scraper,
|
||||
'fetch_from_paddington',
|
||||
lambda travel_date, user_agent, station_crs='BRI': [
|
||||
{'depart_paddington': '17:15', 'arrive_destination': '18:55', 'headcode': '1B99'},
|
||||
],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
app_module.gwr_fares_scraper,
|
||||
'fetch',
|
||||
lambda station_crs, travel_date, direction='to_paddington': {
|
||||
'17:15': {'ticket': 'Off-Peak Single', 'price': 63.60, 'code': 'SVS'}
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
app_module.eurostar_scraper,
|
||||
'fetch',
|
||||
lambda destination, travel_date, direction='outbound': [
|
||||
{'depart_destination': '15:12', 'arrive_st_pancras': '16:30',
|
||||
'destination': destination, 'train_number': 'ES 9035',
|
||||
'price': 49, 'seats': 43, 'plus_price': None, 'plus_seats': None},
|
||||
],
|
||||
)
|
||||
client = _client()
|
||||
|
||||
resp = client.get('/results/BRI/paris/2026-04-10?journey_type=inbound')
|
||||
html = resp.get_data(as_text=True)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert 'Paris Gare du Nord → Bristol Temple Meads' in html
|
||||
assert '15:12 → 16:30' in html
|
||||
assert '17:15 → 18:55' in html
|
||||
assert 'ES 9035' in html
|
||||
|
||||
|
||||
def test_results_return_renders_outbound_and_inbound_tables(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.rtt_scraper,
|
||||
'fetch',
|
||||
lambda travel_date, user_agent, station_crs='BRI': [
|
||||
{'depart_bristol': '07:00', 'arrive_paddington': '08:45', 'headcode': '1A23'},
|
||||
],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
app_module.rtt_scraper,
|
||||
'fetch_from_paddington',
|
||||
lambda travel_date, user_agent, station_crs='BRI': [
|
||||
{'depart_paddington': '17:15', 'arrive_destination': '18:55', 'headcode': '1B99'},
|
||||
],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
app_module.gwr_fares_scraper,
|
||||
'fetch',
|
||||
lambda station_crs, travel_date, direction='to_paddington': {
|
||||
'07:00': {'ticket': 'Anytime Day Single', 'price': 138.70, 'code': 'SDS'},
|
||||
'17:15': {'ticket': 'Off-Peak Single', 'price': 63.60, 'code': 'SVS'},
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
app_module.eurostar_scraper,
|
||||
'fetch_return',
|
||||
lambda destination, outbound_date, return_date: {
|
||||
'outbound': [
|
||||
{'depart_st_pancras': '10:01', 'arrive_destination': '13:34',
|
||||
'destination': destination, 'train_number': 'ES 9014',
|
||||
'price': 59, 'seats': 42, 'plus_price': None, 'plus_seats': None},
|
||||
],
|
||||
'inbound': [
|
||||
{'depart_destination': '15:12', 'arrive_st_pancras': '16:30',
|
||||
'destination': destination, 'train_number': 'ES 9035',
|
||||
'price': 49, 'seats': 43, 'plus_price': None, 'plus_seats': None},
|
||||
],
|
||||
},
|
||||
)
|
||||
client = _client()
|
||||
|
||||
resp = client.get('/results/BRI/paris/2026-04-10?journey_type=return&return_date=2026-04-17')
|
||||
html = resp.get_data(as_text=True)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert 'Outbound: Bristol Temple Meads → Paris Gare du Nord' in html
|
||||
assert 'Return: Paris Gare du Nord → Bristol Temple Meads' in html
|
||||
assert 'ES 9014' in html
|
||||
assert 'ES 9035' in html
|
||||
|
||||
|
||||
def test_api_advance_fares_returns_json(monkeypatch):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key, ttl=None: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue