11# Unit tests related to 'Shipments' (https://www.easypost.com/docs/api#shipments).
22
3+ import time
4+
35import easypost
6+ import pytest
47
58
69def test_shipment_creation ():
@@ -67,12 +70,6 @@ def test_shipment_creation():
6770 rate_id = shipment .rates [0 ].id
6871 assert rate_id is not None
6972
70- shipment .get_rates ()
71-
72- new_rate_id = shipment .rates [0 ].id
73- assert new_rate_id is not None
74- assert new_rate_id != rate_id
75-
7673 # Assert address values match
7774 assert shipment .buyer_address .country == to_address .country
7875 assert shipment .buyer_address .phone == to_address .phone
@@ -98,3 +95,78 @@ def test_shipment_creation():
9895 assert shipment .insurance == '100.00'
9996
10097 assert 'https://easypost-files.s3-us-west-2.amazonaws.com' in shipment .postage_label .label_url
98+
99+
100+ @pytest .mark .slow
101+ def test_rerate ():
102+ # We create a shipment and assert on values saved.
103+
104+ # create a to address and a from address
105+ to_address = easypost .Address .create (
106+ name = "Sawyer Bateman" ,
107+ street1 = "1A Larkspur Cres." ,
108+ street2 = "" ,
109+ city = "St. Albert" ,
110+ state = "AB" ,
111+ zip = "t8n2m4" ,
112+ country = "CA" ,
113+ phone = "780-283-9384"
114+ )
115+ from_address = easypost .Address .create (
116+ company = "EasyPost" ,
117+ street1 = "118 2nd St" ,
118+ street2 = "4th Fl" ,
119+ city = "San Francisco" ,
120+ state = "CA" ,
121+ zip = "94105" ,
122+ phone = "415-456-7890"
123+ )
124+
125+ # create a parcel
126+ parcel = easypost .Parcel .create (
127+ length = 10.2 ,
128+ width = 7.8 ,
129+ height = 4.3 ,
130+ weight = 21.2
131+ )
132+
133+ # create customs_info form for intl shipping
134+ customs_item = easypost .CustomsItem .create (
135+ description = "EasyPost t-shirts" ,
136+ hs_tariff_number = 123456 ,
137+ origin_country = "US" ,
138+ quantity = 2 ,
139+ value = 96.27 ,
140+ weight = 21.1
141+ )
142+ customs_info = easypost .CustomsInfo .create (
143+ customs_certify = 1 ,
144+ customs_signer = "Hector Hammerfall" ,
145+ contents_type = "gift" ,
146+ contents_explanation = "" ,
147+ eel_pfc = "NOEEI 30.37(a)" ,
148+ non_delivery_option = "return" ,
149+ restriction_type = "none" ,
150+ restriction_comments = "" ,
151+ customs_items = [customs_item ]
152+ )
153+
154+ # create shipment
155+ shipment = easypost .Shipment .create (
156+ to_address = to_address ,
157+ from_address = from_address ,
158+ parcel = parcel ,
159+ customs_info = customs_info
160+ )
161+
162+ rate_id = shipment .rates [0 ].id
163+ assert rate_id is not None
164+
165+ # we only rerate on get_rates calls for shipments made at least 60 seconds ago
166+ time .sleep (61 )
167+
168+ shipment .get_rates ()
169+
170+ new_rate_id = shipment .rates [0 ].id
171+ assert new_rate_id is not None
172+ assert new_rate_id != rate_id
0 commit comments