Skip to content

Commit

Permalink
fixed Report classing issue and resolved some linter problems
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryftw committed Dec 15, 2016
1 parent 34e75e5 commit bebed27
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 17 deletions.
13 changes: 11 additions & 2 deletions easypost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def convert_to_easypost_object(response, api_key, parent=None, name=None):
'CarrierAccount': CarrierAccount,
'User': User,
'Report': Report,
'ShipmentReport': Report,
'PaymentLogReport': Report,
'TrackerReport': Report
}

prefixes = {
Expand All @@ -99,7 +102,10 @@ def convert_to_easypost_object(response, api_key, parent=None, name=None):
'pickuprate': PickupRate,
'pl': PostageLabel,
'ca': CarrierAccount,
'user': User
'user': User,
'shprep': Report,
'plrep': Report,
'trkrep': Report
}

if isinstance(response, list):
Expand Down Expand Up @@ -645,9 +651,11 @@ def verify(self, carrier=None):
class ScanForm(AllResource, CreateResource):
pass


class Insurance(AllResource, CreateResource):
pass


class CustomsItem(AllResource, CreateResource):
pass

Expand Down Expand Up @@ -903,9 +911,10 @@ def api_keys(self):

return my_api_keys


class Report(AllResource, CreateResource):

REPORT_TYPES = { 'shprep': 'shipment', 'plrep': 'payment_log', 'trkrep': 'tracker' }
REPORT_TYPES = {'shprep': 'shipment', 'plrep': 'payment_log', 'trkrep': 'tracker'}

@classmethod
def create(cls, api_key=None, **params):
Expand Down
4 changes: 2 additions & 2 deletions examples/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

report = easypost.Report.create(
start_date="2012-12-01",
end_date= "2013-01-01",
end_date="2013-01-01",
type="shipment"
)
print(report.id)
Expand All @@ -14,7 +14,7 @@

report2 = easypost.Report.create(
start_date="2013-12-02",
end_date= "2014-01-01",
end_date="2014-01-01",
type="shipment"
)

Expand Down
70 changes: 57 additions & 13 deletions tests/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,65 @@

easypost.api_key = api_key


class ReportTests(unittest.TestCase):

def test_report(self):
report = easypost.Report.create(
start_date="2012-12-01",
end_date="2013-01-01",
type="shipment"
)
def test_shipment_report(self):
report = easypost.Report.create(
start_date="2012-12-01",
end_date="2013-01-01",
type="shipment"
)

assert report.object == "ShipmentReport"
assert report.status == "available"
assert report.__class__ == easypost.Report

report2 = easypost.Report.retrieve(report.id, api_key=api_key)

assert report2.__class__ == easypost.Report
assert report2.id == report.id

reports = easypost.Report.all(api_key=api_key, type="shipment")
assert len(reports["reports"])
assert reports["reports"][0].id == report.id == report2.id

def test_payment_log_report(self):
report = easypost.Report.create(
start_date="2012-12-01",
end_date="2013-01-01",
type="payment_log"
)

assert report.object == "PaymentLogReport"
assert report.status == "available"
assert report.__class__ == easypost.Report

report2 = easypost.Report.retrieve(report.id, api_key=api_key)

assert report2.__class__ == easypost.Report
assert report2.id == report.id

reports = easypost.Report.all(api_key=api_key, type="payment_log")
assert len(reports["reports"])
assert reports["reports"][0].id == report.id == report2.id

def test_tracker_report(self):
report = easypost.Report.create(
start_date="2012-12-01",
end_date="2013-01-01",
type="tracker"
)

assert report.object == "TrackerReport"
# assert report.status == "available" # Not yet implemented for tracker reports
assert report.__class__ == easypost.Report

assert report.object == "ShipmentReport"
assert report.status == "available"
report2 = easypost.Report.retrieve(report.id, api_key=api_key)

report2 = easypost.Report.retrieve(report.id, api_key=api_key)
assert report2.id == report.id
assert report2.__class__ == easypost.Report
assert report2.id == report.id

reports = easypost.Report.all(api_key=api_key, type = "shipment")
assert len(reports["reports"])
assert reports["reports"][0].id == report.id == report2.id
reports = easypost.Report.all(api_key=api_key, type="tracker")
assert len(reports["reports"])
assert reports["reports"][0].id == report.id == report2.id

0 comments on commit bebed27

Please sign in to comment.