@@ -235,15 +235,18 @@ def _record_booking_artifacts(case_id: str, rpc_captures: list[dict[str, str]],
235235 )
236236
237237
238- def _find_bookable_itinerary (search_result : Any ) -> Itinerary :
238+ def _bookable_candidates (search_result : Any , * , limit : int = 5 ) -> list [Itinerary ]:
239+ candidates : list [Itinerary ] = []
239240 for option in search_result .results :
240241 for leg in option .legs :
241242 itinerary = leg .itinerary
242243 if itinerary is None :
243244 continue
244245 if itinerary .booking_token and rpc ._build_selected_legs (itinerary ):
245- return itinerary
246- raise AssertionError ("Expected at least one itinerary with booking token and selected legs" )
246+ candidates .append (itinerary )
247+ if len (candidates ) >= limit :
248+ return candidates
249+ return candidates
247250
248251
249252class TestShoppingContract :
@@ -317,16 +320,27 @@ def test_booking_results_parseable_and_artifacted(self, monkeypatch: pytest.Monk
317320 )
318321 assert search_result .results , "Expected at least one itinerary before live booking lookup"
319322
320- itinerary = _find_bookable_itinerary (search_result )
323+ candidates = _bookable_candidates (search_result )
324+ assert candidates , "Expected at least one itinerary with booking token and selected legs"
325+
321326 rpc_captures = _capture_rpc_texts (monkeypatch )
322- options = rpc .get_booking_results (
323- itinerary ,
324- registry_version = date .today ().isoformat (),
325- transport = TransportConfig (timeout = 30 , retries = 1 ),
326- )
327+ options : list [Any ] = []
328+ itinerary : Itinerary | None = None
329+ for candidate in candidates :
330+ options = rpc .get_booking_results (
331+ candidate ,
332+ registry_version = date .today ().isoformat (),
333+ transport = TransportConfig (timeout = 30 , retries = 1 ),
334+ )
335+ if options :
336+ itinerary = candidate
337+ break
327338
328339 assert rpc_captures , "Expected a live booking RPC capture"
329- assert options , "Expected at least one booking option from live booking lookup"
340+ assert options and itinerary is not None , (
341+ f"Expected at least one booking option after trying { len (candidates )} "
342+ "itineraries (upstream returned empty for every candidate)"
343+ )
330344
331345 for option in options [:5 ]:
332346 assert option .price > 0
0 commit comments