From 3028140283129b9d3cb9390311e08eaa26f7c8ce Mon Sep 17 00:00:00 2001 From: oeway Date: Tue, 9 Nov 2021 23:10:29 +0100 Subject: [PATCH] Fix plugin_count --- hypha/VERSION | 2 +- hypha/apps.py | 4 ++-- hypha/core/interface.py | 7 +++++-- hypha/server.py | 1 + tests/test_server_apps.py | 7 +++++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hypha/VERSION b/hypha/VERSION index f2e88a80..d15dbbeb 100644 --- a/hypha/VERSION +++ b/hypha/VERSION @@ -1,3 +1,3 @@ { - "version": "0.12.10" + "version": "0.12.11" } diff --git a/hypha/apps.py b/hypha/apps.py index ffe12464..aab6bda6 100644 --- a/hypha/apps.py +++ b/hypha/apps.py @@ -442,9 +442,9 @@ def connected(plugin): self._apps[page_id]["status"] = "connected" asyncio.get_running_loop().create_task(check_ready(plugin, config)) - def failed(config): + def failed(detail): app_info["watch"] = False - fut.set_exception(Exception(config.detail)) + fut.set_exception(Exception(detail)) plugin_event_bus.on("connected", connected) plugin_event_bus.on("failed", failed) diff --git a/hypha/core/interface.py b/hypha/core/interface.py index 9550d9b0..cbc12878 100644 --- a/hypha/core/interface.py +++ b/hypha/core/interface.py @@ -189,10 +189,13 @@ def get_user_info_from_token(self, token): # if the same user id does not exist if user_info.id in self._all_users: user_info = self._all_users[user_info.id] - else: - self._all_users[user_info.id] = user_info return user_info + def add_user(self, user_info): + """Add a user.""" + if user_info.id not in self._all_users: + self._all_users[user_info.id] = user_info + def create_user_workspace(self, user_info, read_only: bool = False): """Create a workspace for the user.""" # only registered user can have persistent workspace diff --git a/hypha/server.py b/hypha/server.py index 4c3060fa..9164d19f 100644 --- a/hypha/server.py +++ b/hypha/server.py @@ -144,6 +144,7 @@ async def register_plugin(sid, config): user_info, event_bus, ) + core_interface.add_user(user_info) user_info.add_plugin(plugin) workspace.add_plugin(plugin) event_bus.emit( diff --git a/tests/test_server_apps.py b/tests/test_server_apps.py index 081a9d1c..9d8280db 100644 --- a/tests/test_server_apps.py +++ b/tests/test_server_apps.py @@ -196,9 +196,12 @@ async def test_non_persistent_workspace(socketio_server): response = requests.get(f"{SIO_SERVER_URL}/api/stats") assert response.status_code == 200 stats = response.json() - assert stats["plugin_count"] == 3 workspace_info = find_item(stats["workspaces"], "name", workspace) assert workspace_info is not None + count = 0 + for workspace in stats["workspaces"]: + count += len(workspace["plugins"]) + assert stats["plugin_count"] == count plugins = workspace_info["plugins"] assert find_item(plugins, "id", plugin.config["id"]) is not None @@ -208,6 +211,6 @@ async def test_non_persistent_workspace(socketio_server): response = requests.get(f"{SIO_SERVER_URL}/api/stats") assert response.status_code == 200 stats = response.json() - assert stats["plugin_count"] == 1 workspace_info = find_item(stats["workspaces"], "name", workspace) assert workspace_info is None + assert stats["plugin_count"] == count - 2