Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

help: Move writing-tests-for-interactive-bots from API to help center.

Lauryn Menardd59aefce9aee
diff --git a/api_docs/interactive-bots-api.md b/api_docs/interactive-bots-api.md
index a1a8ee4d349..5c76eea59a0 100644
--- a/api_docs/interactive-bots-api.md
+++ b/api_docs/interactive-bots-api.md
@@ -312,4 +312,4 @@ with use_storage(bot_handler.storage, ["foo", "bar"]) as cache:
## Related articles
* [Writing bots](/api/writing-bots)
-* [Writing tests for bots](/api/writing-tests-for-interactive-bots)
+* [Writing tests for bots](/help/writing-tests-for-interactive-bots)
diff --git a/api_docs/sidebar_index.md b/api_docs/sidebar_index.md
index 6abf97aba17..b0f026edc8f 100644
--- a/api_docs/sidebar_index.md
+++ b/api_docs/sidebar_index.md
@@ -9,7 +9,7 @@
* [Writing bots](/api/writing-bots)
* [Interactive bots API](/api/interactive-bots-api)
-* [Writing tests for bots](/api/writing-tests-for-interactive-bots)
+* [Writing tests for bots](/help/writing-tests-for-interactive-bots)
* [Running bots](/help/running-bots)
* [Deploying bots](/help/deploying-bots)
* [Outgoing webhooks](/help/outgoing-webhooks)
diff --git a/api_docs/writing-bots.md b/api_docs/writing-bots.md
index 5cd3bd1688d..08335ac7401 100644
--- a/api_docs/writing-bots.md
+++ b/api_docs/writing-bots.md
@@ -128,7 +128,7 @@ Ensure that you restarted the `zulip-run-bot` script.
## Related articles
* [Interactive bots API](/api/interactive-bots-api)
-* [Writing tests for bots](/api/writing-tests-for-interactive-bots)
+* [Writing tests for bots](/help/writing-tests-for-interactive-bots)
* [Running bots](/help/running-bots)
* [Deploying bots](/help/deploying-bots)
* [Configuring the Python bindings](/api/configuring-python-bindings)
diff --git a/starlight_help/astro.config.mjs b/starlight_help/astro.config.mjs
index a448a156a12..41324c45f37 100644
--- a/starlight_help/astro.config.mjs
+++ b/starlight_help/astro.config.mjs
@@ -667,6 +667,7 @@ export default defineConfig({
},
"view-your-bots",
"view-all-bots-in-your-organization",
+ "writing-tests-for-interactive-bots",
"running-bots",
"deploying-bots",
"outgoing-webhooks",
diff --git a/api_docs/writing-tests-for-interactive-bots.md b/starlight_help/src/content/docs/writing-tests-for-interactive-bots.mdx
similarity index 64%
rename from api_docs/writing-tests-for-interactive-bots.md
rename to starlight_help/src/content/docs/writing-tests-for-interactive-bots.mdx
index 57509e2eb16..f8ab4b7adde 100644
--- a/api_docs/writing-tests-for-interactive-bots.md
+++ b/starlight_help/src/content/docs/writing-tests-for-interactive-bots.mdx
@@ -1,4 +1,8 @@
-# Writing tests for interactive bots
+---
+title: Writing tests for interactive bots
+---
+
+import ZulipNote from "../../components/ZulipNote.astro";
This page gives an overview of the unit testing framework for interactive bots.
Bots in the main
@@ -6,15 +10,16 @@ Bots in the main
repository are required to include a reasonable set of unit tests, so that
future developers can easily refactor them.
-*Unit tests for bots make heavy use of mocking. If you want to get comfortable with mocking,
- mocking strategies, etc. you should check out our [mocking guide](
- https://zulip.readthedocs.io/en/latest/testing/testing-with-django.html#testing-with-mocks).*
+<ZulipNote>
+ Unit tests for bots make heavy use of mocking. If you want to get comfortable with mocking,
+ mocking strategies, etc. you should check out our
+ [mocking guide](https://zulip.readthedocs.io/en/latest/testing/testing-with-django.html#testing-with-mocks).
+</ZulipNote>
## A simple example
- Let's have a look at a simple test suite for the [`helloworld`](
- https://github.com/zulip/python-zulip-api/tree/main/zulip_bots/zulip_bots/bots/helloworld)
- bot.
+Let's have a look at a simple test suite for the
+[`helloworld`](https://github.com/zulip/python-zulip-api/tree/main/zulip_bots/zulip_bots/bots/helloworld) bot.
```python
from zulip_bots.test_lib import StubBotTestCase
@@ -46,8 +51,7 @@ The best way to learn about bot tests is to read all the existing tests in the
Once you have written a test suite, you want to verify that everything works as expected.
-* To test a bot in [Zulip's bot directory](
- https://github.com/zulip/python-zulip-api/tree/main/zulip_bots/zulip_bots/bots):
+* To test a bot in [Zulip's bot directory](https://github.com/zulip/python-zulip-api/tree/main/zulip_bots/zulip_bots/bots):
`tools/test-bots <botname>`
* To run all bot tests: `tools/test-bots`
@@ -56,40 +60,41 @@ Once you have written a test suite, you want to verify that everything works as
This section shows advanced testing techniques for more complicated bots that have
configuration files or interact with third-party APIs.
-*The code for the bot testing library can be found [here](
- https://github.com/zulip/python-zulip-api/blob/main/zulip_bots/zulip_bots/test_lib.py).*
-
+*The code for the bot testing library can be found [here](https://github.com/zulip/python-zulip-api/blob/main/zulip_bots/zulip_bots/test_lib.py).*
### Testing bots with config files
-Some bots, such as [Giphy](
-https://github.com/zulip/python-zulip-api/tree/main/zulip_bots/zulip_bots/bots/giphy),
+Some bots, such as [Giphy](https://github.com/zulip/python-zulip-api/tree/main/zulip_bots/zulip_bots/bots/giphy),
support or require user configuration options to control how the bot works.
To test such a bot, you can use the following pattern:
- with self.mock_config_info(dict(api_key=12345)):
- # self.verify_reply(...)
+```
+with self.mock_config_info(dict(api_key=12345)):
+ # self.verify_reply(...)
+```
`mock_config_info()` replaces the actual step of reading configuration from the file
system and gives your test "dummy data" instead.
### Testing bots with internet access
-Some bots, such as [Giphy](
-https://github.com/zulip/python-zulip-api/tree/main/zulip_bots/zulip_bots/bots/giphy),
+Some bots, such as [Giphy](https://github.com/zulip/python-zulip-api/tree/main/zulip_bots/zulip_bots/bots/giphy),
depend on a third-party service, such as the Giphy web app, in order to work. Because
we want our test suite to be reliable and not add load to these third-party APIs, tests
for these services need to have "test fixtures": sample HTTP request/response pairs to
be used by the tests. You can specify which one to use in your test code using the
following helper method:
- with self.mock_http_conversation('test_fixture_name'):
- # self.assert_bot_response(...)
+```
+with self.mock_http_conversation('test_fixture_name'):
+ # self.assert_bot_response(...)
+```
`mock_http_conversation(fixture_name)` patches `requests.get` and returns the data specified
in the file `fixtures/{fixture_name}.json`. Use the following JSON code as a skeleton for new
fixtures:
+
```json
{
"request": {
@@ -103,12 +108,14 @@ fixtures:
}
}
```
-For an example, check out the [giphy bot](
-https://github.com/zulip/python-zulip-api/tree/main/zulip_bots/zulip_bots/bots/giphy).
-*Tip: You can use [requestbin](https://requestbin.com/) or a similar
-tool to capture payloads from the service your bot is interacting
-with.*
+For an example, check out the [giphy bot](https://github.com/zulip/python-zulip-api/tree/main/zulip_bots/zulip_bots/bots/giphy).
+
+<ZulipNote>
+ You can use [requestbin](https://requestbin.com/) or a similar
+ tool to capture payloads from the service your bot is interacting
+ with.
+</ZulipNote>
### Examples
diff --git a/zerver/lib/url_redirects.py b/zerver/lib/url_redirects.py
index b524ede155a..1f20b53f17a 100644
--- a/zerver/lib/url_redirects.py
+++ b/zerver/lib/url_redirects.py
@@ -14,6 +14,9 @@ REDIRECTED_TO_HELP_DOCUMENTATION: list[URLRedirect] = [
URLRedirect("/api/outgoing-webhooks", "/help/outgoing-webhooks"),
URLRedirect("/api/deploying-bots", "/help/deploying-bots"),
URLRedirect("/api/running-bots", "/help/running-bots"),
+ URLRedirect(
+ "/api/writing-tests-for-interactive-bots", "/help/writing-tests-for-interactive-bots"
+ ),
]
API_DOCUMENTATION_REDIRECTS: list[URLRedirect] = [