diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 890641059..a674702d2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/examples/user/user.py b/examples/user/user.py index 5160f9ff8..cd1a5432a 100644 --- a/examples/user/user.py +++ b/examples/user/user.py @@ -179,7 +179,7 @@ ################################################## # Update Event Notification Settings # -# PATCH /user/webhooks/event/settings # +# PATCH /user/webhooks/event/settings/{webhook_id} # data = { "bounce": True, @@ -196,13 +196,14 @@ "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() @@ -210,12 +211,24 @@ 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) diff --git a/test/integ/test_sendgrid.py b/test/integ/test_sendgrid.py index 0c63851eb..690e2405f 100644 --- a/test/integ/test_sendgrid.py +++ b/test/integ/test_sendgrid.py @@ -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}