Skip to content
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

feat: Multiple Webhook Support #1067

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ All test files are in the [`test`](test) directory. For the purposes of contribu

The integration tests require a Twilio SendGrid mock API in order to execute. We've simplified setting this up using Docker to run the tests. You will just need [Docker Desktop](https://docs.docker.com/get-docker/) and `make`.

Once these are available, simply execute the Docker test target to run all tests: `make test-docker`. This command can also be used to open an interactive shell into the container where this library is installed. To start a *bash* shell for example, use this command: `command=bash make test-docker`.
Once these are available, simply execute the Docker test target to run all tests: `make test-docker`. This command can also be used to open an interactive shell into the container where this library is installed. To start a *bash* shell for example, use this command: `command=bash make test-docker` and you can run a specific test like `source venv/bin/activate; python -m unittest test.integ.test_sendgrid.UnitTests.test_useragent`.

## Style Guidelines & Naming Conventions

Expand Down
21 changes: 17 additions & 4 deletions examples/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@

##################################################
# Update Event Notification Settings #
# PATCH /user/webhooks/event/settings #
# PATCH /user/webhooks/event/settings/{webhook_id} #

data = {
"bounce": True,
Expand All @@ -196,26 +196,39 @@
"unsubscribe": True,
"url": "url"
}
response = sg.client.user.webhooks.event.settings.patch(request_body=data)
webhook_id = "some-webhook-uuid"
response = sg.client.user.webhooks.event.settings._(webhook_id).patch(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)

##################################################
# Retrieve Event Webhook settings #
# Retrieve Event Webhook settings (legacy, no id)#
# GET /user/webhooks/event/settings #

response = sg.client.user.webhooks.event.settings.get()
print(response.status_code)
print(response.body)
print(response.headers)

##################################################
# Retrieve Event Webhook settings #
# GET /user/webhooks/event/settings/{webhook_id} #

webhook_id = "some-webhook-uuid"
response = sg.client.user.webhooks.event.settings._(webhook_id).get()
print(response.status_code)
print(response.body)
print(response.headers)

##################################################
# Test Event Notification Settings #
# POST /user/webhooks/event/test #

webhook_id = "some-webhook-uuid"
data = {
"url": "url"
"url": "url",
"id": webhook_id
}
response = sg.client.user.webhooks.event.test.post(request_body=data)
print(response.status_code)
Expand Down
19 changes: 17 additions & 2 deletions test/integ/test_sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1992,19 +1992,34 @@ def test_user_webhooks_event_settings_patch(self):
"unsubscribe": True,
"url": "url"
}
webhook_id = "some-webhook-uuid"
headers = {'X-Mock': 200}
response = self.sg.client.user.webhooks.event.settings.patch(
response = self.sg.client.user.webhooks.event.settings._(webhook_id).patch(
request_body=data, request_headers=headers)
self.assertEqual(response.status_code, 200)

def test_user_webhooks_event_settings_get(self):
# legacy webhook API only allowed for a single webhook. When no ID is provided,
# backwards compatiblity ensures we will get the oldest webhook back.
# Going forward, users should use settings._(webhook_id) in all calls.
def test_user_webhooks_event_settings_get_legacy_no_id(self):
headers = {'X-Mock': 200}
webhook_id = "some-webhook-uuid"
response = self.sg.client.user.webhooks.event.settings.get(
request_headers=headers)
self.assertEqual(response.status_code, 200)

def test_user_webhooks_event_settings_get(self):
headers = {'X-Mock': 200}
webhook_id = "some-webhook-uuid"
self.assertTrue(False, "not true")
response = self.sg.client.user.webhooks.event.settings._(webhook_id).get(
request_headers=headers)

self.assertEqual(response.status_code, 200)

def test_user_webhooks_event_test_post(self):
data = {
"id": "some-webhook-id",
"url": "url"
}
headers = {'X-Mock': 204}
Expand Down