From 047c02781cbd92d29594dc61ba0ee76d78bac796 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Sun, 23 Apr 2017 19:20:46 -0230 Subject: [PATCH] webhook-walkthrough: Recommend passing kwargs to build_webhook_url. When constructing URLs for testing, we now recommend passing query parameters as keyword arguments to build_webhook_url instead of overriding it. --- docs/webhook-walkthrough.md | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/docs/webhook-walkthrough.md b/docs/webhook-walkthrough.md index 21d53b80ed..fa22e6140a 100644 --- a/docs/webhook-walkthrough.md +++ b/docs/webhook-walkthrough.md @@ -476,32 +476,24 @@ http://myhost/api/v1/external/querytest?api_key=abcdefgh&stream=alerts&topic=que It provides values for `stream` and `topic`, and the webhook can get those using `REQ` without any special handling. How does this work in a test? -The new attribute `TOPIC` exists only in our class, so the default version of -`build_webhook_url` from `WebhookTestCase` doesn't know how to use it to -construct the URL. Instead, we provide a custom `build_webhook_url` to -override the default one: +The new attribute `TOPIC` exists only in our class so far. In order to +construct a URL with a query parameter for `topic`, you can pass the +attribute `TOPIC` as a keyword argument to `build_webhook_url`, like so: ``` class QuerytestHookTests(WebhookTestCase): STREAM_NAME = 'querytest' TOPIC = "Default Topic" - URL_TEMPLATE = "/api/v1/external/querytest?api_key={api_key}&stream={stream}&topic={topic}" + URL_TEMPLATE = "/api/v1/external/querytest?api_key={api_key}&stream={stream}" FIXTURE_DIR_NAME = 'querytest' - # override the base class behavior so we can include TOPIC - def build_webhook_url(self): - # type: () -> Text - - api_key = self.get_api_key(self.TEST_USER_EMAIL) - return self.URL_TEMPLATE.format(stream=self.STREAM_NAME, api_key=api_key, topic=self.TOPIC) - def test_querytest_test_one(self): # type: () -> None # construct the URL used for this test self.TOPIC = u"Query Test" - self.url = self.build_webhook_url() + self.url = self.build_webhook_url(topic=self.TOPIC) # define the expected message contents expected_subject = u"Query Test"