Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit c516bfb

Browse files
author
Norberto Lopes
authored
Merge pull request #331 from duffelhq/nlopes-fix-322
fix: add stops to slices segments
2 parents 7baa6ab + 0e78121 commit c516bfb

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

duffel_api/models/offer.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,29 @@ def from_json(cls, json: dict):
221221
)
222222

223223

224+
@dataclass
225+
class OfferSliceSegmentStop:
226+
"""Additional segment-specific information about the stops"""
227+
228+
id: str
229+
airport: Airport
230+
departing_at: datetime
231+
arriving_at: datetime
232+
duration: str
233+
234+
@classmethod
235+
def from_json(cls, json: dict):
236+
"""Construct a class instance from a JSON response."""
237+
print(json)
238+
return cls(
239+
id=json["id"],
240+
airport=Airport.from_json(json["airport"]),
241+
departing_at=parse_datetime(json["departing_at"]),
242+
arriving_at=parse_datetime(json["arriving_at"]),
243+
duration=json["duration"],
244+
)
245+
246+
224247
@dataclass
225248
class OfferSliceSegment:
226249
"""The segments - that is, specific flights - that the airline is offering
@@ -242,6 +265,7 @@ class OfferSliceSegment:
242265
operating_carrier: Airline
243266
operating_carrier_flight_number: Optional[str]
244267
passengers: Sequence[OfferSliceSegmentPassenger]
268+
stops: Sequence[OfferSliceSegmentStop]
245269

246270
@classmethod
247271
def from_json(cls, json: dict):
@@ -270,6 +294,12 @@ def from_json(cls, json: dict):
270294
],
271295
[],
272296
),
297+
stops=get_and_transform(
298+
json,
299+
"stops",
300+
lambda value: [OfferSliceSegmentStop.from_json(stop) for stop in value],
301+
[],
302+
),
273303
)
274304

275305

tests/fixtures/get-partial-offer-request-by-id.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
"type": "airport"
281281
},
282282
"departing_at": "2020-06-13T16:38:02",
283+
"arriving_at": "2020-06-13T11:38:02",
283284
"duration": "PT02H26M",
284285
"id": "sto_00009htYpSCXrwaB9Dn456"
285286
}

tests/test_partial_offer_requests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def test_get_partial_offer_request_by_id(requests_mock):
2020
offer = offer_request.offers[0]
2121
assert offer.partial
2222
assert offer.id == "off_00009htYpSCXrwaB9DnUm0"
23+
assert offer.slices[0].segments[0].id == "seg_00009htYpSCXrwaB9Dn456"
24+
assert offer.slices[0].segments[0].stops[0].id == "sto_00009htYpSCXrwaB9Dn456"
2325

2426

2527
def test_create_partial_offer_request(requests_mock):

0 commit comments

Comments
 (0)