11import unittest
2+ import json
23from unittest .mock import patch , ANY
34from .fixture import gateway
45
@@ -36,6 +37,44 @@ def test_parse_tracking_response(self):
3637
3738 self .assertListEqual (lib .to_dict (parsed_response ), ParsedTrackingResponse )
3839
40+ def test_status_mapping (self ):
41+ status_expectations = {
42+ "Creation" : "pending" ,
43+ "DataReceived" : "pending" ,
44+ "Pickup" : "picked_up" ,
45+ "PartiallyPickedUp" : "picked_up" ,
46+ "Transit" : "in_transit" ,
47+ "PartiallyInTransit" : "in_transit" ,
48+ "OutForDelivery" : "out_for_delivery" ,
49+ "PartiallyOutForDelivery" : "out_for_delivery" ,
50+ "Delivered" : "delivered" ,
51+ "PartiallyDelivered" : "delivered" ,
52+ "OnHold" : "on_hold" ,
53+ "Attention" : "on_hold" ,
54+ "PickupAttemptFailed" : "on_hold" ,
55+ "RefusedDelivery" : "on_hold" ,
56+ "Cancelled" : "cancelled" ,
57+ "ReturnCompleted" : "return_to_sender" ,
58+ "ReturnToSender" : "return_to_sender" ,
59+ "OutForPickup" : "ready_for_pickup" ,
60+ "SomethingUnexpected" : "unknown" ,
61+ }
62+
63+ for nationex_status , expected_karrio_status in status_expectations .items ():
64+ with self .subTest (nationex_status = nationex_status ):
65+ tracking_response = json .loads (TrackingResponse )
66+ tracking_response ["ShipmentStatus" ] = nationex_status
67+ tracking_response ["StatusHistories" ][0 ]["ShipmentStatus" ] = nationex_status
68+
69+ with patch ("karrio.mappers.nationex.proxy.lib.request" ) as mock :
70+ mock .return_value = json .dumps (tracking_response )
71+ parsed_response = (
72+ karrio .Tracking .fetch (self .TrackingRequest ).from_ (gateway ).parse ()
73+ )
74+
75+ tracking = lib .to_dict (parsed_response )[0 ][0 ]
76+ self .assertEqual (tracking ["status" ], expected_karrio_status )
77+
3978 def test_parse_error_response (self ):
4079 with patch ("karrio.mappers.nationex.proxy.lib.request" ) as mock :
4180 mock .return_value = ErrorResponse
@@ -66,6 +105,7 @@ def test_parse_error_response(self):
66105 "date" : "2019-08-24" ,
67106 "description" : "Data received" ,
68107 "location" : "St-Hubert" ,
108+ "status" : "pending" ,
69109 "time" : "14:15 PM" ,
70110 "timestamp" : "2019-08-24T14:15:22.000Z" ,
71111 }
@@ -83,7 +123,7 @@ def test_parse_error_response(self):
83123 "shipping_date" : "2021-03-30" ,
84124 },
85125 "meta" : {"accounty_number" : "165556" , "reference" : "CX4335" },
86- "status" : "in_transit " ,
126+ "status" : "pending " ,
87127 "tracking_number" : "103882774" ,
88128 }
89129 ],
0 commit comments