Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Account for new UPS endpoint in carrier account create/update functions #336

Merged
merged 7 commits into from
Jul 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add new create_ups and update_ups functions
Justintime50 committed Jul 3, 2024
commit 77012f5c8e3be225178dd8ceef27b7e48590e7c3
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## Next Release

- Adds new `create_ups` and `update_ups` functions under `carrier_account`
- Starting `2024-08-05`, UPS accounts can no longer be created or updated through the normal create and update functions and must use these UPS specific functions

## v9.2.0 (2024-04-10)

- Fix payment method funding and deletion failures due to undetermined payment method type
1 change: 0 additions & 1 deletion easypost/constant.py
Original file line number Diff line number Diff line change
@@ -35,6 +35,5 @@
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS = [
"FedexAccount",
"FedexSmartpostAccount",
"UpsAccount",
]
_FILTERS_KEY = "filters"
17 changes: 17 additions & 0 deletions easypost/services/carrier_account_service.py
Original file line number Diff line number Diff line change
@@ -60,6 +60,23 @@ def types(self) -> List[Dict[str, Any]]:

return convert_to_easypost_object(response=response)

def create_ups(self, **params) -> CarrierAccount:
"""Create a UPS CarrierAccount which has its own custom workflow."""
url = "/ups_oauth_registrations"
wrapped_params = {"ups_oauth_registrations": params}

response = Requestor(self._client).request(
method=RequestMethod.POST,
url=url,
params=wrapped_params,
)

return convert_to_easypost_object(response=response)

def update_ups(self, id: str, **params) -> CarrierAccount:
"""Update a UPS CarrierAccount which has its own custom workflow."""
return self._update_resource("UpsOauthRegistrations", id, **params)

def _select_carrier_account_creation_endpoint(self, carrier_account_type: Optional[Any]) -> str:
"""Determines which API endpoint to use for the creation call."""
if carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS:
69 changes: 69 additions & 0 deletions tests/cassettes/test_carrier_account_create_ups.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions tests/cassettes/test_carrier_account_update_ups.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 40 additions & 2 deletions tests/test_carrier_account.py
Original file line number Diff line number Diff line change
@@ -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,41 @@ 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.

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",
}

try:
prod_client.carrier_account.create_ups(**carrier_account)
except ApiError as error:
assert error.http_status == 422
assert any(
[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_update_ups(prod_client):
"""Test updating a UPS Carrier Account.

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 that we routed the request correctly.
"""
carrier_account = {
"type": "UpsAccount",
}

try:
prod_client.carrier_account.update_ups("ca_123", **carrier_account)
except ApiError as error:
assert error.http_status == 404