Skip to content

Commit 661a2a2

Browse files
committed
Merge branch 'fix-tests'
Closes #103 Reviewed by @jaredg
2 parents f05a95c + d9c9484 commit 661a2a2

File tree

4 files changed

+85
-9
lines changed

4 files changed

+85
-9
lines changed

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
markers =
3+
slow: marks tests as slow (deselect with '-m "not slow"')

requirements-tests.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pytest==3.0.6
2-
pytest-cov==2.4.0
1+
pytest==4.6.*
2+
pytest-cov==2.8.1
33
pytz

tests/test_batch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import easypost
44
from time import sleep
55

6+
67
def test_batch_create_and_buy():
78
# We create Address and Parcel objects. We then try to create a Batch containing a shipment.
89
# Finally, we assert on saved and returned data.
@@ -72,7 +73,7 @@ def test_batch_create_and_buy():
7273
assert batch.shipments[0].buyer_address.street1 == '388 Townsend St'
7374

7475
# Assert on fees
75-
assert batch.shipments[0].fees[0].amount == '0.01000'
76+
assert batch.shipments[0].fees[0].amount == '0.00000'
7677
assert batch.shipments[0].fees[1].amount == '7.68000'
7778
assert batch.shipments[0].fees[2].amount == '1.00000'
7879

tests/test_shipment.py

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Unit tests related to 'Shipments' (https://www.easypost.com/docs/api#shipments).
22

3+
import time
4+
35
import easypost
6+
import pytest
47

58

69
def 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

Comments
 (0)