From 2b4851059c00890b24d6d9d24d3f0df720e4b0c9 Mon Sep 17 00:00:00 2001 From: jchen293 Date: Mon, 16 Dec 2024 17:04:47 -0500 Subject: [PATCH] add update params --- CHANGELOG.md | 5 +- easypost/services/base_service.py | 1 + easypost/services/carrier_account_service.py | 2 +- ...arrier_account_update_amazon_shipping.yaml | 77 ++++++++++--------- tests/test_carrier_account.py | 14 ++-- 5 files changed, 54 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adfccc76..d48b6378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,13 @@ # CHANGELOG +## Next Release + +- Routes `AmazonShippingAccount` create/update requests to the new `/register_oauth` endpoint + ## v9.5.0 (2024-10-24) - Adds `tracking_codes` as a parameter of the `all` method on the TrackerService - Removes the deprecated `create_list` tracker endpoint function as it is no longer available via API -- Routes `AmazonShippingAccount` create/update requests to the new `/register_oauth` endpoint ## v9.4.1 (2024-08-09) diff --git a/easypost/services/base_service.py b/easypost/services/base_service.py index dfd93b26..b9499d06 100644 --- a/easypost/services/base_service.py +++ b/easypost/services/base_service.py @@ -77,6 +77,7 @@ def _update_resource( """Update an EasyPost object via the EasyPost API.""" url = self._instance_url(class_name, id) wrapped_params = {self._snakecase_name(class_name): params} + response = Requestor(self._client).request(method=method, url=url, params=wrapped_params, beta=beta) return convert_to_easypost_object(response=response) diff --git a/easypost/services/carrier_account_service.py b/easypost/services/carrier_account_service.py index a2790257..720dd747 100644 --- a/easypost/services/carrier_account_service.py +++ b/easypost/services/carrier_account_service.py @@ -63,7 +63,7 @@ def update(self, id: str, **params) -> CarrierAccount: response = Requestor(self._client).request( method=RequestMethod.PATCH, url=f"/carrier_accounts/register_oauth/{id}", - params={}, + params={"carrier_account_oauth_registrations": params}, ) return convert_to_easypost_object(response=response) else: diff --git a/tests/cassettes/test_carrier_account_update_amazon_shipping.yaml b/tests/cassettes/test_carrier_account_update_amazon_shipping.yaml index 60d54ae6..f7ba2959 100644 --- a/tests/cassettes/test_carrier_account_update_amazon_shipping.yaml +++ b/tests/cassettes/test_carrier_account_update_amazon_shipping.yaml @@ -20,16 +20,16 @@ interactions: uri: https://api.easypost.com/v2/carrier_accounts/register_oauth response: body: - string: '{"id": "ca_102f186f791648b692501b0c6b8971a4", "object": "CarrierAccount", - "type": "AmazonShippingAccount", "clone": false, "created_at": "2024-10-21T21:55:03Z", - "updated_at": "2024-10-21T21:55:03Z", "description": null, "reference": null, + string: '{"id": "ca_e875ee2e98ac4c0c8d1d8f5b43aac959", "object": "CarrierAccount", + "type": "AmazonShippingAccount", "clone": false, "created_at": "2024-12-16T22:02:20Z", + "updated_at": "2024-12-16T22:02:20Z", "description": null, "reference": null, "billing_type": "carrier", "readable": "Amazon Shipping", "logo": null, "fields": [], "credentials": {}, "test_credentials": {}}' headers: cache-control: - private, no-cache, no-store content-length: - - '1432' + - '1420' content-type: - application/json; charset=utf-8 expires: @@ -49,20 +49,20 @@ interactions: x-download-options: - noopen x-ep-request-uuid: - - 6c7e76b86716cdb7e7874d4300480c14 + - ead55e6f6760a36ce786c93e005b6c1f x-frame-options: - SAMEORIGIN x-node: - - bigweb42nuq + - bigweb35nuq x-permitted-cross-domain-policies: - none x-proxied: - - intlb4nuq b6e1b5034c + - intlb4nuq 51d74985a2 - extlb2nuq 99aac35317 x-runtime: - - '0.080434' + - '0.081789' x-version-label: - - easypost-202410212124-540267707a-master + - easypost-202412120021-b747238cc5-master x-xss-protection: - 1; mode=block status: @@ -82,19 +82,19 @@ interactions: user-agent: - method: GET - uri: https://api.easypost.com/v2/carrier_accounts/ca_102f186f791648b692501b0c6b8971a4 + uri: https://api.easypost.com/v2/carrier_accounts/ca_e875ee2e98ac4c0c8d1d8f5b43aac959 response: body: - string: '{"id": "ca_102f186f791648b692501b0c6b8971a4", "object": "CarrierAccount", - "type": "AmazonShippingAccount", "clone": false, "created_at": "2024-10-21T21:55:03Z", - "updated_at": "2024-10-21T21:55:03Z", "description": null, "reference": null, + string: '{"id": "ca_e875ee2e98ac4c0c8d1d8f5b43aac959", "object": "CarrierAccount", + "type": "AmazonShippingAccount", "clone": false, "created_at": "2024-12-16T22:02:20Z", + "updated_at": "2024-12-16T22:02:20Z", "description": null, "reference": null, "billing_type": "carrier", "readable": "Amazon Shipping", "logo": null, "fields": [], "credentials": {}, "test_credentials": {}}' headers: cache-control: - private, no-cache, no-store content-length: - - '1432' + - '1420' content-type: - application/json; charset=utf-8 expires: @@ -109,32 +109,35 @@ interactions: - chunked x-backend: - easypost + x-canary: + - direct x-content-type-options: - nosniff x-download-options: - noopen x-ep-request-uuid: - - 6c7e76b86716cdbce7874d430048118f + - ead55e6f6760a36ce786c93e005b6c7c x-frame-options: - SAMEORIGIN x-node: - - bigweb42nuq + - bigweb32nuq x-permitted-cross-domain-policies: - none x-proxied: - - intlb4nuq b6e1b5034c + - intlb4nuq 51d74985a2 - extlb2nuq 99aac35317 x-runtime: - - '0.033679' + - '0.038244' x-version-label: - - easypost-202410212124-540267707a-master + - easypost-202412120021-b747238cc5-master x-xss-protection: - 1; mode=block status: code: 200 message: OK - request: - body: '{}' + body: '{"carrier_account_oauth_registrations": {"description": "test description", + "reference": "test reference"}}' headers: Accept: - '*/*' @@ -143,7 +146,7 @@ interactions: Connection: - keep-alive Content-Length: - - '2' + - '107' Content-Type: - application/json authorization: @@ -151,19 +154,19 @@ interactions: user-agent: - method: PATCH - uri: https://api.easypost.com/v2/carrier_accounts/register_oauth/ca_102f186f791648b692501b0c6b8971a4 + uri: https://api.easypost.com/v2/carrier_accounts/register_oauth/ca_e875ee2e98ac4c0c8d1d8f5b43aac959 response: body: - string: '{"id": "ca_102f186f791648b692501b0c6b8971a4", "object": "CarrierAccount", - "type": "AmazonShippingAccount", "clone": false, "created_at": "2024-10-21T21:55:03Z", - "updated_at": "2024-10-21T21:55:08Z", "description": null, "reference": null, + string: '{"id": "ca_e875ee2e98ac4c0c8d1d8f5b43aac959", "object": "CarrierAccount", + "type": "AmazonShippingAccount", "clone": false, "created_at": "2024-12-16T22:02:20Z", + "updated_at": "2024-12-16T22:02:21Z", "description": null, "reference": null, "billing_type": "carrier", "readable": "Amazon Shipping", "logo": null, "fields": [], "credentials": {}, "test_credentials": {}}' headers: cache-control: - private, no-cache, no-store content-length: - - '1440' + - '1452' content-type: - application/json; charset=utf-8 expires: @@ -183,20 +186,20 @@ interactions: x-download-options: - noopen x-ep-request-uuid: - - 6c7e76b86716cdbce7874d43004811bd + - ead55e6f6760a36de786c93e005b6cc6 x-frame-options: - SAMEORIGIN x-node: - - bigweb36nuq + - bigweb39nuq x-permitted-cross-domain-policies: - none x-proxied: - - intlb4nuq b6e1b5034c + - intlb4nuq 51d74985a2 - extlb2nuq 99aac35317 x-runtime: - - '0.066719' + - '0.062129' x-version-label: - - easypost-202410212124-540267707a-master + - easypost-202412120021-b747238cc5-master x-xss-protection: - 1; mode=block status: @@ -218,7 +221,7 @@ interactions: user-agent: - method: DELETE - uri: https://api.easypost.com/v2/carrier_accounts/ca_102f186f791648b692501b0c6b8971a4 + uri: https://api.easypost.com/v2/carrier_accounts/ca_e875ee2e98ac4c0c8d1d8f5b43aac959 response: body: string: '{}' @@ -246,20 +249,20 @@ interactions: x-download-options: - noopen x-ep-request-uuid: - - 6c7e76b86716cdbde7874d4300481200 + - ead55e6f6760a36de786c93e005b6d26 x-frame-options: - SAMEORIGIN x-node: - - bigweb53nuq + - bigweb55nuq x-permitted-cross-domain-policies: - none x-proxied: - - intlb3nuq b6e1b5034c + - intlb4nuq 51d74985a2 - extlb2nuq 99aac35317 x-runtime: - - '0.063692' + - '0.103086' x-version-label: - - easypost-202410212124-540267707a-master + - easypost-202412120021-b747238cc5-master x-xss-protection: - 1; mode=block status: diff --git a/tests/test_carrier_account.py b/tests/test_carrier_account.py index f70db90e..ebb506be 100644 --- a/tests/test_carrier_account.py +++ b/tests/test_carrier_account.py @@ -157,21 +157,23 @@ def test_carrier_account_create_amazon_shipping(prod_client): @pytest.mark.vcr() -def test_carrier_account_update_amazon_shipping(prod_client, synchronous_sleep_seconds): +def test_carrier_account_update_amazon_shipping(prod_client): """Test updating an Amazon Shipping Carrier Account which uses a different URL and schema.""" - function_name = inspect.stack()[0][3] params = { "type": "AmazonShippingAccount", } amazon_shipping_account = prod_client.carrier_account.create(**params) - if not os.path.exists(os.path.join("tests", "cassettes", f"{function_name}.yaml")): - time.sleep(synchronous_sleep_seconds) # Wait enough time for updating the carrier account - updated_amazon_shipping_account = prod_client.carrier_account.update(amazon_shipping_account.id) + + # TODO: Re-record this cassettes and add two assertions for description and reference when we made the changes in API level for update endpoint + updated_amazon_shipping_account = prod_client.carrier_account.update( + amazon_shipping_account.id, + description="test description", + reference="test reference", + ) assert isinstance(updated_amazon_shipping_account, CarrierAccount) assert str.startswith(updated_amazon_shipping_account.id, "ca_") - assert amazon_shipping_account.updated_at != updated_amazon_shipping_account.updated_at prod_client.carrier_account.delete( amazon_shipping_account.id