From 04cfeb956a5585222e8f9258e228f6aa6f4092f8 Mon Sep 17 00:00:00 2001 From: jchen293 Date: Tue, 22 Oct 2024 13:07:30 -0400 Subject: [PATCH 1/4] Add Amazon shipping endpoint --- CHANGELOG.md | 1 + easypost/constant.py | 3 + easypost/services/base_service.py | 1 - easypost/services/carrier_account_service.py | 12 + ...arrier_account_create_amazon_shipping.yaml | 137 +++++++++ ...arrier_account_update_amazon_shipping.yaml | 268 ++++++++++++++++++ tests/test_carrier_account.py | 45 +++ 7 files changed, 466 insertions(+), 1 deletion(-) create mode 100644 tests/cassettes/test_carrier_account_create_amazon_shipping.yaml create mode 100644 tests/cassettes/test_carrier_account_update_amazon_shipping.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index e3681187..8e6a8068 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - 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/constant.py b/easypost/constant.py index 9659e779..066a239a 100644 --- a/easypost/constant.py +++ b/easypost/constant.py @@ -36,6 +36,9 @@ "FedexAccount", "FedexSmartpostAccount", ] +_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = [ + "AmazonShippingAccount", +] _UPS_OAUTH_CARRIER_ACCOUNT_TYPES = [ "UpsAccount", "UpsMailInnovationsAccount", diff --git a/easypost/services/base_service.py b/easypost/services/base_service.py index cb6b5d76..f3476c01 100644 --- a/easypost/services/base_service.py +++ b/easypost/services/base_service.py @@ -85,7 +85,6 @@ 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 56258a9f..f585e16c 100644 --- a/easypost/services/carrier_account_service.py +++ b/easypost/services/carrier_account_service.py @@ -4,6 +4,7 @@ ) from easypost.constant import ( + _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH, _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS, _UPS_OAUTH_CARRIER_ACCOUNT_TYPES, MISSING_PARAMETER_ERROR, @@ -33,6 +34,8 @@ def create(self, **params) -> CarrierAccount: url = self._select_carrier_account_creation_endpoint(carrier_account_type=carrier_account_type) if carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES: wrapped_params = {"ups_oauth_registrations": params} + elif carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH: + wrapped_params = {"carrier_account_oauth_registrations": params} else: wrapped_params = {self._snakecase_name(self._model_class): params} @@ -54,6 +57,13 @@ def update(self, id: str, **params) -> CarrierAccount: if carrier_account.get("type") in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES: class_name = "UpsOauthRegistrations" + elif carrier_account.get("type") in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH: + response = Requestor(self._client).request( + method=RequestMethod.PATCH, + url=f"/carrier_accounts/register_oauth/{id}", + params={}, + ) + return convert_to_easypost_object(response=response) else: class_name = self._model_class @@ -75,5 +85,7 @@ def _select_carrier_account_creation_endpoint(self, carrier_account_type: Option return "/carrier_accounts/register" elif carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES: return "/ups_oauth_registrations" + elif carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH: + return "/carrier_accounts/register_oauth" return "/carrier_accounts" diff --git a/tests/cassettes/test_carrier_account_create_amazon_shipping.yaml b/tests/cassettes/test_carrier_account_create_amazon_shipping.yaml new file mode 100644 index 00000000..3a3ca1e6 --- /dev/null +++ b/tests/cassettes/test_carrier_account_create_amazon_shipping.yaml @@ -0,0 +1,137 @@ +interactions: +- request: + body: '{"carrier_account_oauth_registrations": {"type": "AmazonShippingAccount", + "selling_partner_id": 123456, "description": "Test Amazon Shipping Account", + "reference": "Test reference id"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '185' + Content-Type: + - application/json + authorization: + - + user-agent: + - + method: POST + uri: https://api.easypost.com/v2/carrier_accounts/register_oauth + response: + body: + string: '{"id": "ca_42645bd4efec44d19990311923247889", "object": "CarrierAccount", + "type": "AmazonShippingAccount", "clone": false, "created_at": "2024-10-21T17:29:15Z", + "updated_at": "2024-10-21T17:29:15Z", "description": "Test Amazon Shipping + Account", "reference": "Test reference id", "billing_type": "carrier", "readable": + "Amazon Shipping", "logo": null, "fields": [], "credentials": {}, "test_credentials": + {}}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1477' + 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: + - 5b98ae6c67168f6be786a35a006ad145 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb36nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq b6e1b5034c + - extlb1nuq 99aac35317 + x-runtime: + - '0.111175' + x-version-label: + - easypost-202410211500-2da9256a8e-master + x-xss-protection: + - 1; mode=block + status: + code: 201 + message: Created +- 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/carrier_accounts/ca_42645bd4efec44d19990311923247889 + response: + body: + string: '{}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '2' + 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: + - 5b98ae6c67168f6be786a35a006ad17a + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb36nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb3nuq b6e1b5034c + - extlb1nuq 99aac35317 + x-runtime: + - '0.061416' + x-version-label: + - easypost-202410211500-2da9256a8e-master + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +version: 1 diff --git a/tests/cassettes/test_carrier_account_update_amazon_shipping.yaml b/tests/cassettes/test_carrier_account_update_amazon_shipping.yaml new file mode 100644 index 00000000..60d54ae6 --- /dev/null +++ b/tests/cassettes/test_carrier_account_update_amazon_shipping.yaml @@ -0,0 +1,268 @@ +interactions: +- request: + body: '{"carrier_account_oauth_registrations": {"type": "AmazonShippingAccount"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '74' + Content-Type: + - application/json + authorization: + - + user-agent: + - + method: POST + 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, + "billing_type": "carrier", "readable": "Amazon Shipping", "logo": null, "fields": + [], "credentials": {}, "test_credentials": {}}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1432' + 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: + - 6c7e76b86716cdb7e7874d4300480c14 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb42nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq b6e1b5034c + - extlb2nuq 99aac35317 + x-runtime: + - '0.080434' + x-version-label: + - easypost-202410212124-540267707a-master + x-xss-protection: + - 1; mode=block + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + authorization: + - + user-agent: + - + method: GET + uri: https://api.easypost.com/v2/carrier_accounts/ca_102f186f791648b692501b0c6b8971a4 + 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, + "billing_type": "carrier", "readable": "Amazon Shipping", "logo": null, "fields": + [], "credentials": {}, "test_credentials": {}}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1432' + 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: + - 6c7e76b86716cdbce7874d430048118f + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb42nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq b6e1b5034c + - extlb2nuq 99aac35317 + x-runtime: + - '0.033679' + x-version-label: + - easypost-202410212124-540267707a-master + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +- request: + body: '{}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '2' + Content-Type: + - application/json + authorization: + - + user-agent: + - + method: PATCH + uri: https://api.easypost.com/v2/carrier_accounts/register_oauth/ca_102f186f791648b692501b0c6b8971a4 + 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, + "billing_type": "carrier", "readable": "Amazon Shipping", "logo": null, "fields": + [], "credentials": {}, "test_credentials": {}}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1440' + 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: + - 6c7e76b86716cdbce7874d43004811bd + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb36nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq b6e1b5034c + - extlb2nuq 99aac35317 + x-runtime: + - '0.066719' + x-version-label: + - easypost-202410212124-540267707a-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/carrier_accounts/ca_102f186f791648b692501b0c6b8971a4 + response: + body: + string: '{}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '2' + 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: + - 6c7e76b86716cdbde7874d4300481200 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb53nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb3nuq b6e1b5034c + - extlb2nuq 99aac35317 + x-runtime: + - '0.063692' + x-version-label: + - easypost-202410212124-540267707a-master + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_carrier_account.py b/tests/test_carrier_account.py index 72e1a698..f70db90e 100644 --- a/tests/test_carrier_account.py +++ b/tests/test_carrier_account.py @@ -1,3 +1,7 @@ +import inspect +import os +import time + import pytest from easypost.errors.api.api_error import ApiError from easypost.models import CarrierAccount @@ -131,3 +135,44 @@ def test_carrier_account_update_ups(prod_client): prod_client.carrier_account.delete( updated_carrier_account.id ) # Delete the carrier account once it's done being tested. + + +@pytest.mark.vcr() +def test_carrier_account_create_amazon_shipping(prod_client): + """Test registering an Amazon Shipping Carrier Account which uses a different URL and schema.""" + params = { + "type": "AmazonShippingAccount", + "selling_partner_id": 123456, + "description": "Test Amazon Shipping Account", + "reference": "Test reference id", + } + + carrier_account = prod_client.carrier_account.create(**params) + + assert isinstance(carrier_account, CarrierAccount) + assert str.startswith(carrier_account.id, "ca_") + assert carrier_account.type == "AmazonShippingAccount" + + prod_client.carrier_account.delete(carrier_account.id) # Delete the carrier account once it's done being tested. + + +@pytest.mark.vcr() +def test_carrier_account_update_amazon_shipping(prod_client, synchronous_sleep_seconds): + """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) + + 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 + ) # Delete the carrier account once it's done being tested. From e9ffa691930f37c5bda7053dd78c904973fa0a47 Mon Sep 17 00:00:00 2001 From: jchen293 Date: Mon, 16 Dec 2024 17:04:47 -0500 Subject: [PATCH 2/4] add update params --- CHANGELOG.md | 2 +- 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, 51 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e6a8068..a71ac9bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - `BetaReferralCustomerService.create_bank_account_client_secret` - `ReferralCustomerService.add_credit_card_from_stripe` - `ReferralCustomerService.add_bank_account_from_stripe` +- Routes `AmazonShippingAccount` create requests to the new `/register_oauth` endpoint - Fixes the payload wrapping for updating a webhook - Removes deprecated `user.all_api_keys` and `user.api_keys`, use `api_key.all` and `api_key.retrieve_api_keys_for_user` respectively - Bumps all dev dependencies @@ -16,7 +17,6 @@ - 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 f3476c01..cb6b5d76 100644 --- a/easypost/services/base_service.py +++ b/easypost/services/base_service.py @@ -85,6 +85,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 f585e16c..ab4daf8b 100644 --- a/easypost/services/carrier_account_service.py +++ b/easypost/services/carrier_account_service.py @@ -61,7 +61,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 From 64f546c07d8b85efe3dd65891d0335363f4d8443 Mon Sep 17 00:00:00 2001 From: jchen293 Date: Tue, 17 Dec 2024 11:59:48 -0500 Subject: [PATCH 3/4] fix lint --- tests/test_carrier_account.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/test_carrier_account.py b/tests/test_carrier_account.py index ebb506be..a7e73d89 100644 --- a/tests/test_carrier_account.py +++ b/tests/test_carrier_account.py @@ -1,7 +1,3 @@ -import inspect -import os -import time - import pytest from easypost.errors.api.api_error import ApiError from easypost.models import CarrierAccount @@ -165,7 +161,8 @@ def test_carrier_account_update_amazon_shipping(prod_client): amazon_shipping_account = prod_client.carrier_account.create(**params) - # TODO: Re-record this cassettes and add two assertions for description and reference when we made the changes in API level for update endpoint + # 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", From 861290d18b5d00a8b819fe92e8d7b4fb1b8edc5c Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Fri, 11 Apr 2025 10:01:20 -0600 Subject: [PATCH 4/4] fix: create/update based on changes --- easypost/services/carrier_account_service.py | 7 - ...arrier_account_create_amazon_shipping.yaml | 41 ++- ...arrier_account_update_amazon_shipping.yaml | 271 ------------------ tests/test_carrier_account.py | 28 -- 4 files changed, 19 insertions(+), 328 deletions(-) delete mode 100644 tests/cassettes/test_carrier_account_update_amazon_shipping.yaml diff --git a/easypost/services/carrier_account_service.py b/easypost/services/carrier_account_service.py index ab4daf8b..5708b35c 100644 --- a/easypost/services/carrier_account_service.py +++ b/easypost/services/carrier_account_service.py @@ -57,13 +57,6 @@ def update(self, id: str, **params) -> CarrierAccount: if carrier_account.get("type") in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES: class_name = "UpsOauthRegistrations" - elif carrier_account.get("type") in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH: - response = Requestor(self._client).request( - method=RequestMethod.PATCH, - url=f"/carrier_accounts/register_oauth/{id}", - params={"carrier_account_oauth_registrations": params}, - ) - return convert_to_easypost_object(response=response) else: class_name = self._model_class diff --git a/tests/cassettes/test_carrier_account_create_amazon_shipping.yaml b/tests/cassettes/test_carrier_account_create_amazon_shipping.yaml index 3a3ca1e6..eae66012 100644 --- a/tests/cassettes/test_carrier_account_create_amazon_shipping.yaml +++ b/tests/cassettes/test_carrier_account_create_amazon_shipping.yaml @@ -1,8 +1,6 @@ interactions: - request: - body: '{"carrier_account_oauth_registrations": {"type": "AmazonShippingAccount", - "selling_partner_id": 123456, "description": "Test Amazon Shipping Account", - "reference": "Test reference id"}}' + body: '{"carrier_account_oauth_registrations": {"type": "AmazonShippingAccount"}}' headers: Accept: - '*/*' @@ -11,7 +9,7 @@ interactions: Connection: - keep-alive Content-Length: - - '185' + - '74' Content-Type: - application/json authorization: @@ -22,17 +20,16 @@ interactions: uri: https://api.easypost.com/v2/carrier_accounts/register_oauth response: body: - string: '{"id": "ca_42645bd4efec44d19990311923247889", "object": "CarrierAccount", - "type": "AmazonShippingAccount", "clone": false, "created_at": "2024-10-21T17:29:15Z", - "updated_at": "2024-10-21T17:29:15Z", "description": "Test Amazon Shipping - Account", "reference": "Test reference id", "billing_type": "carrier", "readable": - "Amazon Shipping", "logo": null, "fields": [], "credentials": {}, "test_credentials": - {}}' + string: '{"id": "ca_18bfc1a27cc349cfbf219cf0e754f917", "object": "CarrierAccount", + "type": "AmazonShippingAccount", "clone": false, "created_at": "2025-04-10T19:12:34Z", + "updated_at": "2025-04-10T19:12:34Z", "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: - - '1477' + - '1448' content-type: - application/json; charset=utf-8 expires: @@ -52,20 +49,20 @@ interactions: x-download-options: - noopen x-ep-request-uuid: - - 5b98ae6c67168f6be786a35a006ad145 + - 028443c067f81822e2bbac9c00135101 x-frame-options: - SAMEORIGIN x-node: - - bigweb36nuq + - bigweb54nuq x-permitted-cross-domain-policies: - none x-proxied: - - intlb4nuq b6e1b5034c + - intlb3nuq 284c5d344a - extlb1nuq 99aac35317 x-runtime: - - '0.111175' + - '0.225842' x-version-label: - - easypost-202410211500-2da9256a8e-master + - easypost-202504101604-e81adf64e4-master x-xss-protection: - 1; mode=block status: @@ -87,7 +84,7 @@ interactions: user-agent: - method: DELETE - uri: https://api.easypost.com/v2/carrier_accounts/ca_42645bd4efec44d19990311923247889 + uri: https://api.easypost.com/v2/carrier_accounts/ca_18bfc1a27cc349cfbf219cf0e754f917 response: body: string: '{}' @@ -115,20 +112,20 @@ interactions: x-download-options: - noopen x-ep-request-uuid: - - 5b98ae6c67168f6be786a35a006ad17a + - 028443c067f81822e2bbac9c00135164 x-frame-options: - SAMEORIGIN x-node: - - bigweb36nuq + - bigweb35nuq x-permitted-cross-domain-policies: - none x-proxied: - - intlb3nuq b6e1b5034c + - intlb4nuq 284c5d344a - extlb1nuq 99aac35317 x-runtime: - - '0.061416' + - '0.056642' x-version-label: - - easypost-202410211500-2da9256a8e-master + - easypost-202504101604-e81adf64e4-master x-xss-protection: - 1; mode=block status: diff --git a/tests/cassettes/test_carrier_account_update_amazon_shipping.yaml b/tests/cassettes/test_carrier_account_update_amazon_shipping.yaml deleted file mode 100644 index f7ba2959..00000000 --- a/tests/cassettes/test_carrier_account_update_amazon_shipping.yaml +++ /dev/null @@ -1,271 +0,0 @@ -interactions: -- request: - body: '{"carrier_account_oauth_registrations": {"type": "AmazonShippingAccount"}}' - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Content-Length: - - '74' - Content-Type: - - application/json - authorization: - - - user-agent: - - - method: POST - uri: https://api.easypost.com/v2/carrier_accounts/register_oauth - response: - body: - 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: - - '1420' - 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: - - ead55e6f6760a36ce786c93e005b6c1f - x-frame-options: - - SAMEORIGIN - x-node: - - bigweb35nuq - x-permitted-cross-domain-policies: - - none - x-proxied: - - intlb4nuq 51d74985a2 - - extlb2nuq 99aac35317 - x-runtime: - - '0.081789' - x-version-label: - - easypost-202412120021-b747238cc5-master - x-xss-protection: - - 1; mode=block - status: - code: 201 - message: Created -- request: - body: null - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - authorization: - - - user-agent: - - - method: GET - uri: https://api.easypost.com/v2/carrier_accounts/ca_e875ee2e98ac4c0c8d1d8f5b43aac959 - response: - body: - 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: - - '1420' - 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-canary: - - direct - x-content-type-options: - - nosniff - x-download-options: - - noopen - x-ep-request-uuid: - - ead55e6f6760a36ce786c93e005b6c7c - x-frame-options: - - SAMEORIGIN - x-node: - - bigweb32nuq - x-permitted-cross-domain-policies: - - none - x-proxied: - - intlb4nuq 51d74985a2 - - extlb2nuq 99aac35317 - x-runtime: - - '0.038244' - x-version-label: - - easypost-202412120021-b747238cc5-master - x-xss-protection: - - 1; mode=block - status: - code: 200 - message: OK -- request: - body: '{"carrier_account_oauth_registrations": {"description": "test description", - "reference": "test reference"}}' - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Content-Length: - - '107' - Content-Type: - - application/json - authorization: - - - user-agent: - - - method: PATCH - uri: https://api.easypost.com/v2/carrier_accounts/register_oauth/ca_e875ee2e98ac4c0c8d1d8f5b43aac959 - response: - body: - 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: - - '1452' - 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: - - ead55e6f6760a36de786c93e005b6cc6 - x-frame-options: - - SAMEORIGIN - x-node: - - bigweb39nuq - x-permitted-cross-domain-policies: - - none - x-proxied: - - intlb4nuq 51d74985a2 - - extlb2nuq 99aac35317 - x-runtime: - - '0.062129' - x-version-label: - - easypost-202412120021-b747238cc5-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/carrier_accounts/ca_e875ee2e98ac4c0c8d1d8f5b43aac959 - response: - body: - string: '{}' - headers: - cache-control: - - private, no-cache, no-store - content-length: - - '2' - 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: - - ead55e6f6760a36de786c93e005b6d26 - x-frame-options: - - SAMEORIGIN - x-node: - - bigweb55nuq - x-permitted-cross-domain-policies: - - none - x-proxied: - - intlb4nuq 51d74985a2 - - extlb2nuq 99aac35317 - x-runtime: - - '0.103086' - x-version-label: - - easypost-202412120021-b747238cc5-master - x-xss-protection: - - 1; mode=block - status: - code: 200 - message: OK -version: 1 diff --git a/tests/test_carrier_account.py b/tests/test_carrier_account.py index a7e73d89..57554394 100644 --- a/tests/test_carrier_account.py +++ b/tests/test_carrier_account.py @@ -138,9 +138,6 @@ def test_carrier_account_create_amazon_shipping(prod_client): """Test registering an Amazon Shipping Carrier Account which uses a different URL and schema.""" params = { "type": "AmazonShippingAccount", - "selling_partner_id": 123456, - "description": "Test Amazon Shipping Account", - "reference": "Test reference id", } carrier_account = prod_client.carrier_account.create(**params) @@ -150,28 +147,3 @@ def test_carrier_account_create_amazon_shipping(prod_client): assert carrier_account.type == "AmazonShippingAccount" prod_client.carrier_account.delete(carrier_account.id) # Delete the carrier account once it's done being tested. - - -@pytest.mark.vcr() -def test_carrier_account_update_amazon_shipping(prod_client): - """Test updating an Amazon Shipping Carrier Account which uses a different URL and schema.""" - params = { - "type": "AmazonShippingAccount", - } - - amazon_shipping_account = prod_client.carrier_account.create(**params) - - # 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_") - - prod_client.carrier_account.delete( - amazon_shipping_account.id - ) # Delete the carrier account once it's done being tested.