-
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bot_server: Add support for running botserver from bots registry.
- Loading branch information
Showing
2 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from typing import Any, Dict | ||
from unittest import mock | ||
|
||
from zulip_bots.finder import metadata | ||
from zulip_bots.lib import BotHandler | ||
from zulip_botserver import server | ||
from zulip_botserver.input_parameters import parse_args | ||
|
@@ -273,6 +274,37 @@ def test_load_lib_modules(self) -> None: | |
).as_posix() | ||
module = server.load_lib_modules([path])[path] | ||
|
||
@mock.patch("zulip_botserver.server.app") | ||
@mock.patch("sys.argv", ["zulip-botserver", "--config-file", "/foo/bar/baz.conf"]) | ||
def test_load_from_registry(self, mock_app: mock.Mock) -> None: | ||
packaged_bot_module = mock.MagicMock(__version__="1.0.0", __file__="asd") | ||
packaged_bot_entrypoint = metadata.EntryPoint( | ||
"packaged_bot", "module_name", "zulip_bots.registry" | ||
) | ||
bots_config = { | ||
"packaged_bot": { | ||
"email": "[email protected]", | ||
"key": "value", | ||
"site": "http://localhost", | ||
"token": "abcd1234", | ||
} | ||
} | ||
|
||
with mock.patch( | ||
"zulip_botserver.server.read_config_file", return_value=bots_config | ||
), mock.patch("zulip_botserver.server.lib.ExternalBotHandler", new=mock.Mock()), mock.patch( | ||
"zulip_bots.finder.metadata.EntryPoint.load", | ||
return_value=packaged_bot_module, | ||
), mock.patch( | ||
"zulip_bots.finder.metadata.entry_points", | ||
return_value=(packaged_bot_entrypoint,), | ||
): | ||
server.main() | ||
|
||
mock_app.config.__setitem__.assert_any_call( | ||
"BOTS_LIB_MODULES", {"packaged_bot": packaged_bot_module} | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters