webhook docs: Avoid misleading `get_body` references.

For most cases you don't need to override `get_body`,
and for non-trivial cases, there's really no set pattern.

(It would be nice if we didn't default to json extensions
and just forced folks to be explicit about file extensions,
which would remove a whole class of `get_body` overrides.)
This commit is contained in:
Steve Howell 2020-08-20 19:18:02 +00:00 committed by Tim Abbott
parent 6d65af1790
commit ef5de173fe
1 changed files with 5 additions and 13 deletions

View File

@ -326,9 +326,6 @@ class HelloWorldHookTests(WebhookTestCase):
self.check_webhook('hello', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("helloworld", fixture_name, file_type="json")
```
In the above example, `STREAM_NAME`, `URL_TEMPLATE`, and `FIXTURE_DIR_NAME` refer
@ -346,10 +343,6 @@ value from the fixture. If these don't match, the test will fail.
you would provide a webhook URL to the 3rd party service. `api_key={api_key}` says
that an API key is expected.
In `get_body`, the first argument in the call to `self.webhook_fixture_data` specifies the
prefix of your fixture file names, and `file_type` their type. Common types are
`json` and `txt`.
When writing tests for your webhook, you'll want to include one test function
(and corresponding fixture) per each distinct message condition that your
integration supports.
@ -591,14 +584,13 @@ class QuerytestHookTests(WebhookTestCase):
self.check_webhook('test_one', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("querytest", fixture_name, file_type="json")
```
You can also override `get_body` if your test data needs to be constructed in
an unusual way. For more, see the definition for the base class, `WebhookTestCase`
in `zerver/lib/test_classes.py.`
You can also override `get_body` or `get_payload` if your test data
needs to be constructed in an unusual way.
For more, see the definition for the base class, `WebhookTestCase`
in `zerver/lib/test_classes.py`, or just grep for examples.
### Custom HTTP event-type headers