From c6eaa64099cacd0e6e76810d0b19460afb550a8c Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Tue, 3 Feb 2026 11:48:41 -0700 Subject: [PATCH] feat: delete tracker --- CHANGELOG.md | 1 + easypost/services/tracker_service.py | 14 +-- tests/cassettes/test_tracker_delete.yaml | 153 +++++++++++++++++++++++ tests/test_tracker.py | 8 ++ 4 files changed, 168 insertions(+), 8 deletions(-) create mode 100644 tests/cassettes/test_tracker_delete.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 118a7b9..4069025 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - `api_key.delete` - `api_key.enable` - `api_key.disable` +- Adds a `tracker.delete` function ## v10.3.0 (2025-11-24) diff --git a/easypost/services/tracker_service.py b/easypost/services/tracker_service.py index 734f835..eed418d 100644 --- a/easypost/services/tracker_service.py +++ b/easypost/services/tracker_service.py @@ -1,15 +1,9 @@ -from typing import ( - Any, - Optional, -) +from typing import Any, Optional from easypost.constant import _FILTERS_KEY from easypost.easypost_object import convert_to_easypost_object from easypost.models import Tracker -from easypost.requestor import ( - RequestMethod, - Requestor, -) +from easypost.requestor import RequestMethod, Requestor from easypost.services.base_service import BaseService @@ -70,3 +64,7 @@ def get_next_page( params.update(optional_params) return self.all(**params) + + def delete(self, id: str) -> None: + """Delete a Tracker.""" + self._delete_resource(self._model_class, id) diff --git a/tests/cassettes/test_tracker_delete.yaml b/tests/cassettes/test_tracker_delete.yaml new file mode 100644 index 0000000..115b4cd --- /dev/null +++ b/tests/cassettes/test_tracker_delete.yaml @@ -0,0 +1,153 @@ +interactions: +- request: + body: '{"tracker": {"tracking_code": "EZ1000000001"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '46' + Content-Type: + - application/json + authorization: + - + user-agent: + - + method: POST + uri: https://api.easypost.com/v2/trackers + response: + body: + string: '{"id": "trk_52d78046d6a14e8b92af8b8546080a05", "object": "Tracker", + "mode": "test", "tracking_code": "EZ1000000001", "status": "pre_transit", + "status_detail": "status_update", "created_at": "2025-11-05T21:59:07Z", "updated_at": + "2025-11-05T21:59:07Z", "signed_by": null, "weight": null, "est_delivery_date": + "2025-11-05T21:59:07Z", "shipment_id": null, "carrier": "USPS", "tracking_details": + [{"object": "TrackingDetail", "message": "Pre-Shipment Info Sent to USPS", + "description": "", "status": "pre_transit", "status_detail": "status_update", + "datetime": "2025-10-05T21:59:07Z", "source": "USPS", "carrier_code": "", + "tracking_location": {"object": "TrackingLocation", "city": null, "state": + null, "country": null, "zip": null}, "est_delivery_date": null}, {"object": + "TrackingDetail", "message": "Shipping Label Created", "description": "", + "status": "pre_transit", "status_detail": "status_update", "datetime": "2025-10-06T10:36:07Z", + "source": "USPS", "carrier_code": "", "tracking_location": {"object": "TrackingLocation", + "city": "HOUSTON", "state": "TX", "country": null, "zip": "77063"}, "est_delivery_date": + null}], "carrier_detail": {"object": "CarrierDetail", "service": "First-Class + Package Service", "container_type": null, "est_delivery_date_local": null, + "est_delivery_time_local": null, "origin_location": "HOUSTON TX, 77001", "origin_tracking_location": + {"object": "TrackingLocation", "city": "HOUSTON", "state": "TX", "country": + null, "zip": "77063"}, "destination_location": "CHARLESTON SC, 29401", "destination_tracking_location": + null, "guaranteed_delivery_date": null, "alternate_identifier": null, "initial_delivery_attempt": + null}, "delivery_evidence": [], "finalized": true, "is_return": false, "public_url": + "https://track.easypost.com/djE6dHJrXzUyZDc4MDQ2ZDZhMTRlOGI5MmFmOGI4NTQ2MDgwYTA1"}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1691' + content-type: + - application/json; charset=utf-8 + expires: + - '0' + location: + - /api/v2/trackers/trk_52d78046d6a14e8b92af8b8546080a05 + pragma: + - no-cache + referrer-policy: + - strict-origin-when-cross-origin + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-backend: + - easypost + x-content-type-options: + - nosniff + x-download-options: + - noopen + x-ep-request-uuid: + - 7dd2312e69824159e788f74f0032e696 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb33nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq 5f0235a1ab + - extlb2nuq cbbd141214 + x-runtime: + - '0.063693' + x-version-label: + - easypost-202602022215-5a5c93c546-master + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + authorization: + - + user-agent: + - + method: DELETE + uri: https://api.easypost.com/v2/trackers/trk_52d78046d6a14e8b92af8b8546080a05 + response: + body: + string: '{"success": true}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '16' + content-type: + - application/json; charset=utf-8 + expires: + - '0' + pragma: + - no-cache + referrer-policy: + - strict-origin-when-cross-origin + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-backend: + - easypost + x-content-type-options: + - nosniff + x-download-options: + - noopen + x-ep-request-uuid: + - 7dd231306982415ae788f7500032e6fe + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb53nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq 5f0235a1ab + - extlb2nuq cbbd141214 + x-runtime: + - '0.041496' + x-version-label: + - easypost-202602022215-5a5c93c546-master + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_tracker.py b/tests/test_tracker.py index 2554feb..f57468a 100644 --- a/tests/test_tracker.py +++ b/tests/test_tracker.py @@ -66,3 +66,11 @@ def test_tracker_get_next_page(page_size, test_client): except Exception as e: if e.message != NO_MORE_PAGES_ERROR: raise Exception(_TEST_FAILED_INTENTIONALLY_ERROR) + + +@pytest.mark.vcr() +def test_tracker_delete(test_client): + tracker = test_client.tracker.create(tracking_code="EZ1000000001") + + # Nothing gets returned here, simply ensure no error gets raised + test_client.tracker.delete(tracker.id)