diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b882ae..ac03144 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## Next Release + +- Routes `UpsAccount`, `UpsMailInnovationsAccount`, and `UpsSurepostAccount` create/update requests to the new `/ups_oauth_registrations` endpoint + - Starting `2024-08-05`, UPS accounts will require a new payload to register or update. See [UPS OAuth 2.0 Update](https://support.easypost.com/hc/en-us/articles/26635027512717-UPS-OAuth-2-0-Update?utm_medium=email&_hsenc=p2ANqtz-96MmFtWICOzy9sKRbbcZSiMovZSrY3MSX1_bgY9N3f9yLVfWQdLhjAGq-SmNcOnDIS6GYhZ0OApjDBrGkKyLLMx1z6_TFOVp6-wllhEFQINrkuRuc&_hsmi=313130292&utm_content=313130292&utm_source=hs_email) for more details + ## v9.2.0 (2024-04-10) - Fix payment method funding and deletion failures due to undetermined payment method type diff --git a/easypost/constant.py b/easypost/constant.py index 0f9feb1..3d153e6 100644 --- a/easypost/constant.py +++ b/easypost/constant.py @@ -35,6 +35,11 @@ _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS = [ "FedexAccount", "FedexSmartpostAccount", +] +_UPS_OAUTH_CARRIER_ACCOUNT_TYPES = [ "UpsAccount", + "UpsMailInnovationsAccount", + "UpsSurepostAccount", ] _FILTERS_KEY = "filters" +_EXCLUDED_CLASS_NAMES = ["ups_oauth_registrations"] diff --git a/easypost/services/base_service.py b/easypost/services/base_service.py index 2e6c5c5..203aa5f 100644 --- a/easypost/services/base_service.py +++ b/easypost/services/base_service.py @@ -6,6 +6,7 @@ ) from easypost.constant import ( + _EXCLUDED_CLASS_NAMES, _FILTERS_KEY, NO_MORE_PAGES_ERROR, ) @@ -30,7 +31,9 @@ def _snakecase_name(self, class_name: str) -> str: def _class_url(self, class_name: str) -> str: """Generate a URL based on class name.""" transformed_class_name = self._snakecase_name(class_name) - if transformed_class_name[-1:] in ("s", "h"): + if transformed_class_name in _EXCLUDED_CLASS_NAMES: + return f"/{transformed_class_name}" + elif transformed_class_name[-1:] in ("s", "h"): return f"/{transformed_class_name}es" else: return f"/{transformed_class_name}s" diff --git a/easypost/services/carrier_account_service.py b/easypost/services/carrier_account_service.py index f78ab78..53d3cea 100644 --- a/easypost/services/carrier_account_service.py +++ b/easypost/services/carrier_account_service.py @@ -7,6 +7,7 @@ from easypost.constant import ( _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS, + _UPS_OAUTH_CARRIER_ACCOUNT_TYPES, MISSING_PARAMETER_ERROR, ) from easypost.easypost_object import convert_to_easypost_object @@ -32,7 +33,10 @@ def create(self, **params) -> CarrierAccount: raise MissingParameterError(MISSING_PARAMETER_ERROR.format("type")) url = self._select_carrier_account_creation_endpoint(carrier_account_type=carrier_account_type) - wrapped_params = {self._snakecase_name(self._model_class): params} + if carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES: + wrapped_params = {"ups_oauth_registrations": params} + else: + wrapped_params = {self._snakecase_name(self._model_class): params} response = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=wrapped_params) @@ -48,7 +52,14 @@ def retrieve(self, id: str) -> CarrierAccount: def update(self, id: str, **params) -> CarrierAccount: """Update a CarrierAccount.""" - return self._update_resource(self._model_class, id, **params) + carrier_account = self.retrieve(id) + + if carrier_account.get("type") in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES: + class_name = "UpsOauthRegistrations" + else: + class_name = self._model_class + + return self._update_resource(class_name, id, **params) def delete(self, id: str) -> None: """Delete a CarrierAccount.""" @@ -64,5 +75,7 @@ def _select_carrier_account_creation_endpoint(self, carrier_account_type: Option """Determines which API endpoint to use for the creation call.""" if carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS: return "/carrier_accounts/register" + elif carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES: + return "/ups_oauth_registrations" return "/carrier_accounts" diff --git a/tests/cassettes/test_carrier_account_create_ups.yaml b/tests/cassettes/test_carrier_account_create_ups.yaml new file mode 100644 index 0000000..36a389f --- /dev/null +++ b/tests/cassettes/test_carrier_account_create_ups.yaml @@ -0,0 +1,136 @@ +interactions: +- request: + body: '{"ups_oauth_registrations": {"type": "UpsAccount", "account_number": "123456789"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '82' + Content-Type: + - application/json + authorization: + - + user-agent: + - + method: POST + uri: https://api.easypost.com/v2/ups_oauth_registrations + response: + body: + string: '{"id": "ca_032bd1041a5d4418b8378bcc2a738a45", "object": "CarrierAccount", + "type": "UpsAccount", "clone": false, "created_at": "2024-07-09T17:02:56Z", + "updated_at": "2024-07-09T17:02:56Z", "description": null, "reference": null, + "billing_type": "carrier", "readable": "UPS", "logo": null, "fields": [], + "credentials": {}, "test_credentials": {}}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1392' + 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: + - 52ecff22668d6d40e2b7ddea00434ef1 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb34nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq fa152d4755 + - extlb1nuq fa152d4755 + x-runtime: + - '0.087747' + x-version-label: + - easypost-202407091438-d7c6f02f06-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_032bd1041a5d4418b8378bcc2a738a45 + 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-canary: + - direct + x-content-type-options: + - nosniff + x-download-options: + - noopen + x-ep-request-uuid: + - 52ecff22668d6d40e2b7ddea00434f1f + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb43nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb3nuq fa152d4755 + - extlb1nuq fa152d4755 + x-runtime: + - '0.208397' + x-version-label: + - easypost-202407091438-d7c6f02f06-master + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +version: 1 diff --git a/tests/cassettes/test_carrier_account_create_with_custom_workflow.yaml b/tests/cassettes/test_carrier_account_create_with_custom_workflow.yaml index 4a3567a..38a5a31 100644 --- a/tests/cassettes/test_carrier_account_create_with_custom_workflow.yaml +++ b/tests/cassettes/test_carrier_account_create_with_custom_workflow.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: '{"carrier_account": {"type": "UpsAccount", "registration_data": {}}}' + body: '{"carrier_account": {"type": "FedexAccount", "registration_data": {}}}' headers: Accept: - '*/*' @@ -9,7 +9,7 @@ interactions: Connection: - keep-alive Content-Length: - - '68' + - '70' Content-Type: - application/json authorization: @@ -21,22 +21,29 @@ interactions: response: body: string: '{"error": {"code": "UNPROCESSABLE_ENTITY", "message": "The request - was understood, but cannot be processed.", "errors": [{"field": "account_number", - "message": "must be present and a string"}, {"field": "city", "message": "must - be present and a string"}, {"field": "company", "message": "must be present - and a string"}, {"field": "country", "message": "must be present and a string"}, - {"field": "email", "message": "must be present and a string"}, {"field": "name", - "message": "must be present and a string"}, {"field": "phone", "message": - "must be present and a string"}, {"field": "postal_code", "message": "must - be present and a string"}, {"field": "state", "message": "must be present - and a string"}, {"field": "street1", "message": "must be present and a string"}, - {"field": "title", "message": "must be present and a string"}, {"field": "website", - "message": "must be present and a string"}]}}' + was understood, but cannot be processed.", "errors": [{"field": "shipping_streets", + "message": "must be present and a string"}, {"field": "shipping_city", "message": + "must be present and a string"}, {"field": "shipping_state", "message": "must + be present and a string"}, {"field": "shipping_postal_code", "message": "must + be present and a string"}, {"field": "shipping_country_code", "message": "must + be present and a string"}, {"field": "corporate_first_name", "message": "must + be present and a string"}, {"field": "corporate_last_name", "message": "must + be present and a string"}, {"field": "corporate_job_title", "message": "must + be present and a string"}, {"field": "corporate_company_name", "message": + "must be present and a string"}, {"field": "corporate_phone_number", "message": + "must be present and a string"}, {"field": "corporate_email_address", "message": + "must be present and a string"}, {"field": "corporate_streets", "message": + "must be present and a string"}, {"field": "corporate_city", "message": "must + be present and a string"}, {"field": "corporate_state", "message": "must be + present and a string"}, {"field": "corporate_postal_code", "message": "must + be present and a string"}, {"field": "corporate_country_code", "message": + "must be present and a string"}, {"field": "account_number", "message": "must + be present and a string"}]}}' headers: cache-control: - private, no-cache, no-store content-length: - - '846' + - '1347' content-type: - application/json; charset=utf-8 expires: @@ -56,21 +63,20 @@ interactions: x-download-options: - noopen x-ep-request-uuid: - - cdb1f665645ead1ce2aabe8300016878 + - cbf774926685bfece2bc38790027cf8b x-frame-options: - SAMEORIGIN x-node: - - bigweb12nuq + - bigweb39nuq x-permitted-cross-domain-policies: - none x-proxied: - - intlb1nuq a29e4ad05c - - intlb1wdc a29e4ad05c - - extlb3wdc 5ab12a3ed2 + - intlb3nuq fa152d4755 + - extlb1nuq fa152d4755 x-runtime: - - '0.033932' + - '0.042392' x-version-label: - - easypost-202305121849-b449e9bf47-master + - easypost-202407031852-b015027e75-master x-xss-protection: - 1; mode=block status: diff --git a/tests/cassettes/test_carrier_account_update.yaml b/tests/cassettes/test_carrier_account_update.yaml index 9ff6293..712b8f1 100644 --- a/tests/cassettes/test_carrier_account_update.yaml +++ b/tests/cassettes/test_carrier_account_update.yaml @@ -23,9 +23,9 @@ interactions: uri: https://api.easypost.com/v2/carrier_accounts response: body: - string: '{"id": "ca_a575738b0d994778a960c5c19e748baa", "object": "CarrierAccount", - "type": "DhlEcsAccount", "clone": false, "created_at": "2023-05-12T21:21:53Z", - "updated_at": "2023-05-12T21:21:53Z", "description": "DHL eCommerce Solutions + string: '{"id": "ca_c58170a2b708469eb2828ce150f818c5", "object": "CarrierAccount", + "type": "DhlEcsAccount", "clone": false, "created_at": "2024-07-08T20:54:18Z", + "updated_at": "2024-07-08T20:54:18Z", "description": "DHL eCommerce Solutions Account", "reference": null, "billing_type": "carrier", "readable": "DHL eCommerce Solutions", "logo": null, "fields": [], "credentials": {}, "test_credentials": {}}' @@ -36,8 +36,6 @@ interactions: - '1469' content-type: - application/json; charset=utf-8 - etag: - - W/"ae937268738bf972b34e687a182d5a17" expires: - '0' pragma: @@ -50,31 +48,100 @@ interactions: - chunked x-backend: - easypost + x-canary: + - direct x-content-type-options: - nosniff x-download-options: - noopen x-ep-request-uuid: - - fe8d870a645eadf1e2aac27e000e79d2 + - df6fc7b2668c51fae2cba07700263f54 x-frame-options: - SAMEORIGIN x-node: - - bigweb9nuq + - bigweb43nuq x-permitted-cross-domain-policies: - none x-proxied: - - intlb1nuq a29e4ad05c - - intlb2wdc a29e4ad05c - - extlb4wdc 5ab12a3ed2 + - intlb4nuq fa152d4755 + - extlb1nuq fa152d4755 x-runtime: - - '0.111611' + - '0.127030' x-version-label: - - easypost-202305122104-29dd2d738a-master + - easypost-202407081949-3228d5845b-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_c58170a2b708469eb2828ce150f818c5 + response: + body: + string: '{"id": "ca_c58170a2b708469eb2828ce150f818c5", "object": "CarrierAccount", + "type": "DhlEcsAccount", "clone": false, "created_at": "2024-07-08T20:54:18Z", + "updated_at": "2024-07-08T20:54:18Z", "description": "DHL eCommerce Solutions + Account", "reference": null, "billing_type": "carrier", "readable": "DHL eCommerce + Solutions", "logo": null, "fields": [], "credentials": {}, "test_credentials": + {}}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1469' + 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: + - df6fc7b2668c51fbe2cba07700263f78 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb32nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq fa152d4755 + - extlb1nuq fa152d4755 + x-runtime: + - '0.036536' + x-version-label: + - easypost-202407081949-3228d5845b-master + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK - request: body: '{"carrier_account": {"description": "My custom description"}}' headers: @@ -93,12 +160,12 @@ interactions: user-agent: - method: PATCH - uri: https://api.easypost.com/v2/carrier_accounts/ca_a575738b0d994778a960c5c19e748baa + uri: https://api.easypost.com/v2/carrier_accounts/ca_c58170a2b708469eb2828ce150f818c5 response: body: - string: '{"id": "ca_a575738b0d994778a960c5c19e748baa", "object": "CarrierAccount", - "type": "DhlEcsAccount", "clone": false, "created_at": "2023-05-12T21:21:53Z", - "updated_at": "2023-05-12T21:21:54Z", "description": "My custom description", + string: '{"id": "ca_c58170a2b708469eb2828ce150f818c5", "object": "CarrierAccount", + "type": "DhlEcsAccount", "clone": false, "created_at": "2024-07-08T20:54:18Z", + "updated_at": "2024-07-08T20:54:19Z", "description": "My custom description", "reference": null, "billing_type": "carrier", "readable": "DHL eCommerce Solutions", "logo": null, "fields": [], "credentials": {}, "test_credentials": {}}' headers: @@ -108,8 +175,6 @@ interactions: - '1459' content-type: - application/json; charset=utf-8 - etag: - - W/"f872eb829c218950953d19ed5a7de737" expires: - '0' pragma: @@ -127,21 +192,20 @@ interactions: x-download-options: - noopen x-ep-request-uuid: - - fe8d870a645eadf1e2aac27e000e79f4 + - df6fc7b2668c51fbe2cba07700263f8d x-frame-options: - SAMEORIGIN x-node: - - bigweb5nuq + - bigweb39nuq x-permitted-cross-domain-policies: - none x-proxied: - - intlb1nuq a29e4ad05c - - intlb2wdc a29e4ad05c - - extlb4wdc 5ab12a3ed2 + - intlb3nuq fa152d4755 + - extlb1nuq fa152d4755 x-runtime: - - '0.127137' + - '0.113688' x-version-label: - - easypost-202305121849-b449e9bf47-master + - easypost-202407081949-3228d5845b-master x-xss-protection: - 1; mode=block status: @@ -163,7 +227,7 @@ interactions: user-agent: - method: DELETE - uri: https://api.easypost.com/v2/carrier_accounts/ca_a575738b0d994778a960c5c19e748baa + uri: https://api.easypost.com/v2/carrier_accounts/ca_c58170a2b708469eb2828ce150f818c5 response: body: string: '{}' @@ -174,8 +238,6 @@ interactions: - '2' content-type: - application/json; charset=utf-8 - etag: - - W/"44136fa355b3678a1146ad16f7e8649e" expires: - '0' pragma: @@ -193,21 +255,20 @@ interactions: x-download-options: - noopen x-ep-request-uuid: - - fe8d870a645eadf2e2aac27e000e7a0c + - df6fc7b2668c51fbe2cba07700263fb1 x-frame-options: - SAMEORIGIN x-node: - - bigweb4nuq + - bigweb38nuq x-permitted-cross-domain-policies: - none x-proxied: - - intlb2nuq a29e4ad05c - - intlb1wdc a29e4ad05c - - extlb4wdc 5ab12a3ed2 + - intlb3nuq fa152d4755 + - extlb1nuq fa152d4755 x-runtime: - - '0.113851' + - '0.066036' x-version-label: - - easypost-202305121849-b449e9bf47-master + - easypost-202407081949-3228d5845b-master x-xss-protection: - 1; mode=block status: diff --git a/tests/cassettes/test_carrier_account_update_ups.yaml b/tests/cassettes/test_carrier_account_update_ups.yaml new file mode 100644 index 0000000..005b542 --- /dev/null +++ b/tests/cassettes/test_carrier_account_update_ups.yaml @@ -0,0 +1,268 @@ +interactions: +- request: + body: '{"ups_oauth_registrations": {"type": "UpsAccount", "account_number": "123456789"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '82' + Content-Type: + - application/json + authorization: + - + user-agent: + - + method: POST + uri: https://api.easypost.com/v2/ups_oauth_registrations + response: + body: + string: '{"id": "ca_e5527ea2bd0f44c59f85fd198428da2b", "object": "CarrierAccount", + "type": "UpsAccount", "clone": false, "created_at": "2024-07-09T17:22:32Z", + "updated_at": "2024-07-09T17:22:32Z", "description": null, "reference": null, + "billing_type": "carrier", "readable": "UPS", "logo": null, "fields": [], + "credentials": {}, "test_credentials": {}}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1388' + 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: + - 52ecff1e668d71d8e2b7eef000485d09 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb53nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq fa152d4755 + - extlb1nuq fa152d4755 + x-runtime: + - '0.090996' + x-version-label: + - easypost-202407091438-d7c6f02f06-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_e5527ea2bd0f44c59f85fd198428da2b + response: + body: + string: '{"id": "ca_e5527ea2bd0f44c59f85fd198428da2b", "object": "CarrierAccount", + "type": "UpsAccount", "clone": false, "created_at": "2024-07-09T17:22:32Z", + "updated_at": "2024-07-09T17:22:32Z", "description": null, "reference": null, + "billing_type": "carrier", "readable": "UPS", "logo": null, "fields": [], + "credentials": {}, "test_credentials": {}}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1388' + 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: + - 52ecff1e668d71d8e2b7eef000485d33 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb36nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq fa152d4755 + - extlb1nuq fa152d4755 + x-runtime: + - '0.040106' + x-version-label: + - easypost-202407091438-d7c6f02f06-master + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +- request: + body: '{"ups_oauth_registrations": {"account_number": "987654321"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '60' + Content-Type: + - application/json + authorization: + - + user-agent: + - + method: PATCH + uri: https://api.easypost.com/v2/ups_oauth_registrations/ca_e5527ea2bd0f44c59f85fd198428da2b + response: + body: + string: '{"id": "ca_e5527ea2bd0f44c59f85fd198428da2b", "object": "CarrierAccount", + "type": "UpsAccount", "clone": false, "created_at": "2024-07-09T17:22:32Z", + "updated_at": "2024-07-09T17:22:32Z", "description": null, "reference": null, + "billing_type": "carrier", "readable": "UPS", "logo": null, "fields": [], + "credentials": {}, "test_credentials": {}}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1416' + 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: + - 52ecff1e668d71d8e2b7eef000485d4a + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb39nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb3nuq fa152d4755 + - extlb1nuq fa152d4755 + x-runtime: + - '0.079076' + x-version-label: + - easypost-202407091438-d7c6f02f06-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_e5527ea2bd0f44c59f85fd198428da2b + 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: + - 52ecff1e668d71d9e2b7eef000485d62 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb36nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb3nuq fa152d4755 + - extlb1nuq fa152d4755 + x-runtime: + - '0.078431' + x-version-label: + - easypost-202407091438-d7c6f02f06-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 c6d19f9..07be3cf 100644 --- a/tests/test_carrier_account.py +++ b/tests/test_carrier_account.py @@ -75,13 +75,13 @@ def test_carrier_account_type(prod_client): @pytest.mark.vcr() def test_carrier_account_create_with_custom_workflow(prod_client): - """Test register a Carrier Account with custom registration such as FedEx or UPS. + """Test registering a Carrier Account with custom workflow. We purposefully don't pass data here because real data is required for this endpoint which we don't have in a test context, simply assert the error matches when no data is passed. """ carrier_account = { - "type": "UpsAccount", + "type": "FedexAccount", "registration_data": {}, } @@ -93,3 +93,39 @@ def test_carrier_account_create_with_custom_workflow(prod_client): [error["field"] == "account_number" and error["message"] == "must be present and a string"] for error in error.errors ) + + +@pytest.mark.vcr() +def test_carrier_account_create_ups(prod_client): + """Test registering a UPS Carrier Account which uses a different URL and schema.""" + params = { + "type": "UpsAccount", + "account_number": "123456789", + } + + carrier_account = prod_client.carrier_account.create(**params) + + assert isinstance(carrier_account, CarrierAccount) + assert str.startswith(carrier_account.id, "ca_") + assert carrier_account.type == "UpsAccount" + + 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_ups(prod_client): + """Test updating a UPS Carrier Account which uses a different URL and schema.""" + params = { + "type": "UpsAccount", + "account_number": "123456789", + } + + carrier_account = prod_client.carrier_account.create(**params) + + prod_client.carrier_account.update(carrier_account.id, account_number="987654321") + + assert isinstance(carrier_account, CarrierAccount) + assert str.startswith(carrier_account.id, "ca_") + assert carrier_account.type == "UpsAccount" + + prod_client.carrier_account.delete(carrier_account.id) # Delete the carrier account once it's done being tested.