From 05b9850ba35adf456140ec57e715b9e9dc1408cc Mon Sep 17 00:00:00 2001 From: PIG208 <359101898@qq.com> Date: Mon, 2 Aug 2021 23:32:02 +0800 Subject: [PATCH] api: Fetch server_settings when initializing Client. We store the information about the version of the server and the feature level for transparent compatibility handling. --- zulip/zulip/__init__.py | 5 +++++ zulip_botserver/tests/test_server.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 725896e..3721f7a 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -486,6 +486,11 @@ class Client: self.has_connected = False + server_settings = self.get_server_settings() + self.zulip_version: Optional[str] = server_settings.get("zulip_version") + self.feature_level: int = server_settings.get("zulip_feature_level", 0) + assert self.zulip_version is not None + def ensure_session(self) -> None: # Check if the session has been created already, and return diff --git a/zulip_botserver/tests/test_server.py b/zulip_botserver/tests/test_server.py index 9022e92..3d94db5 100644 --- a/zulip_botserver/tests/test_server.py +++ b/zulip_botserver/tests/test_server.py @@ -25,6 +25,13 @@ class BotServerTests(BotServerTestCase): def handler_class(self) -> Any: return BotServerTests.MockMessageHandler() + def setUp(self) -> None: + # Since initializing Client invokes `get_server_settings` that fails in the test + # environment, we need to mock it to pretend that there exists a backend. + super().setUp() + self.patch = mock.patch("zulip.Client.get_server_settings", return_value=mock.Mock()) + self.patch.start() + def test_successful_request(self) -> None: available_bots = ["helloworld"] bots_config = {