Skip to content

Commit 0e01c88

Browse files
authored
Export webhooks namespace to default client (#322)
Follow-up to #321 Signed-off-by: Mattt Zmuda <[email protected]>
1 parent b8196f5 commit 0e01c88

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

replicate/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
models = default_client.models
2020
predictions = default_client.predictions
2121
trainings = default_client.trainings
22+
webhooks = default_client.webhooks

tests/test_webhooks.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import respx
66
from httpx import Request
77

8+
import replicate
89
from replicate.client import Client
910
from replicate.webhook import (
1011
InvalidSecretKeyError,
1112
InvalidSignatureError,
1213
InvalidTimestampError,
1314
MissingWebhookBodyError,
1415
MissingWebhookHeaderError,
15-
Webhooks,
1616
WebhookSigningSecret,
1717
)
1818

@@ -69,7 +69,9 @@ def test_validate_webhook_invalid_signature(webhook_signing_secret):
6969
body = '{"test": 2432232314}'
7070

7171
with pytest.raises(InvalidSignatureError, match="Webhook signature is invalid"):
72-
Webhooks.validate(headers=headers, body=body, secret=webhook_signing_secret)
72+
replicate.webhooks.validate(
73+
headers=headers, body=body, secret=webhook_signing_secret
74+
)
7375

7476

7577
def test_validate_webhook_missing_webhook_id(webhook_signing_secret):
@@ -79,7 +81,9 @@ def test_validate_webhook_missing_webhook_id(webhook_signing_secret):
7981
body = '{"test": 2432232314}'
8082

8183
with pytest.raises(MissingWebhookHeaderError, match="Missing webhook id"):
82-
Webhooks.validate(headers=headers, body=body, secret=webhook_signing_secret)
84+
replicate.webhooks.validate(
85+
headers=headers, body=body, secret=webhook_signing_secret
86+
)
8387

8488

8589
def test_validate_webhook_invalid_secret():
@@ -92,7 +96,7 @@ def test_validate_webhook_invalid_secret():
9296
body = '{"test": 2432232314}'
9397

9498
with pytest.raises(InvalidSecretKeyError, match="Invalid secret key format"):
95-
Webhooks.validate(
99+
replicate.webhooks.validate(
96100
headers=headers,
97101
body=body,
98102
secret=WebhookSigningSecret(key="invalid_secret_format"),
@@ -104,7 +108,7 @@ def test_validate_webhook_missing_headers(webhook_signing_secret):
104108
body = '{"test": 2432232314}'
105109

106110
with pytest.raises(MissingWebhookHeaderError, match="Missing webhook headers"):
107-
Webhooks.validate(
111+
replicate.webhooks.validate(
108112
headers=headers, # type: ignore
109113
body=body,
110114
secret=webhook_signing_secret,
@@ -121,7 +125,7 @@ def test_validate_webhook_missing_body(webhook_signing_secret):
121125
body = None
122126

123127
with pytest.raises(MissingWebhookBodyError, match="Missing webhook body"):
124-
Webhooks.validate(
128+
replicate.webhooks.validate(
125129
headers=headers,
126130
body=body, # type: ignore
127131
secret=webhook_signing_secret,
@@ -154,7 +158,7 @@ def test_validate_webhook_timestamp(
154158
with pytest.raises(
155159
(InvalidTimestampError if timestamp_invalid else InvalidSignatureError),
156160
):
157-
Webhooks.validate(
161+
replicate.webhooks.validate(
158162
headers=headers,
159163
body=body,
160164
secret=webhook_signing_secret,

0 commit comments

Comments
 (0)