From c16aeb10d90fc1caba80790b8ce10cc77cf599e4 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Mon, 30 Nov 2026 09:21:08 -0700 Subject: [PATCH 1/3] fix: keep report and tracker filters when paginating --- CHANGELOG.md | 5 +++++ easypost/services/report_service.py | 4 ++++ easypost/services/tracker_service.py | 3 +++ tests/test_report.py | 19 +++++++++++++++++++ tests/test_tracker.py | 16 ++++++++++++++++ 5 files changed, 47 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66bada2f..fc569d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## Next Release + +- Fixes `report.get_next_page` dropping the `start_datetime` and `end_datetime` 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` diff --git a/easypost/services/report_service.py b/easypost/services/report_service.py index ac2c2182..31f257e1 100644 --- a/easypost/services/report_service.py +++ b/easypost/services/report_service.py @@ -41,6 +41,8 @@ def all(self, **params) -> dict[str, Any]: filters = { "key": "reports", "type": params.get("type", None), + "start_datetime": params.get("start_datetime"), + "end_datetime": params.get("end_datetime"), } report_type = params.pop("type") @@ -72,6 +74,8 @@ def get_next_page( "before_id": reports["reports"][-1].id, "page_size": page_size, "type": reports.get(_FILTERS_KEY, {}).get("type"), # Use the same type as the last page + "start_datetime": reports.get(_FILTERS_KEY, {}).get("start_datetime"), + "end_datetime": reports.get(_FILTERS_KEY, {}).get("end_datetime"), } if optional_params: diff --git a/easypost/services/tracker_service.py b/easypost/services/tracker_service.py index eed418d0..b51e4f90 100644 --- a/easypost/services/tracker_service.py +++ b/easypost/services/tracker_service.py @@ -57,6 +57,9 @@ 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 } diff --git a/tests/test_report.py b/tests/test_report.py index cda07a2b..65e15d21 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -1,3 +1,5 @@ +from unittest.mock import patch + import pytest from easypost.constant import ( @@ -94,3 +96,20 @@ def test_report_get_next_page(report_type, page_size, test_client): except Exception as e: if e.message != NO_MORE_PAGES_ERROR: raise Exception(_TEST_FAILED_INTENTIONALLY_ERROR) + + +@pytest.mark.vcr() # Cassette not needed due to mocking, but used to avoid making real bogus API calls +def test_report_get_next_page_keeps_date_filters(test_client): + first_page_response = {"reports": [{"id": "shprep_123"}], "has_more": True} + + with patch("easypost.requestor.Requestor.request", return_value=first_page_response): + first_page = test_client.report.all( + type="shipment", start_datetime="2026-01-01", end_datetime="2026-01-31", page_size=1 + ) + + with patch("easypost.requestor.Requestor.request", return_value=first_page_response) as mock_request: + test_client.report.get_next_page(reports=first_page, page_size=1) + + params = mock_request.call_args.kwargs["params"] + assert params["start_datetime"] == "2026-01-01" + assert params["end_datetime"] == "2026-01-31" diff --git a/tests/test_tracker.py b/tests/test_tracker.py index f57468a7..a924fcd1 100644 --- a/tests/test_tracker.py +++ b/tests/test_tracker.py @@ -1,3 +1,5 @@ +from unittest.mock import patch + import pytest from easypost.constant import ( @@ -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"] From c10404c76161e2052515327d27fc0a20015ae694 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Mon, 30 Nov 2026 09:31:08 -0700 Subject: [PATCH 2/3] fix: keep date filters when paginating other list results --- CHANGELOG.md | 2 +- easypost/services/address_service.py | 5 +++++ easypost/services/claim_service.py | 5 +++++ easypost/services/event_service.py | 5 +++++ easypost/services/insurance_service.py | 5 +++++ easypost/services/pickup_service.py | 5 +++++ easypost/services/referral_customer_service.py | 4 ++++ easypost/services/refund_service.py | 5 +++++ easypost/services/scan_form_service.py | 5 +++++ easypost/services/shipment_service.py | 4 ++++ easypost/services/tracker_service.py | 4 ++++ easypost/services/user_service.py | 11 +++++++++++ 12 files changed, 59 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc569d15..06cf17e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Next Release -- Fixes `report.get_next_page` dropping the `start_datetime` and `end_datetime` filters of the original `all` call +- Fixes `get_next_page` (addresses, claims, events, insurances, pickups, referral customers, refunds, reports, scan forms, shipments and trackers) and `get_next_page_of_children` dropping the `start_datetime` and `end_datetime` filters of the original list call - Fixes `tracker.get_next_page` dropping the `tracking_codes` filter of the original `all` call ## v10.9.0 (2026-11-09) diff --git a/easypost/services/address_service.py b/easypost/services/address_service.py index bea69baa..3f3837dd 100644 --- a/easypost/services/address_service.py +++ b/easypost/services/address_service.py @@ -3,6 +3,7 @@ Optional, ) +from easypost.constant import _FILTERS_KEY from easypost.easypost_object import convert_to_easypost_object from easypost.models import Address from easypost.requestor import ( @@ -43,6 +44,8 @@ def all(self, **params) -> dict[str, Any]: """Retrieve a list of Addresses.""" filters = { "key": "addresses", + "start_datetime": params.get("start_datetime"), + "end_datetime": params.get("end_datetime"), } return self._all_resources(self._model_class, filters, **params) @@ -83,6 +86,8 @@ def get_next_page( params = { "before_id": addresses["addresses"][-1].id, "page_size": page_size, + "start_datetime": addresses.get(_FILTERS_KEY, {}).get("start_datetime"), + "end_datetime": addresses.get(_FILTERS_KEY, {}).get("end_datetime"), } if optional_params: diff --git a/easypost/services/claim_service.py b/easypost/services/claim_service.py index c7925b04..f1806985 100644 --- a/easypost/services/claim_service.py +++ b/easypost/services/claim_service.py @@ -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 ( @@ -29,6 +30,8 @@ def all(self, **params) -> dict[str, Any]: """Retrieve a list of Claims.""" filters = { "key": "claims", + "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) @@ -49,6 +52,8 @@ def get_next_page( params = { "before_id": claims["claims"][-1].id, "page_size": page_size, + "start_datetime": claims.get(_FILTERS_KEY, {}).get("start_datetime"), + "end_datetime": claims.get(_FILTERS_KEY, {}).get("end_datetime"), } if optional_params: diff --git a/easypost/services/event_service.py b/easypost/services/event_service.py index 8d0aad3f..0e62d168 100644 --- a/easypost/services/event_service.py +++ b/easypost/services/event_service.py @@ -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, @@ -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) @@ -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: diff --git a/easypost/services/insurance_service.py b/easypost/services/insurance_service.py index c60ea30f..22026a9a 100644 --- a/easypost/services/insurance_service.py +++ b/easypost/services/insurance_service.py @@ -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 ( @@ -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) @@ -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: diff --git a/easypost/services/pickup_service.py b/easypost/services/pickup_service.py index b38291ca..a11afce6 100644 --- a/easypost/services/pickup_service.py +++ b/easypost/services/pickup_service.py @@ -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 ( @@ -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) @@ -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: diff --git a/easypost/services/referral_customer_service.py b/easypost/services/referral_customer_service.py index 236715ba..12556799 100644 --- a/easypost/services/referral_customer_service.py +++ b/easypost/services/referral_customer_service.py @@ -61,6 +61,8 @@ def all(self, **params) -> dict[str, Any]: """ filters = { "key": "referral_customers", + "start_datetime": params.get("start_datetime"), + "end_datetime": params.get("end_datetime"), } url = "/referral_customers" @@ -83,6 +85,8 @@ def get_next_page( params = { "before_id": referral_customers["referral_customers"][-1].id, "page_size": page_size, + "start_datetime": referral_customers.get(_FILTERS_KEY, {}).get("start_datetime"), + "end_datetime": referral_customers.get(_FILTERS_KEY, {}).get("end_datetime"), } if optional_params: diff --git a/easypost/services/refund_service.py b/easypost/services/refund_service.py index e9f2fee5..884c9ba6 100644 --- a/easypost/services/refund_service.py +++ b/easypost/services/refund_service.py @@ -3,6 +3,7 @@ Optional, ) +from easypost.constant import _FILTERS_KEY from easypost.models import Refund from easypost.services.base_service import BaseService @@ -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) @@ -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: diff --git a/easypost/services/scan_form_service.py b/easypost/services/scan_form_service.py index fe5590a5..50c2f39e 100644 --- a/easypost/services/scan_form_service.py +++ b/easypost/services/scan_form_service.py @@ -3,6 +3,7 @@ Optional, ) +from easypost.constant import _FILTERS_KEY from easypost.models import ScanForm from easypost.services.base_service import BaseService @@ -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) @@ -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: diff --git a/easypost/services/shipment_service.py b/easypost/services/shipment_service.py index 91a622db..1a46c810 100644 --- a/easypost/services/shipment_service.py +++ b/easypost/services/shipment_service.py @@ -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) @@ -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: diff --git a/easypost/services/tracker_service.py b/easypost/services/tracker_service.py index b51e4f90..67c21f37 100644 --- a/easypost/services/tracker_service.py +++ b/easypost/services/tracker_service.py @@ -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"): @@ -61,6 +63,8 @@ def get_next_page( "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: diff --git a/easypost/services/user_service.py b/easypost/services/user_service.py index dfeea029..2a5c48ee 100644 --- a/easypost/services/user_service.py +++ b/easypost/services/user_service.py @@ -3,6 +3,7 @@ Optional, ) +from easypost.constant import _FILTERS_KEY from easypost.easypost_object import convert_to_easypost_object from easypost.models import User from easypost.requestor import ( @@ -75,6 +76,12 @@ def update_brand(self, id: str, **params) -> User: def all_children(self, **params) -> dict[str, Any]: """Retrieve a paginated list of children from the API.""" + filters = { + "key": "children", + "start_datetime": params.get("start_datetime"), + "end_datetime": params.get("end_datetime"), + } + url = "/users/children" response = Requestor(self._client).request( method=RequestMethod.GET, @@ -82,6 +89,8 @@ def all_children(self, **params) -> dict[str, Any]: params=params, ) + response[_FILTERS_KEY] = filters # Save the filters used to reference in potential get_next_page call + return convert_to_easypost_object(response=response) def get_next_page_of_children( @@ -96,6 +105,8 @@ def get_next_page_of_children( params = { "after_id": children["children"][-1].id, "page_size": page_size, + "start_datetime": children.get(_FILTERS_KEY, {}).get("start_datetime"), + "end_datetime": children.get(_FILTERS_KEY, {}).get("end_datetime"), } if optional_params: From 0924ce9ce3df65c98d4d4d4ab87f3e399e8d2227 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Mon, 30 Nov 2026 09:46:18 -0700 Subject: [PATCH 3/3] fix: only keep filters the API applies on next pages --- CHANGELOG.md | 3 ++- easypost/services/address_service.py | 5 ----- easypost/services/claim_service.py | 4 ++++ .../services/referral_customer_service.py | 4 ---- easypost/services/report_service.py | 4 ---- easypost/services/user_service.py | 11 ----------- tests/test_claim.py | 17 +++++++++++++++++ tests/test_report.py | 19 ------------------- 8 files changed, 23 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06cf17e2..296038b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## Next Release -- Fixes `get_next_page` (addresses, claims, events, insurances, pickups, referral customers, refunds, reports, scan forms, shipments and trackers) and `get_next_page_of_children` dropping the `start_datetime` and `end_datetime` filters of the original list call +- 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) diff --git a/easypost/services/address_service.py b/easypost/services/address_service.py index 3f3837dd..bea69baa 100644 --- a/easypost/services/address_service.py +++ b/easypost/services/address_service.py @@ -3,7 +3,6 @@ Optional, ) -from easypost.constant import _FILTERS_KEY from easypost.easypost_object import convert_to_easypost_object from easypost.models import Address from easypost.requestor import ( @@ -44,8 +43,6 @@ def all(self, **params) -> dict[str, Any]: """Retrieve a list of Addresses.""" filters = { "key": "addresses", - "start_datetime": params.get("start_datetime"), - "end_datetime": params.get("end_datetime"), } return self._all_resources(self._model_class, filters, **params) @@ -86,8 +83,6 @@ def get_next_page( params = { "before_id": addresses["addresses"][-1].id, "page_size": page_size, - "start_datetime": addresses.get(_FILTERS_KEY, {}).get("start_datetime"), - "end_datetime": addresses.get(_FILTERS_KEY, {}).get("end_datetime"), } if optional_params: diff --git a/easypost/services/claim_service.py b/easypost/services/claim_service.py index f1806985..2666090a 100644 --- a/easypost/services/claim_service.py +++ b/easypost/services/claim_service.py @@ -30,6 +30,8 @@ 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"), } @@ -52,6 +54,8 @@ 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"), } diff --git a/easypost/services/referral_customer_service.py b/easypost/services/referral_customer_service.py index 12556799..236715ba 100644 --- a/easypost/services/referral_customer_service.py +++ b/easypost/services/referral_customer_service.py @@ -61,8 +61,6 @@ def all(self, **params) -> dict[str, Any]: """ filters = { "key": "referral_customers", - "start_datetime": params.get("start_datetime"), - "end_datetime": params.get("end_datetime"), } url = "/referral_customers" @@ -85,8 +83,6 @@ def get_next_page( params = { "before_id": referral_customers["referral_customers"][-1].id, "page_size": page_size, - "start_datetime": referral_customers.get(_FILTERS_KEY, {}).get("start_datetime"), - "end_datetime": referral_customers.get(_FILTERS_KEY, {}).get("end_datetime"), } if optional_params: diff --git a/easypost/services/report_service.py b/easypost/services/report_service.py index 31f257e1..ac2c2182 100644 --- a/easypost/services/report_service.py +++ b/easypost/services/report_service.py @@ -41,8 +41,6 @@ def all(self, **params) -> dict[str, Any]: filters = { "key": "reports", "type": params.get("type", None), - "start_datetime": params.get("start_datetime"), - "end_datetime": params.get("end_datetime"), } report_type = params.pop("type") @@ -74,8 +72,6 @@ def get_next_page( "before_id": reports["reports"][-1].id, "page_size": page_size, "type": reports.get(_FILTERS_KEY, {}).get("type"), # Use the same type as the last page - "start_datetime": reports.get(_FILTERS_KEY, {}).get("start_datetime"), - "end_datetime": reports.get(_FILTERS_KEY, {}).get("end_datetime"), } if optional_params: diff --git a/easypost/services/user_service.py b/easypost/services/user_service.py index 2a5c48ee..dfeea029 100644 --- a/easypost/services/user_service.py +++ b/easypost/services/user_service.py @@ -3,7 +3,6 @@ Optional, ) -from easypost.constant import _FILTERS_KEY from easypost.easypost_object import convert_to_easypost_object from easypost.models import User from easypost.requestor import ( @@ -76,12 +75,6 @@ def update_brand(self, id: str, **params) -> User: def all_children(self, **params) -> dict[str, Any]: """Retrieve a paginated list of children from the API.""" - filters = { - "key": "children", - "start_datetime": params.get("start_datetime"), - "end_datetime": params.get("end_datetime"), - } - url = "/users/children" response = Requestor(self._client).request( method=RequestMethod.GET, @@ -89,8 +82,6 @@ def all_children(self, **params) -> dict[str, Any]: params=params, ) - response[_FILTERS_KEY] = filters # Save the filters used to reference in potential get_next_page call - return convert_to_easypost_object(response=response) def get_next_page_of_children( @@ -105,8 +96,6 @@ def get_next_page_of_children( params = { "after_id": children["children"][-1].id, "page_size": page_size, - "start_datetime": children.get(_FILTERS_KEY, {}).get("start_datetime"), - "end_datetime": children.get(_FILTERS_KEY, {}).get("end_datetime"), } if optional_params: diff --git a/tests/test_claim.py b/tests/test_claim.py index 7f474901..1ff7199e 100644 --- a/tests/test_claim.py +++ b/tests/test_claim.py @@ -1,3 +1,5 @@ +from unittest.mock import patch + import pytest from easypost.constant import ( @@ -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" diff --git a/tests/test_report.py b/tests/test_report.py index 65e15d21..cda07a2b 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -1,5 +1,3 @@ -from unittest.mock import patch - import pytest from easypost.constant import ( @@ -96,20 +94,3 @@ def test_report_get_next_page(report_type, page_size, test_client): except Exception as e: if e.message != NO_MORE_PAGES_ERROR: raise Exception(_TEST_FAILED_INTENTIONALLY_ERROR) - - -@pytest.mark.vcr() # Cassette not needed due to mocking, but used to avoid making real bogus API calls -def test_report_get_next_page_keeps_date_filters(test_client): - first_page_response = {"reports": [{"id": "shprep_123"}], "has_more": True} - - with patch("easypost.requestor.Requestor.request", return_value=first_page_response): - first_page = test_client.report.all( - type="shipment", start_datetime="2026-01-01", end_datetime="2026-01-31", page_size=1 - ) - - with patch("easypost.requestor.Requestor.request", return_value=first_page_response) as mock_request: - test_client.report.get_next_page(reports=first_page, page_size=1) - - params = mock_request.call_args.kwargs["params"] - assert params["start_datetime"] == "2026-01-01" - assert params["end_datetime"] == "2026-01-31"