|
| 1 | +# Unit tests related to 'ScanForms' (https://www.easypost.com/docs/api.html#manifesting-scan-form). |
| 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 ScanFormTests(unittest.TestCase): |
| 11 | + |
| 12 | + def test_scan_form_create_and_retrieve(self): |
| 13 | + # prepare params for shipment |
| 14 | + to_address = { |
| 15 | + "name": "Sawyer Bateman", |
| 16 | + "street1": "1A Larkspur Cres.", |
| 17 | + "street2": "", |
| 18 | + "city": "St. Albert", |
| 19 | + "state": "AB", |
| 20 | + "zip": "t8n2m4", |
| 21 | + "country": "CA", |
| 22 | + "phone": "780-283-9384" |
| 23 | + } |
| 24 | + from_address = { |
| 25 | + "company": "EasyPost", |
| 26 | + "street1": "118 2nd St", |
| 27 | + "street2": "4th Fl", |
| 28 | + "city": "San Francisco", |
| 29 | + "state": "CA", |
| 30 | + "zip": "94105", |
| 31 | + "phone": "415-456-7890" |
| 32 | + } |
| 33 | + parcel = { |
| 34 | + "length": 10.2, |
| 35 | + "width": 7.8, |
| 36 | + "height": 4.3, |
| 37 | + "weight": 21.2 |
| 38 | + } |
| 39 | + customs_item = { |
| 40 | + "description": "EasyPost t-shirts", |
| 41 | + "hs_tariff_number": 123456, |
| 42 | + "origin_country": "US", |
| 43 | + "quantity": 2, |
| 44 | + "value": 96.27, |
| 45 | + "weight": 21.1 |
| 46 | + } |
| 47 | + customs_info = { |
| 48 | + "customs_certify": 1, |
| 49 | + "customs_signer": "Hector Hammerfall", |
| 50 | + "contents_type": "gift", |
| 51 | + "contents_explanation": "", |
| 52 | + "eel_pfc": "NOEEI 30.37(a)", |
| 53 | + "non_delivery_option": "return", |
| 54 | + "restriction_type": "none", |
| 55 | + "restriction_comments": "", |
| 56 | + "customs_items": [customs_item] |
| 57 | + } |
| 58 | + |
| 59 | + # create shipment and buy |
| 60 | + shipment = easypost.Shipment.create( |
| 61 | + to_address=to_address, |
| 62 | + from_address=from_address, |
| 63 | + parcel=parcel, |
| 64 | + customs_info=customs_info |
| 65 | + ) |
| 66 | + shipment.buy(rate=shipment.lowest_rate(['USPS', 'ups'], 'priorityMAILInternational'), insurance=100.00) |
| 67 | + |
| 68 | + # create scan form |
| 69 | + scan_form = easypost.ScanForm.create( |
| 70 | + shipments=[shipment] |
| 71 | + ) |
| 72 | + |
| 73 | + # Assert values match |
| 74 | + assert scan_form.id is not None |
| 75 | + assert scan_form.tracking_codes[0] == shipment.tracking_code |
| 76 | + |
| 77 | + # retrieve a copy of the scan form |
| 78 | + scan_form2 = easypost.ScanForm.retrieve(scan_form.id) |
| 79 | + |
| 80 | + # Assert values match |
| 81 | + assert scan_form2.id == scan_form.id |
| 82 | + |
| 83 | + # index scan_forms |
| 84 | + scan_forms = easypost.ScanForm.all(page_size=2) |
| 85 | + |
| 86 | + # Assert values match |
| 87 | + assert scan_forms["scan_forms"][0].id == scan_form.id |
0 commit comments