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