Skip to content

Commit 489b443

Browse files
authored
Merge pull request #41 from EasyPost/insurance
add insurance object
2 parents 18cf2ff + 8ea4051 commit 489b443

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

easypost/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def convert_to_easypost_object(response, api_key, parent=None, name=None):
6666
'CustomsInfo': CustomsInfo,
6767
'Parcel': Parcel,
6868
'Shipment': Shipment,
69+
'Insurance': Insurance,
6970
'Rate': Rate,
7071
'Refund': Refund,
7172
'Batch': Batch,
@@ -87,6 +88,7 @@ def convert_to_easypost_object(response, api_key, parent=None, name=None):
8788
'cstinfo': CustomsInfo,
8889
'prcl': Parcel,
8990
'shp': Shipment,
91+
'ins': Insurance,
9092
'rate': Rate,
9193
'rfnd': Refund,
9294
'batch': Batch,
@@ -642,6 +644,8 @@ def verify(self, carrier=None):
642644
class ScanForm(AllResource, CreateResource):
643645
pass
644646

647+
class Insurance(AllResource, CreateResource):
648+
pass
645649

646650
class CustomsItem(AllResource, CreateResource):
647651
pass

tests/insurance.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Unit tests related to 'Shipments' (https://www.easypost.com/docs/api#shipments).
2+
3+
import unittest
4+
import easypost
5+
from constants import API_KEY as api_key
6+
7+
easypost.api_key = api_key
8+
9+
10+
class InsuranceTests(unittest.TestCase):
11+
12+
def test_insurance_creation(self):
13+
# We create an insurance and assert on values saved.
14+
tracking_code = "EZ2000000002"
15+
carrier = "USPS"
16+
amount = 101.00
17+
18+
to_address = {
19+
"name": "Dr. Steve Brule",
20+
"street1": "179 N Harbor Dr",
21+
"city": "Redondo Beach",
22+
"state": "CA",
23+
"zip": "90277",
24+
"phone": "310-808-5243"
25+
}
26+
27+
from_address = {
28+
"company": "EasyPost",
29+
"street1": "118 2nd St",
30+
"street2": "4th Fl",
31+
"city": "San Francisco",
32+
"state": "CA",
33+
"zip": "94105",
34+
"phone": "415-456-7890"
35+
}
36+
37+
# create insurance
38+
insurance = easypost.Insurance.create(
39+
to_address=to_address,
40+
from_address=from_address,
41+
tracking_code=tracking_code,
42+
carrier=carrier,
43+
amount=amount
44+
)
45+
46+
# Assertions that create worked as expected
47+
assert isinstance(insurance.to_address, easypost.Address)
48+
assert isinstance(insurance.from_address, easypost.Address)
49+
assert insurance.tracking_code == tracking_code
50+
assert insurance.amount == "101.00000"
51+
assert isinstance(insurance.tracker, easypost.Tracker)
52+
53+
insurance2 = easypost.Insurance.retrieve(insurance.id)
54+
55+
# Assertions that retrieve worked as expected
56+
assert insurance2.id == insurance.id
57+
assert isinstance(insurance2.to_address, easypost.Address)
58+
assert isinstance(insurance2.from_address, easypost.Address)
59+
assert insurance2.tracking_code == tracking_code
60+
assert insurance2.amount == "101.00000"
61+
assert isinstance(insurance2.tracker, easypost.Tracker)
62+
63+
insurances = easypost.Insurance.all(page_size=5)
64+
65+
# Assertions that index worked as expected
66+
assert len(insurances["insurances"]) == 5
67+
assert insurances["has_more"]

0 commit comments

Comments
 (0)