Skip to content

Commit f7f6cf8

Browse files
committed
fixed ScanForm create and added tests
1 parent 4264acb commit f7f6cf8

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed

CHANGELOG

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
=== 3.5.1 2017-01-19
2+
3+
* Fixed create for ScanForms
4+
5+
16
=== 3.5.0 2017-01-18
27

38
* Added basic CRUD methods for Webhook Objects

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.5.0
1+
3.5.1

easypost/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,12 @@ def verify(self, carrier=None):
659659

660660

661661
class ScanForm(AllResource, CreateResource):
662-
pass
662+
@classmethod
663+
def create(cls, api_key=None, **params):
664+
requestor = Requestor(api_key)
665+
url = cls.class_url()
666+
response, api_key = requestor.request('post', url, params)
667+
return convert_to_easypost_object(response, api_key)
663668

664669

665670
class Insurance(AllResource, CreateResource):

easypost/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '3.5.0'
1+
VERSION = '3.5.1'

tests/scan_form.py

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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

Comments
 (0)