Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Next Release

- Fixes the payload wrapping for updating a webhook

## v9.5.0 (2024-10-24)

- Adds `tracking_codes` as a parameter of the `all` method on the TrackerService
Expand Down
11 changes: 10 additions & 1 deletion easypost/services/webhook_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
Dict,
)

from easypost.easypost_object import convert_to_easypost_object
from easypost.models import Webhook
from easypost.requestor import (
RequestMethod,
Requestor,
)
from easypost.services.base_service import BaseService


Expand All @@ -26,7 +31,11 @@ def retrieve(self, id: str) -> Webhook:

def update(self, id: str, **params) -> Webhook:
"""Update a Webhook."""
return self._update_resource(self._model_class, id, **params)
url = self._instance_url(self._model_class, id)

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

return convert_to_easypost_object(response=response)

def delete(self, id: str) -> None:
"""Delete a Webhook."""
Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 170 files
41 changes: 20 additions & 21 deletions tests/cassettes/test_webhook_create.yaml

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

63 changes: 33 additions & 30 deletions tests/cassettes/test_webhook_update.yaml

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

13 changes: 9 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def pytest_sessionfinish(session, exitstatus):


@pytest.fixture(autouse=True)
def check_expired_cassettes(expiration_days: int = 180, throw_error: bool = False):
def check_expired_cassettes(expiration_days: int = 365, throw_error: bool = False):
"""Checks for expired cassettes and throws errors if they are too old and must be re-recorded."""
test_name = os.environ.get("PYTEST_CURRENT_TEST").split(":")[-1].split(" ")[0] # type: ignore
cassette_filepath = os.path.join("tests", "cassettes", f"{test_name}.yaml")
Expand Down Expand Up @@ -338,17 +338,22 @@ def event_bytes():

@pytest.fixture
def webhook_hmac_signature():
return read_fixture_data()["webhook_hmac_signature"]
return read_fixture_data()["webhooks"]["hmac_signature"]


@pytest.fixture
def webhook_secret():
return read_fixture_data()["webhook_secret"]
return read_fixture_data()["webhooks"]["secret"]


@pytest.fixture
def webhook_url():
return read_fixture_data()["webhook_url"]
return read_fixture_data()["webhooks"]["url"]


@pytest.fixture
def webhook_custom_headers():
return read_fixture_data()["webhooks"]["custom_headers"]


@pytest.fixture
Expand Down
22 changes: 17 additions & 5 deletions tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@


@pytest.mark.vcr()
def test_webhook_create(webhook_url, test_client):
webhook = test_client.webhook.create(url=webhook_url)
def test_webhook_create(webhook_url, webhook_secret, webhook_custom_headers, test_client):
webhook = test_client.webhook.create(
url=webhook_url,
webhook_secret=webhook_secret,
custom_headers=webhook_custom_headers,
)

assert isinstance(webhook, Webhook)
assert str.startswith(webhook.id, "hook_")
assert webhook.url == webhook_url
assert webhook.custom_headers[0]["name"] == "test"
assert webhook.custom_headers[0]["value"] == "header"

test_client.webhook.delete(
webhook.id
Expand Down Expand Up @@ -42,11 +48,17 @@ def test_webhook_all(page_size, test_client):


@pytest.mark.vcr()
def test_webhook_update(webhook_url, test_client):
def test_webhook_update(webhook_url, webhook_secret, webhook_custom_headers, test_client):
webhook = test_client.webhook.create(url=webhook_url)
test_client.webhook.update(webhook.id)
updated_webhook = test_client.webhook.update(
webhook.id,
webhook_secret=webhook_secret,
custom_headers=webhook_custom_headers,
)

assert isinstance(webhook, Webhook)
assert isinstance(updated_webhook, Webhook)
assert updated_webhook.custom_headers[0]["name"] == "test"
assert updated_webhook.custom_headers[0]["value"] == "header"

test_client.webhook.delete(
webhook.id
Expand Down