Skip to content

Commit 025260c

Browse files
authored
Merge pull request #356 from EasyPost/webhook_params
test: additional params in webhook create/update calls
2 parents 0f38da0 + 279962a commit 025260c

File tree

7 files changed

+94
-62
lines changed

7 files changed

+94
-62
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## Next Release
4+
5+
- Fixes the payload wrapping for updating a webhook
6+
37
## v9.5.0 (2024-10-24)
48

59
- Adds `tracking_codes` as a parameter of the `all` method on the TrackerService

easypost/services/webhook_service.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
Dict,
44
)
55

6+
from easypost.easypost_object import convert_to_easypost_object
67
from easypost.models import Webhook
8+
from easypost.requestor import (
9+
RequestMethod,
10+
Requestor,
11+
)
712
from easypost.services.base_service import BaseService
813

914

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

2732
def update(self, id: str, **params) -> Webhook:
2833
"""Update a Webhook."""
29-
return self._update_resource(self._model_class, id, **params)
34+
url = self._instance_url(self._model_class, id)
35+
36+
response = Requestor(self._client).request(method=RequestMethod.PATCH, url=url, params=params)
37+
38+
return convert_to_easypost_object(response=response)
3039

3140
def delete(self, id: str) -> None:
3241
"""Delete a Webhook."""

examples

Submodule examples updated 170 files

tests/cassettes/test_webhook_create.yaml

Lines changed: 20 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/cassettes/test_webhook_update.yaml

Lines changed: 33 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/conftest.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def pytest_sessionfinish(session, exitstatus):
4545

4646

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

339339
@pytest.fixture
340340
def webhook_hmac_signature():
341-
return read_fixture_data()["webhook_hmac_signature"]
341+
return read_fixture_data()["webhooks"]["hmac_signature"]
342342

343343

344344
@pytest.fixture
345345
def webhook_secret():
346-
return read_fixture_data()["webhook_secret"]
346+
return read_fixture_data()["webhooks"]["secret"]
347347

348348

349349
@pytest.fixture
350350
def webhook_url():
351-
return read_fixture_data()["webhook_url"]
351+
return read_fixture_data()["webhooks"]["url"]
352+
353+
354+
@pytest.fixture
355+
def webhook_custom_headers():
356+
return read_fixture_data()["webhooks"]["custom_headers"]
352357

353358

354359
@pytest.fixture

tests/test_webhook.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55

66

77
@pytest.mark.vcr()
8-
def test_webhook_create(webhook_url, test_client):
9-
webhook = test_client.webhook.create(url=webhook_url)
8+
def test_webhook_create(webhook_url, webhook_secret, webhook_custom_headers, test_client):
9+
webhook = test_client.webhook.create(
10+
url=webhook_url,
11+
webhook_secret=webhook_secret,
12+
custom_headers=webhook_custom_headers,
13+
)
1014

1115
assert isinstance(webhook, Webhook)
1216
assert str.startswith(webhook.id, "hook_")
1317
assert webhook.url == webhook_url
18+
assert webhook.custom_headers[0]["name"] == "test"
19+
assert webhook.custom_headers[0]["value"] == "header"
1420

1521
test_client.webhook.delete(
1622
webhook.id
@@ -42,11 +48,17 @@ def test_webhook_all(page_size, test_client):
4248

4349

4450
@pytest.mark.vcr()
45-
def test_webhook_update(webhook_url, test_client):
51+
def test_webhook_update(webhook_url, webhook_secret, webhook_custom_headers, test_client):
4652
webhook = test_client.webhook.create(url=webhook_url)
47-
test_client.webhook.update(webhook.id)
53+
updated_webhook = test_client.webhook.update(
54+
webhook.id,
55+
webhook_secret=webhook_secret,
56+
custom_headers=webhook_custom_headers,
57+
)
4858

49-
assert isinstance(webhook, Webhook)
59+
assert isinstance(updated_webhook, Webhook)
60+
assert updated_webhook.custom_headers[0]["name"] == "test"
61+
assert updated_webhook.custom_headers[0]["value"] == "header"
5062

5163
test_client.webhook.delete(
5264
webhook.id

0 commit comments

Comments
 (0)