Skip to content

Commit

Permalink
fix: ups carrier account tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Jul 9, 2024
1 parent 4f93a56 commit 5be741a
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 67 deletions.
3 changes: 2 additions & 1 deletion easypost/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
"FedexAccount",
"FedexSmartpostAccount",
]
_UPS_OATH_CARRIER_ACCOUNT_TYPES = [
_UPS_OAUTH_CARRIER_ACCOUNT_TYPES = [
"UpsAccount",
"UpsMailInnovationsAccount",
"UpsSurepostAccount",
]
_FILTERS_KEY = "filters"
_EXCLUDED_CLASS_NAMES = ["ups_oauth_registrations"]
5 changes: 4 additions & 1 deletion easypost/services/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)

from easypost.constant import (
_EXCLUDED_CLASS_NAMES,
_FILTERS_KEY,
NO_MORE_PAGES_ERROR,
)
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions easypost/services/carrier_account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from easypost.constant import (
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS,
_UPS_OATH_CARRIER_ACCOUNT_TYPES,
_UPS_OAUTH_CARRIER_ACCOUNT_TYPES,
MISSING_PARAMETER_ERROR,
)
from easypost.easypost_object import convert_to_easypost_object
Expand All @@ -33,7 +33,7 @@ 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)
if carrier_account_type in _UPS_OATH_CARRIER_ACCOUNT_TYPES:
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}
Expand All @@ -54,7 +54,7 @@ def update(self, id: str, **params) -> CarrierAccount:
"""Update a CarrierAccount."""
carrier_account = self.retrieve(id)

if carrier_account.get("type") in _UPS_OATH_CARRIER_ACCOUNT_TYPES:
if carrier_account.get("type") in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
class_name = "UpsOauthRegistrations"
else:
class_name = self._model_class
Expand All @@ -75,7 +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_OATH_CARRIER_ACCOUNT_TYPES:
elif carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
return "/ups_oauth_registrations"

return "/carrier_accounts"
93 changes: 80 additions & 13 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.

Loading

0 comments on commit 5be741a

Please sign in to comment.