-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from EasyPost/reports-python
first attempt client lib python for reports
- Loading branch information
Showing
3 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import easypost | ||
easypost.api_key = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi' | ||
|
||
report = easypost.Report.create( | ||
start_date="2012-12-01", | ||
end_date="2013-01-01", | ||
type="shipment" | ||
) | ||
print(report.id) | ||
|
||
report1 = easypost.Report.retrieve(report.id) | ||
|
||
print(report1.id) | ||
|
||
report2 = easypost.Report.create( | ||
start_date="2013-12-02", | ||
end_date="2014-01-01", | ||
type="shipment" | ||
) | ||
|
||
reports3 = easypost.Report.all(type="shipment") | ||
|
||
print(reports3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import unittest | ||
import easypost | ||
from constants import API_KEY as api_key | ||
|
||
easypost.api_key = api_key | ||
|
||
|
||
class ReportTests(unittest.TestCase): | ||
|
||
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 | ||
|
||
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="tracker") | ||
assert len(reports["reports"]) | ||
assert reports["reports"][0].id == report.id == report2.id |