Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Next Release

- Fixes `get_next_page` (claims, events, insurances, pickups, refunds, scan forms, shipments and trackers) dropping the `start_datetime` and `end_datetime` filters of the original `all` call
- Fixes `claim.get_next_page` dropping the `type` and `status` filters of the original `all` call
- Fixes `tracker.get_next_page` dropping the `tracking_codes` filter of the original `all` call

## v10.9.0 (2026-11-09)

- Removes the legacy Google App Engine `urlfetch` transport; all requests now use `requests`
Expand Down
9 changes: 9 additions & 0 deletions easypost/services/claim_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Optional,
)

from easypost.constant import _FILTERS_KEY
from easypost.easypost_object import convert_to_easypost_object
from easypost.models import Claim
from easypost.requestor import (
Expand All @@ -29,6 +30,10 @@ def all(self, **params) -> dict[str, Any]:
"""Retrieve a list of Claims."""
filters = {
"key": "claims",
"type": params.get("type"),
"status": params.get("status"),
"start_datetime": params.get("start_datetime"),
"end_datetime": params.get("end_datetime"),
}

return self._all_resources(class_name=self._model_class, filters=filters, beta=False, **params)
Expand All @@ -49,6 +54,10 @@ def get_next_page(
params = {
"before_id": claims["claims"][-1].id,
"page_size": page_size,
"type": claims.get(_FILTERS_KEY, {}).get("type"),
"status": claims.get(_FILTERS_KEY, {}).get("status"),
"start_datetime": claims.get(_FILTERS_KEY, {}).get("start_datetime"),
"end_datetime": claims.get(_FILTERS_KEY, {}).get("end_datetime"),
}

if optional_params:
Expand Down
5 changes: 5 additions & 0 deletions easypost/services/event_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Optional,
)

from easypost.constant import _FILTERS_KEY
from easypost.easypost_object import convert_to_easypost_object
from easypost.models import (
Event,
Expand All @@ -28,6 +29,8 @@ def all(self, **params) -> dict[str, Any]:
"""Retrieve a list of Events."""
filters = {
"key": "events",
"start_datetime": params.get("start_datetime"),
"end_datetime": params.get("end_datetime"),
}

return self._all_resources(self._model_class, filters, **params)
Expand Down Expand Up @@ -64,6 +67,8 @@ def get_next_page(
params = {
"before_id": events["events"][-1].id,
"page_size": page_size,
"start_datetime": events.get(_FILTERS_KEY, {}).get("start_datetime"),
"end_datetime": events.get(_FILTERS_KEY, {}).get("end_datetime"),
}

if optional_params:
Expand Down
5 changes: 5 additions & 0 deletions easypost/services/insurance_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Optional,
)

from easypost.constant import _FILTERS_KEY
from easypost.easypost_object import convert_to_easypost_object
from easypost.models import Insurance
from easypost.requestor import (
Expand All @@ -25,6 +26,8 @@ def all(self, **params) -> dict[str, Any]:
"""Retrieve a list of Insurances."""
filters = {
"key": "insurances",
"start_datetime": params.get("start_datetime"),
"end_datetime": params.get("end_datetime"),
}

return self._all_resources(self._model_class, filters, **params)
Expand All @@ -45,6 +48,8 @@ def get_next_page(
params = {
"before_id": insurances["insurances"][-1].id,
"page_size": page_size,
"start_datetime": insurances.get(_FILTERS_KEY, {}).get("start_datetime"),
"end_datetime": insurances.get(_FILTERS_KEY, {}).get("end_datetime"),
}

if optional_params:
Expand Down
5 changes: 5 additions & 0 deletions easypost/services/pickup_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Optional,
)

from easypost.constant import _FILTERS_KEY
from easypost.easypost_object import convert_to_easypost_object
from easypost.models import Pickup
from easypost.requestor import (
Expand All @@ -25,6 +26,8 @@ def all(self, **params) -> dict[str, Any]:
"""Retrieve a list of Pickups."""
filters = {
"key": "pickups",
"start_datetime": params.get("start_datetime"),
"end_datetime": params.get("end_datetime"),
}

return self._all_resources(self._model_class, filters, **params)
Expand All @@ -45,6 +48,8 @@ def get_next_page(
params = {
"before_id": pickups["pickups"][-1].id,
"page_size": page_size,
"start_datetime": pickups.get(_FILTERS_KEY, {}).get("start_datetime"),
"end_datetime": pickups.get(_FILTERS_KEY, {}).get("end_datetime"),
}

if optional_params:
Expand Down
5 changes: 5 additions & 0 deletions easypost/services/refund_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Optional,
)

from easypost.constant import _FILTERS_KEY
from easypost.models import Refund
from easypost.services.base_service import BaseService

Expand All @@ -20,6 +21,8 @@ def all(self, **params) -> dict[str, Any]:
"""Retrieve a list of Shipment Refunds."""
filters = {
"key": "refunds",
"start_datetime": params.get("start_datetime"),
"end_datetime": params.get("end_datetime"),
}

return self._all_resources(self._model_class, filters, **params)
Expand All @@ -40,6 +43,8 @@ def get_next_page(
params = {
"before_id": refunds["refunds"][-1].id,
"page_size": page_size,
"start_datetime": refunds.get(_FILTERS_KEY, {}).get("start_datetime"),
"end_datetime": refunds.get(_FILTERS_KEY, {}).get("end_datetime"),
}

if optional_params:
Expand Down
5 changes: 5 additions & 0 deletions easypost/services/scan_form_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Optional,
)

from easypost.constant import _FILTERS_KEY
from easypost.models import ScanForm
from easypost.services.base_service import BaseService

Expand All @@ -20,6 +21,8 @@ def all(self, **params) -> dict[str, Any]:
"""Retrieve a list of ScanForms."""
filters = {
"key": "scan_forms",
"start_datetime": params.get("start_datetime"),
"end_datetime": params.get("end_datetime"),
}

return self._all_resources(self._model_class, filters, **params)
Expand All @@ -40,6 +43,8 @@ def get_next_page(
params = {
"before_id": scan_forms["scan_forms"][-1].id,
"page_size": page_size,
"start_datetime": scan_forms.get(_FILTERS_KEY, {}).get("start_datetime"),
"end_datetime": scan_forms.get(_FILTERS_KEY, {}).get("end_datetime"),
}

if optional_params:
Expand Down
4 changes: 4 additions & 0 deletions easypost/services/shipment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def all(self, **params) -> dict[str, Any]:
"key": "shipments",
"include_children": params.get("include_children"),
"purchased": params.get("purchased"),
"start_datetime": params.get("start_datetime"),
"end_datetime": params.get("end_datetime"),
}

return self._all_resources(self._model_class, filters, **params)
Expand All @@ -63,6 +65,8 @@ def get_next_page(
"include_children": shipments.get(_FILTERS_KEY, {}).get("include_children"),
# Use the same purchased as the last page
"purchased": shipments.get(_FILTERS_KEY, {}).get("purchased"),
"start_datetime": shipments.get(_FILTERS_KEY, {}).get("start_datetime"),
"end_datetime": shipments.get(_FILTERS_KEY, {}).get("end_datetime"),
}

if optional_params:
Expand Down
7 changes: 7 additions & 0 deletions easypost/services/tracker_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def all(self, **params) -> dict[str, Any]:
"tracking_code": params.get("tracking_code"),
"tracking_codes": params.get("tracking_codes"),
"carrier": params.get("carrier"),
"start_datetime": params.get("start_datetime"),
"end_datetime": params.get("end_datetime"),
}
# Make Ruby on Rails happy with proper URL encoding
if params.get("tracking_codes"):
Expand Down Expand Up @@ -57,7 +59,12 @@ def get_next_page(
"tracking_code": trackers.get(_FILTERS_KEY, {}).get(
"tracking_code"
), # Use the same tracking_code as the last page
"tracking_codes": trackers.get(_FILTERS_KEY, {}).get(
"tracking_codes"
), # Use the same tracking_codes as the last page
"carrier": trackers.get(_FILTERS_KEY, {}).get("carrier"), # Use the same carrier as the last page
"start_datetime": trackers.get(_FILTERS_KEY, {}).get("start_datetime"),
"end_datetime": trackers.get(_FILTERS_KEY, {}).get("end_datetime"),
}

if optional_params:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_claim.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import patch

import pytest

from easypost.constant import (
Expand Down Expand Up @@ -102,3 +104,18 @@ def test_claim_cancel(test_client, full_shipment, basic_claim):
assert isinstance(cancelled_claim, Claim)
assert str.startswith(cancelled_claim.id, "clm_")
assert cancelled_claim.status == "cancelled"


@pytest.mark.vcr() # Cassette not needed due to mocking, but used to avoid making real bogus API calls
def test_claim_get_next_page_keeps_filters(test_client):
first_page_response = {"claims": [{"id": "clm_123"}], "has_more": True}

with patch("easypost.requestor.Requestor.request", return_value=first_page_response):
first_page = test_client.claim.all(type="damage", status="submitted", page_size=1)

with patch("easypost.requestor.Requestor.request", return_value=first_page_response) as mock_request:
test_client.claim.get_next_page(claims=first_page, page_size=1)

params = mock_request.call_args.kwargs["params"]
assert params["type"] == "damage"
assert params["status"] == "submitted"
16 changes: 16 additions & 0 deletions tests/test_tracker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import patch

import pytest

from easypost.constant import (
Expand Down Expand Up @@ -74,3 +76,17 @@ def test_tracker_delete(test_client):

# Nothing gets returned here, simply ensure no error gets raised
test_client.tracker.delete(tracker.id)


@pytest.mark.vcr() # Cassette not needed due to mocking, but used to avoid making real bogus API calls
def test_tracker_get_next_page_keeps_tracking_codes(test_client):
first_page_response = {"trackers": [{"id": "trk_123"}], "has_more": True}

with patch("easypost.requestor.Requestor.request", return_value=first_page_response):
first_page = test_client.tracker.all(tracking_codes=["EZ1000000001"], page_size=1)

with patch("easypost.requestor.Requestor.request", return_value=first_page_response) as mock_request:
test_client.tracker.get_next_page(trackers=first_page, page_size=1)

params = mock_request.call_args.kwargs["params"]
assert params["tracking_codes[]"] == ["EZ1000000001"]
Loading