Skip to content

Commit bebed27

Browse files
author
Jake Epstein
committed
fixed Report classing issue and resolved some linter problems
1 parent 34e75e5 commit bebed27

File tree

3 files changed

+70
-17
lines changed

3 files changed

+70
-17
lines changed

easypost/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def convert_to_easypost_object(response, api_key, parent=None, name=None):
7979
'CarrierAccount': CarrierAccount,
8080
'User': User,
8181
'Report': Report,
82+
'ShipmentReport': Report,
83+
'PaymentLogReport': Report,
84+
'TrackerReport': Report
8285
}
8386

8487
prefixes = {
@@ -99,7 +102,10 @@ def convert_to_easypost_object(response, api_key, parent=None, name=None):
99102
'pickuprate': PickupRate,
100103
'pl': PostageLabel,
101104
'ca': CarrierAccount,
102-
'user': User
105+
'user': User,
106+
'shprep': Report,
107+
'plrep': Report,
108+
'trkrep': Report
103109
}
104110

105111
if isinstance(response, list):
@@ -645,9 +651,11 @@ def verify(self, carrier=None):
645651
class ScanForm(AllResource, CreateResource):
646652
pass
647653

654+
648655
class Insurance(AllResource, CreateResource):
649656
pass
650657

658+
651659
class CustomsItem(AllResource, CreateResource):
652660
pass
653661

@@ -903,9 +911,10 @@ def api_keys(self):
903911

904912
return my_api_keys
905913

914+
906915
class Report(AllResource, CreateResource):
907916

908-
REPORT_TYPES = { 'shprep': 'shipment', 'plrep': 'payment_log', 'trkrep': 'tracker' }
917+
REPORT_TYPES = {'shprep': 'shipment', 'plrep': 'payment_log', 'trkrep': 'tracker'}
909918

910919
@classmethod
911920
def create(cls, api_key=None, **params):

examples/report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
report = easypost.Report.create(
55
start_date="2012-12-01",
6-
end_date= "2013-01-01",
6+
end_date="2013-01-01",
77
type="shipment"
88
)
99
print(report.id)
@@ -14,7 +14,7 @@
1414

1515
report2 = easypost.Report.create(
1616
start_date="2013-12-02",
17-
end_date= "2014-01-01",
17+
end_date="2014-01-01",
1818
type="shipment"
1919
)
2020

tests/report.py

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,65 @@
44

55
easypost.api_key = api_key
66

7+
78
class ReportTests(unittest.TestCase):
89

9-
def test_report(self):
10-
report = easypost.Report.create(
11-
start_date="2012-12-01",
12-
end_date="2013-01-01",
13-
type="shipment"
14-
)
10+
def test_shipment_report(self):
11+
report = easypost.Report.create(
12+
start_date="2012-12-01",
13+
end_date="2013-01-01",
14+
type="shipment"
15+
)
16+
17+
assert report.object == "ShipmentReport"
18+
assert report.status == "available"
19+
assert report.__class__ == easypost.Report
20+
21+
report2 = easypost.Report.retrieve(report.id, api_key=api_key)
22+
23+
assert report2.__class__ == easypost.Report
24+
assert report2.id == report.id
25+
26+
reports = easypost.Report.all(api_key=api_key, type="shipment")
27+
assert len(reports["reports"])
28+
assert reports["reports"][0].id == report.id == report2.id
29+
30+
def test_payment_log_report(self):
31+
report = easypost.Report.create(
32+
start_date="2012-12-01",
33+
end_date="2013-01-01",
34+
type="payment_log"
35+
)
36+
37+
assert report.object == "PaymentLogReport"
38+
assert report.status == "available"
39+
assert report.__class__ == easypost.Report
40+
41+
report2 = easypost.Report.retrieve(report.id, api_key=api_key)
42+
43+
assert report2.__class__ == easypost.Report
44+
assert report2.id == report.id
45+
46+
reports = easypost.Report.all(api_key=api_key, type="payment_log")
47+
assert len(reports["reports"])
48+
assert reports["reports"][0].id == report.id == report2.id
49+
50+
def test_tracker_report(self):
51+
report = easypost.Report.create(
52+
start_date="2012-12-01",
53+
end_date="2013-01-01",
54+
type="tracker"
55+
)
56+
57+
assert report.object == "TrackerReport"
58+
# assert report.status == "available" # Not yet implemented for tracker reports
59+
assert report.__class__ == easypost.Report
1560

16-
assert report.object == "ShipmentReport"
17-
assert report.status == "available"
61+
report2 = easypost.Report.retrieve(report.id, api_key=api_key)
1862

19-
report2 = easypost.Report.retrieve(report.id, api_key=api_key)
20-
assert report2.id == report.id
63+
assert report2.__class__ == easypost.Report
64+
assert report2.id == report.id
2165

22-
reports = easypost.Report.all(api_key=api_key, type = "shipment")
23-
assert len(reports["reports"])
24-
assert reports["reports"][0].id == report.id == report2.id
66+
reports = easypost.Report.all(api_key=api_key, type="tracker")
67+
assert len(reports["reports"])
68+
assert reports["reports"][0].id == report.id == report2.id

0 commit comments

Comments
 (0)