Skip to content

Export webhooks namespace to default client #322

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

Merged
merged 1 commit into from
Jul 5, 2024
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
1 change: 1 addition & 0 deletions replicate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
models = default_client.models
predictions = default_client.predictions
trainings = default_client.trainings
webhooks = default_client.webhooks
18 changes: 11 additions & 7 deletions tests/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import respx
from httpx import Request

import replicate
from replicate.client import Client
from replicate.webhook import (
InvalidSecretKeyError,
InvalidSignatureError,
InvalidTimestampError,
MissingWebhookBodyError,
MissingWebhookHeaderError,
Webhooks,
WebhookSigningSecret,
)

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

with pytest.raises(InvalidSignatureError, match="Webhook signature is invalid"):
Webhooks.validate(headers=headers, body=body, secret=webhook_signing_secret)
replicate.webhooks.validate(
headers=headers, body=body, secret=webhook_signing_secret
)


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

with pytest.raises(MissingWebhookHeaderError, match="Missing webhook id"):
Webhooks.validate(headers=headers, body=body, secret=webhook_signing_secret)
replicate.webhooks.validate(
headers=headers, body=body, secret=webhook_signing_secret
)


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

with pytest.raises(InvalidSecretKeyError, match="Invalid secret key format"):
Webhooks.validate(
replicate.webhooks.validate(
headers=headers,
body=body,
secret=WebhookSigningSecret(key="invalid_secret_format"),
Expand All @@ -104,7 +108,7 @@ def test_validate_webhook_missing_headers(webhook_signing_secret):
body = '{"test": 2432232314}'

with pytest.raises(MissingWebhookHeaderError, match="Missing webhook headers"):
Webhooks.validate(
replicate.webhooks.validate(
headers=headers, # type: ignore
body=body,
secret=webhook_signing_secret,
Expand All @@ -121,7 +125,7 @@ def test_validate_webhook_missing_body(webhook_signing_secret):
body = None

with pytest.raises(MissingWebhookBodyError, match="Missing webhook body"):
Webhooks.validate(
replicate.webhooks.validate(
headers=headers,
body=body, # type: ignore
secret=webhook_signing_secret,
Expand Down Expand Up @@ -154,7 +158,7 @@ def test_validate_webhook_timestamp(
with pytest.raises(
(InvalidTimestampError if timestamp_invalid else InvalidSignatureError),
):
Webhooks.validate(
replicate.webhooks.validate(
headers=headers,
body=body,
secret=webhook_signing_secret,
Expand Down