From ce193f39bc8662c6c9c3fba9c6f40f95d7280919 Mon Sep 17 00:00:00 2001 From: Romuald Bierbasz Date: Wed, 17 Jul 2019 15:27:27 +0200 Subject: [PATCH] SDK-2933: Add shutdown_client notification --- src/galaxy/api/consts.py | 1 + src/galaxy/api/plugin.py | 10 ++++++++++ tests/conftest.py | 3 ++- tests/test_shutdown_platform_client.py | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/test_shutdown_platform_client.py diff --git a/src/galaxy/api/consts.py b/src/galaxy/api/consts.py index d006714..437f293 100644 --- a/src/galaxy/api/consts.py +++ b/src/galaxy/api/consts.py @@ -98,6 +98,7 @@ class Feature(Enum): ImportUsers = "ImportUsers" VerifyGame = "VerifyGame" ImportFriends = "ImportFriends" + ShutdownPlatformClient = "ShutdownPlatformClient" class LicenseType(Enum): diff --git a/src/galaxy/api/plugin.py b/src/galaxy/api/plugin.py index bfa1d75..34898dc 100644 --- a/src/galaxy/api/plugin.py +++ b/src/galaxy/api/plugin.py @@ -107,6 +107,11 @@ class Plugin: self.uninstall_game, feature=Feature.UninstallGame ) + self._register_notification( + "shutdown_platform_client", + self.shutdown_platform_client, + feature=Feature.ShutdownPlatformClient + ) self._register_method( "import_friends", self.get_friends, @@ -718,6 +723,11 @@ class Plugin: """ raise NotImplementedError() + async def shutdown_platform_client(self) -> None: + """Override this method to gracefully terminate platform client. + This method is called by the GOG Galaxy Client.""" + raise NotImplementedError() + async def get_friends(self) -> List[FriendInfo]: """Override this method to return the friends list of the currently authenticated user. diff --git a/tests/conftest.py b/tests/conftest.py index d94a9f3..0f2fe22 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -48,7 +48,8 @@ def plugin(reader, writer): "get_rooms", "get_room_history_from_message", "get_room_history_from_timestamp", - "get_game_times" + "get_game_times", + "shutdown_platform_client" ) methods = ( diff --git a/tests/test_shutdown_platform_client.py b/tests/test_shutdown_platform_client.py new file mode 100644 index 0000000..e6e8eeb --- /dev/null +++ b/tests/test_shutdown_platform_client.py @@ -0,0 +1,15 @@ +import json + +import pytest + +@pytest.mark.asyncio +async def test_success(plugin, read): + request = { + "jsonrpc": "2.0", + "method": "shutdown_platform_client" + } + + read.side_effect = [json.dumps(request).encode() + b"\n", b""] + plugin.shutdown_platform_client.return_value = None + await plugin.run() + plugin.shutdown_platform_client.assert_called_with()