From b5546157e5083ce382ec63b8cde51d71adb905b8 Mon Sep 17 00:00:00 2001 From: Sasha Gerrand Date: Wed, 22 Dec 2021 12:36:04 +0000 Subject: [PATCH] Update parser for payment requirement fields Both `payment_required_by` and `price_guarantee_expires_at` are returned from the API without microsecond precision: "payment_requirements": { "requires_instant_payment": false, "price_guarantee_expires_at": "2021-12-24T11:39:45Z", "payment_required_by": "2021-12-25T11:39:45Z" }, --- duffel_api/utils.py | 8 ++++++-- tests/fixtures/create-offer-request.json | 4 ++-- tests/fixtures/create-order.json | 4 ++-- tests/fixtures/get-offer-by-id.json | 6 +++--- tests/fixtures/get-offer-request-by-id.json | 6 +++--- tests/fixtures/get-offer-requests.json | 6 +++--- tests/fixtures/get-offers.json | 6 +++--- tests/fixtures/get-order-by-id.json | 4 ++-- tests/fixtures/get-orders.json | 6 +++--- tests/fixtures/update-order-by-id.json | 4 ++-- 10 files changed, 29 insertions(+), 25 deletions(-) diff --git a/duffel_api/utils.py b/duffel_api/utils.py index 1c22388..598484c 100644 --- a/duffel_api/utils.py +++ b/duffel_api/utils.py @@ -14,12 +14,16 @@ def maybe_parse_date_entries(key, value): "pay_by", "confirmed_at", "cancelled_at", - "price_guarantee_expires_at", "synced_at", - "payment_required_by", ]: return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%fZ") + if key in [ + "price_guarantee_expires_at", + "payment_required_by", + ]: + return datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ") + if key in [ "departing_at", "arriving_at", diff --git a/tests/fixtures/create-offer-request.json b/tests/fixtures/create-offer-request.json index 0e0955e..17b97c9 100644 --- a/tests/fixtures/create-offer-request.json +++ b/tests/fixtures/create-offer-request.json @@ -41,8 +41,8 @@ } ], "payment_requirements": { - "payment_required_by": "2020-01-17T10:42:14.545Z", - "price_guarantee_expires_at": "2020-01-17T10:42:14.545Z", + "payment_required_by": "2020-01-17T10:42:14Z", + "price_guarantee_expires_at": "2020-01-17T10:42:14Z", "requires_instant_payment": false }, "slices": [ diff --git a/tests/fixtures/create-order.json b/tests/fixtures/create-order.json index cbd4bf0..9789e42 100644 --- a/tests/fixtures/create-order.json +++ b/tests/fixtures/create-order.json @@ -43,8 +43,8 @@ ], "payment_status": { "awaiting_payment": true, - "payment_required_by": "2020-01-17T10:42:14.545Z", - "price_guarantee_expires_at": "2020-01-17T10:42:14.545Z" + "payment_required_by": "2020-01-17T10:42:14Z", + "price_guarantee_expires_at": "2020-01-17T10:42:14Z" }, "payments": [ { diff --git a/tests/fixtures/get-offer-by-id.json b/tests/fixtures/get-offer-by-id.json index 55b7f7c..8a0e015 100644 --- a/tests/fixtures/get-offer-by-id.json +++ b/tests/fixtures/get-offer-by-id.json @@ -51,8 +51,8 @@ } ], "payment_requirements": { - "payment_required_by": "2020-01-17T10:42:14.545Z", - "price_guarantee_expires_at": "2020-01-17T10:42:14.545Z", + "payment_required_by": "2020-01-17T10:42:14Z", + "price_guarantee_expires_at": "2020-01-17T10:42:14Z", "requires_instant_payment": false }, "slices": [ @@ -230,4 +230,4 @@ "total_emissions_kg": "460", "updated_at": "2020-01-17T10:12:14.545Z" } -} \ No newline at end of file +} diff --git a/tests/fixtures/get-offer-request-by-id.json b/tests/fixtures/get-offer-request-by-id.json index d6ae4cb..d0e178b 100644 --- a/tests/fixtures/get-offer-request-by-id.json +++ b/tests/fixtures/get-offer-request-by-id.json @@ -41,8 +41,8 @@ } ], "payment_requirements": { - "payment_required_by": "2020-01-17T10:42:14.545Z", - "price_guarantee_expires_at": "2020-01-17T10:42:14.545Z", + "payment_required_by": "2020-01-17T10:42:14Z", + "price_guarantee_expires_at": "2020-01-17T10:42:14Z", "requires_instant_payment": false }, "slices": [ @@ -311,4 +311,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tests/fixtures/get-offer-requests.json b/tests/fixtures/get-offer-requests.json index 0c6a8c4..ca94c5a 100644 --- a/tests/fixtures/get-offer-requests.json +++ b/tests/fixtures/get-offer-requests.json @@ -42,8 +42,8 @@ } ], "payment_requirements": { - "payment_required_by": "2020-01-17T10:42:14.545Z", - "price_guarantee_expires_at": "2020-01-17T10:42:14.545Z", + "payment_required_by": "2020-01-17T10:42:14Z", + "price_guarantee_expires_at": "2020-01-17T10:42:14Z", "requires_instant_payment": false }, "slices": [ @@ -317,4 +317,4 @@ "after": "g2wAAAACbQAAABBBZXJvbWlzdC1LaGFya2l2bQAAAB=", "limit": 50 } -} \ No newline at end of file +} diff --git a/tests/fixtures/get-offers.json b/tests/fixtures/get-offers.json index 8e4fe76..dd9f798 100644 --- a/tests/fixtures/get-offers.json +++ b/tests/fixtures/get-offers.json @@ -36,8 +36,8 @@ } ], "payment_requirements": { - "payment_required_by": "2020-01-17T10:42:14.545Z", - "price_guarantee_expires_at": "2020-01-17T10:42:14.545Z", + "payment_required_by": "2020-01-17T10:42:14Z", + "price_guarantee_expires_at": "2020-01-17T10:42:14Z", "requires_instant_payment": false }, "slices": [ @@ -219,4 +219,4 @@ "after": "g2wAAAACbQAAABBBZXJvbWlzdC1LaGFya2l2bQAAAB=", "limit": 50 } -} \ No newline at end of file +} diff --git a/tests/fixtures/get-order-by-id.json b/tests/fixtures/get-order-by-id.json index 929bdc6..d3c39c3 100644 --- a/tests/fixtures/get-order-by-id.json +++ b/tests/fixtures/get-order-by-id.json @@ -54,8 +54,8 @@ ], "payment_status": { "awaiting_payment": true, - "payment_required_by": "2020-01-17T10:42:14.545Z", - "price_guarantee_expires_at": "2020-01-17T10:42:14.545Z" + "payment_required_by": "2020-01-17T10:42:14Z", + "price_guarantee_expires_at": "2020-01-17T10:42:14Z" }, "services": [ { diff --git a/tests/fixtures/get-orders.json b/tests/fixtures/get-orders.json index 9cec308..a1f256b 100644 --- a/tests/fixtures/get-orders.json +++ b/tests/fixtures/get-orders.json @@ -44,8 +44,8 @@ ], "payment_status": { "awaiting_payment": true, - "payment_required_by": "2020-01-17T10:42:14.545Z", - "price_guarantee_expires_at": "2020-01-17T10:42:14.545Z" + "payment_required_by": "2020-01-17T10:42:14Z", + "price_guarantee_expires_at": "2020-01-17T10:42:14Z" }, "payments": [ { @@ -260,4 +260,4 @@ "after": "g2wAAAACbQAAABBBZXJvbWlzdC1LaGFya2l2bQAAAB=", "limit": 50 } -} \ No newline at end of file +} diff --git a/tests/fixtures/update-order-by-id.json b/tests/fixtures/update-order-by-id.json index 929bdc6..d3c39c3 100644 --- a/tests/fixtures/update-order-by-id.json +++ b/tests/fixtures/update-order-by-id.json @@ -54,8 +54,8 @@ ], "payment_status": { "awaiting_payment": true, - "payment_required_by": "2020-01-17T10:42:14.545Z", - "price_guarantee_expires_at": "2020-01-17T10:42:14.545Z" + "payment_required_by": "2020-01-17T10:42:14Z", + "price_guarantee_expires_at": "2020-01-17T10:42:14Z" }, "services": [ {