-
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 #338 from EasyPost/smartrate_service
feat: adds new recommend_ship_date and estimate_delivery_date functions
- Loading branch information
Showing
12 changed files
with
1,747 additions
and
137 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
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
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,38 @@ | ||
from typing import ( | ||
Any, | ||
Dict, | ||
List, | ||
) | ||
|
||
from easypost.easypost_object import convert_to_easypost_object | ||
from easypost.requestor import ( | ||
RequestMethod, | ||
Requestor, | ||
) | ||
from easypost.services.base_service import BaseService | ||
|
||
|
||
class SmartRateService(BaseService): | ||
def __init__(self, client): | ||
self._client = client | ||
self._model_class = "Smartrate" | ||
|
||
def estimate_delivery_date(self, **params) -> List[Dict[str, Any]]: | ||
"""Retrieve the estimated delivery date of each carrier-service level combination via the | ||
Smart Deliver By API, based on a specific ship date and origin-destination postal code pair. | ||
""" | ||
url = "/smartrate/deliver_by" | ||
|
||
response = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=params) | ||
|
||
return convert_to_easypost_object(response=response) | ||
|
||
def recommend_ship_date(self, **params) -> List[Dict[str, Any]]: | ||
"""Retrieve a recommended ship date for each carrier-service level combination via the | ||
Smart Deliver On API, based on a specific delivery date and origin-destination postal code pair. | ||
""" | ||
url = "/smartrate/deliver_on" | ||
|
||
response = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=params) | ||
|
||
return convert_to_easypost_object(response=response) |
792 changes: 656 additions & 136 deletions
792
tests/cassettes/test_retrieve_estimated_delivery_date.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
tests/cassettes/test_smartrate_estimate_delivery_date.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,45 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_smartrate_estimate_delivery_date( | ||
basic_shipment, | ||
ca_address_1, | ||
ca_address_2, | ||
planned_ship_date, | ||
usps, | ||
test_client, | ||
): | ||
"""Test that we retrieve SmartRates when provided a from/to zip and planned ship date.""" | ||
params = { | ||
"from_zip": ca_address_1["zip"], | ||
"to_zip": ca_address_2["zip"], | ||
"planned_ship_date": planned_ship_date, | ||
"carriers": [usps], | ||
} | ||
|
||
rates = test_client.smartrate.estimate_delivery_date(**params) | ||
|
||
assert all(entry.get("easypost_time_in_transit_data") for entry in rates["results"]) | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_smartrate_recommend_ship_date( | ||
basic_shipment, | ||
ca_address_1, | ||
ca_address_2, | ||
desired_delivery_date, | ||
usps, | ||
test_client, | ||
): | ||
"""Test that we retrieve SmartRates when provided a from/to zip and desired delivery date.""" | ||
params = { | ||
"from_zip": ca_address_1["zip"], | ||
"to_zip": ca_address_2["zip"], | ||
"desired_delivery_date": desired_delivery_date, | ||
"carriers": [usps], | ||
} | ||
|
||
rates = test_client.smartrate.recommend_ship_date(**params) | ||
|
||
assert all(entry.get("easypost_time_in_transit_data") for entry in rates["results"]) |