Compare commits

...

28 Commits
0.13 ... 0.22

Author SHA1 Message Date
Romuald Juchnowicz-Bierbasz
92b1d8e4df SDK-2760: Fix paths 2019-04-16 11:02:56 +02:00
Romuald Juchnowicz-Bierbasz
4adef2dace SDK-2760: Move modules 2019-04-16 10:38:45 +02:00
Romuald Juchnowicz-Bierbasz
1430fe39d7 SDK-2760: Make galaxy namespace package 2019-04-16 10:33:05 +02:00
Romuald Juchnowicz-Bierbasz
c591efc493 Increment version 2019-04-16 10:27:07 +02:00
Romuald Juchnowicz-Bierbasz
7c4f3fba5b SDK-2760: Add mock module 2019-04-16 10:26:37 +02:00
Romuald Juchnowicz-Bierbasz
f2e2e41d04 SDK-2760: Add tools module 2019-04-16 10:24:32 +02:00
Romuald Juchnowicz-Bierbasz
25b850d8bb SDK-2760: Dlc list optional 2019-04-16 10:21:31 +02:00
Romuald Juchnowicz-Bierbasz
403736612a Increment version, add changelog 2019-04-12 13:52:47 +02:00
Romuald Juchnowicz-Bierbasz
3071c2e771 SDK-2760: Add Epic platform 2019-04-12 13:51:41 +02:00
Aliaksei Paulouski
23ef34bed5 Increment version 2019-04-06 15:02:06 +02:00
Aliaksei Paulouski
a4b08f8105 Add Cookies to NextStep 2019-04-06 15:02:01 +02:00
Romuald Bierbasz
4d62b8ccb8 SDK-2743: Remove logging setup 2019-04-05 14:24:14 +02:00
Aliaksei Paulouski
d759b4aa85 Increment version 2019-03-28 14:37:30 +01:00
Romuald Juchnowicz-Bierbasz
9b33397827 Add NextStep and pass_login_credentials 2019-03-28 10:20:16 +01:00
Romuald Juchnowicz-Bierbasz
e09e443064 Increment version 2019-03-27 15:15:25 +01:00
Romuald Juchnowicz-Bierbasz
00ed52384a Exclude tests from package 2019-03-27 15:14:29 +01:00
Aliaksei Paulouski
958d9bc0e6 Fix send_message message param name 2019-03-25 11:46:30 +01:00
Pawel Kierski
d73d048ff7 Increment version to 0.17 2019-03-12 16:10:23 +01:00
Aliaksei Paulouski
e06e40f845 Fix duplicated error code 2019-03-12 15:53:42 +01:00
Paweł Kierski
833e6999d7 Return JSON-RPC reponse on generic Exception 2019-03-12 15:38:22 +01:00
Paweł Kierski
ca778e2cdb SDK-2647 Serializing local game state as integer 2019-03-11 13:47:12 +01:00
Romuald Juchnowicz-Bierbasz
9a06428fc0 Remove log 2019-03-11 12:19:45 +01:00
Romuald Juchnowicz-Bierbasz
f9eaeaf726 Increment version, add changelog 2019-03-11 11:08:28 +01:00
Romuald Juchnowicz-Bierbasz
f09171672f SDK-2636: Do not log sensitive data 2019-03-11 11:07:31 +01:00
Romuald Juchnowicz-Bierbasz
ca8d0dfaf4 Increment version, add changelog 2019-03-08 10:19:43 +01:00
Romuald Juchnowicz-Bierbasz
73bc9aa8ec SDK-2623: Call shutdown on socket close 2019-03-08 10:16:57 +01:00
Romuald Juchnowicz-Bierbasz
52273e2f8c Increment veresion, add changelog 2019-03-07 13:19:37 +01:00
Romuald Juchnowicz-Bierbasz
bda867473c SDK-2627: Add version param to Plugin 2019-03-07 13:18:26 +01:00
14 changed files with 173 additions and 89 deletions

View File

@@ -30,4 +30,16 @@ pip install -r requirements.txt
Run tests: Run tests:
```bash ```bash
pytest pytest
``` ```
## Changelog
### 0.21
* Add `Epic` platform.
### 0.16
* Do not log sensitive data.
* Return `LocalGameState` as int (possible combination of flags).
### 0.15
* `shutdown()` is called on socket disconnection.
### 0.14
* Added required version parameter to Plugin constructor.

View File

@@ -1,4 +1,4 @@
from enum import Enum from enum import Enum, Flag
class Platform(Enum): class Platform(Enum):
Unknown = "unknown" Unknown = "unknown"
@@ -10,6 +10,7 @@ class Platform(Enum):
Origin = "origin" Origin = "origin"
Uplay = "uplay" Uplay = "uplay"
Battlenet = "battlenet" Battlenet = "battlenet"
Epic = "epic"
class Feature(Enum): class Feature(Enum):
Unknown = "Unknown" Unknown = "Unknown"
@@ -30,10 +31,10 @@ class LicenseType(Enum):
FreeToPlay = "FreeToPlay" FreeToPlay = "FreeToPlay"
OtherUserLicense = "OtherUserLicense" OtherUserLicense = "OtherUserLicense"
class LocalGameState(Enum): class LocalGameState(Flag):
None_ = "None" None_ = 0
Installed = "Installed" Installed = 1
Running = "Running" Running = 2
class PresenceState(Enum): class PresenceState(Enum):
Unknown = "Unknown" Unknown = "Unknown"

View File

@@ -1,8 +1,6 @@
from galaxy.api.jsonrpc import ApplicationError from galaxy.api.jsonrpc import ApplicationError, UnknownError
class UnknownError(ApplicationError): UnknownError = UnknownError
def __init__(self, data=None):
super().__init__(0, "Unknown error", data)
class AuthenticationRequired(ApplicationError): class AuthenticationRequired(ApplicationError):
def __init__(self, data=None): def __init__(self, data=None):

View File

@@ -1,5 +1,6 @@
import asyncio import asyncio
from collections import namedtuple from collections import namedtuple
from collections.abc import Iterable
import logging import logging
import json import json
@@ -24,7 +25,7 @@ class MethodNotFound(JsonRpcError):
class InvalidParams(JsonRpcError): class InvalidParams(JsonRpcError):
def __init__(self): def __init__(self):
super().__init__(-32601, "Invalid params") super().__init__(-32602, "Invalid params")
class Timeout(JsonRpcError): class Timeout(JsonRpcError):
def __init__(self): def __init__(self):
@@ -40,8 +41,26 @@ class ApplicationError(JsonRpcError):
raise ValueError("The error code in reserved range") raise ValueError("The error code in reserved range")
super().__init__(code, message, data) super().__init__(code, message, data)
class UnknownError(ApplicationError):
def __init__(self, data=None):
super().__init__(0, "Unknown error", data)
Request = namedtuple("Request", ["method", "params", "id"], defaults=[{}, None]) Request = namedtuple("Request", ["method", "params", "id"], defaults=[{}, None])
Method = namedtuple("Method", ["callback", "internal"]) Method = namedtuple("Method", ["callback", "internal", "sensitive_params"])
def anonymise_sensitive_params(params, sensitive_params):
anomized_data = "****"
if not sensitive_params:
return params
if isinstance(sensitive_params, Iterable):
anomized_params = params.copy()
for key in anomized_params.keys():
if key in sensitive_params:
anomized_params[key] = anomized_data
return anomized_params
return anomized_data
class Server(): class Server():
def __init__(self, reader, writer, encoder=json.JSONEncoder()): def __init__(self, reader, writer, encoder=json.JSONEncoder()):
@@ -53,11 +72,27 @@ class Server():
self._notifications = {} self._notifications = {}
self._eof_listeners = [] self._eof_listeners = []
def register_method(self, name, callback, internal): def register_method(self, name, callback, internal, sensitive_params=False):
self._methods[name] = Method(callback, internal) """
Register method
:param name:
:param callback:
:param internal: if True the callback will be processed immediately (synchronously)
:param sensitive_params: list of parameters that will by anonymized before logging; if False - no params
are considered sensitive, if True - all params are considered sensitive
"""
self._methods[name] = Method(callback, internal, sensitive_params)
def register_notification(self, name, callback, internal): def register_notification(self, name, callback, internal, sensitive_params=False):
self._notifications[name] = Method(callback, internal) """
Register notification
:param name:
:param callback:
:param internal: if True the callback will be processed immediately (synchronously)
:param sensitive_params: list of parameters that will by anonymized before logging; if False - no params
are considered sensitive, if True - all params are considered sensitive
"""
self._notifications[name] = Method(callback, internal, sensitive_params)
def register_eof(self, callback): def register_eof(self, callback):
self._eof_listeners.append(callback) self._eof_listeners.append(callback)
@@ -73,7 +108,7 @@ class Server():
self._eof() self._eof()
continue continue
data = data.strip() data = data.strip()
logging.debug("Received data: %s", data) logging.debug("Received %d bytes of data", len(data))
self._handle_input(data) self._handle_input(data)
def stop(self): def stop(self):
@@ -92,43 +127,39 @@ class Server():
self._send_error(None, error) self._send_error(None, error)
return return
logging.debug("Parsed input: %s", request)
if request.id is not None: if request.id is not None:
self._handle_request(request) self._handle_request(request)
else: else:
self._handle_notification(request) self._handle_notification(request)
def _handle_notification(self, request): def _handle_notification(self, request):
logging.debug("Handling notification %s", request)
method = self._notifications.get(request.method) method = self._notifications.get(request.method)
if not method: if not method:
logging.error("Received uknown notification: %s", request.method) logging.error("Received unknown notification: %s", request.method)
return return
callback, internal = method callback, internal, sensitive_params = method
self._log_request(request, sensitive_params)
if internal: if internal:
# internal requests are handled immediately # internal requests are handled immediately
callback(**request.params) callback(**request.params)
else: else:
try: try:
asyncio.create_task(callback(**request.params)) asyncio.create_task(callback(**request.params))
except Exception as error: #pylint: disable=broad-except except Exception:
logging.error( logging.exception("Unexpected exception raised in notification handler")
"Unexpected exception raised in notification handler: %s",
repr(error)
)
def _handle_request(self, request): def _handle_request(self, request):
logging.debug("Handling request %s", request)
method = self._methods.get(request.method) method = self._methods.get(request.method)
if not method: if not method:
logging.error("Received uknown request: %s", request.method) logging.error("Received unknown request: %s", request.method)
self._send_error(request.id, MethodNotFound()) self._send_error(request.id, MethodNotFound())
return return
callback, internal = method callback, internal, sensitive_params = method
self._log_request(request, sensitive_params)
if internal: if internal:
# internal requests are handled immediately # internal requests are handled immediately
response = callback(request.params) response = callback(request.params)
@@ -144,8 +175,9 @@ class Server():
self._send_error(request.id, MethodNotFound()) self._send_error(request.id, MethodNotFound())
except JsonRpcError as error: except JsonRpcError as error:
self._send_error(request.id, error) self._send_error(request.id, error)
except Exception: #pylint: disable=broad-except except Exception as e: #pylint: disable=broad-except
logging.exception("Unexpected exception raised in plugin handler") logging.exception("Unexpected exception raised in plugin handler")
self._send_error(request.id, UnknownError(str(e)))
asyncio.create_task(handle()) asyncio.create_task(handle())
@@ -166,7 +198,8 @@ class Server():
try: try:
line = self._encoder.encode(data) line = self._encoder.encode(data)
logging.debug("Sending data: %s", line) logging.debug("Sending data: %s", line)
self._writer.write((line + "\n").encode("utf-8")) data = (line + "\n").encode("utf-8")
self._writer.write(data)
asyncio.create_task(self._writer.drain()) asyncio.create_task(self._writer.drain())
except TypeError as error: except TypeError as error:
logging.error(str(error)) logging.error(str(error))
@@ -194,25 +227,47 @@ class Server():
self._send(response) self._send(response)
@staticmethod
def _log_request(request, sensitive_params):
params = anonymise_sensitive_params(request.params, sensitive_params)
if request.id is not None:
logging.info("Handling request: id=%s, method=%s, params=%s", request.id, request.method, params)
else:
logging.info("Handling notification: method=%s, params=%s", request.method, params)
class NotificationClient(): class NotificationClient():
def __init__(self, writer, encoder=json.JSONEncoder()): def __init__(self, writer, encoder=json.JSONEncoder()):
self._writer = writer self._writer = writer
self._encoder = encoder self._encoder = encoder
self._methods = {} self._methods = {}
def notify(self, method, params): def notify(self, method, params, sensitive_params=False):
"""
Send notification
:param method:
:param params:
:param sensitive_params: list of parameters that will by anonymized before logging; if False - no params
are considered sensitive, if True - all params are considered sensitive
"""
notification = { notification = {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"method": method, "method": method,
"params": params "params": params
} }
self._log(method, params, sensitive_params)
self._send(notification) self._send(notification)
def _send(self, data): def _send(self, data):
try: try:
line = self._encoder.encode(data) line = self._encoder.encode(data)
logging.debug("Sending data: %s", line) data = (line + "\n").encode("utf-8")
self._writer.write((line + "\n").encode("utf-8")) logging.debug("Sending %d byte of data", len(data))
self._writer.write(data)
asyncio.create_task(self._writer.drain()) asyncio.create_task(self._writer.drain())
except TypeError as error: except TypeError as error:
logging.error("Failed to parse outgoing message: %s", str(error)) logging.error("Failed to parse outgoing message: %s", str(error))
@staticmethod
def _log(method, params, sensitive_params):
params = anonymise_sensitive_params(params, sensitive_params)
logging.info("Sending notification: method=%s, params=%s", method, params)

View File

@@ -6,7 +6,6 @@ import dataclasses
from enum import Enum from enum import Enum
from collections import OrderedDict from collections import OrderedDict
import sys import sys
import os
from galaxy.api.jsonrpc import Server, NotificationClient from galaxy.api.jsonrpc import Server, NotificationClient
from galaxy.api.consts import Feature from galaxy.api.consts import Feature
@@ -23,9 +22,10 @@ class JSONEncoder(json.JSONEncoder):
return super().default(o) return super().default(o)
class Plugin(): class Plugin():
def __init__(self, platform, reader, writer, handshake_token): def __init__(self, platform, version, reader, writer, handshake_token):
logging.info("Creating plugin for platform %s", platform.value) logging.info("Creating plugin for platform %s, version %s", platform.value, version)
self._platform = platform self._platform = platform
self._version = version
self._feature_methods = OrderedDict() self._feature_methods = OrderedDict()
self._active = True self._active = True
@@ -38,7 +38,7 @@ class Plugin():
self._notification_client = NotificationClient(self._writer, encoder) self._notification_client = NotificationClient(self._writer, encoder)
def eof_handler(): def eof_handler():
self._active = False self._shutdown()
self._server.register_eof(eof_handler) self._server.register_eof(eof_handler)
# internal # internal
@@ -47,7 +47,8 @@ class Plugin():
self._register_method("ping", self._ping, internal=True) self._register_method("ping", self._ping, internal=True)
# implemented by developer # implemented by developer
self._register_method("init_authentication", self.authenticate) self._register_method("init_authentication", self.authenticate, sensitive_params=["stored_credentials"])
self._register_method("pass_login_credentials", self.pass_login_credentials)
self._register_method( self._register_method(
"import_owned_games", "import_owned_games",
self.get_owned_games, self.get_owned_games,
@@ -137,7 +138,7 @@ class Plugin():
return False return False
return True return True
def _register_method(self, name, handler, result_name=None, internal=False, feature=None): def _register_method(self, name, handler, result_name=None, internal=False, sensitive_params=False, feature=None):
if internal: if internal:
def method(params): def method(params):
result = handler(**params) result = handler(**params)
@@ -146,7 +147,7 @@ class Plugin():
result_name: result result_name: result
} }
return result return result
self._server.register_method(name, method, True) self._server.register_method(name, method, True, sensitive_params)
else: else:
async def method(params): async def method(params):
result = await handler(**params) result = await handler(**params)
@@ -155,13 +156,13 @@ class Plugin():
result_name: result result_name: result
} }
return result return result
self._server.register_method(name, method, False) self._server.register_method(name, method, False, sensitive_params)
if feature is not None: if feature is not None:
self._feature_methods.setdefault(feature, []).append(handler) self._feature_methods.setdefault(feature, []).append(handler)
def _register_notification(self, name, handler, internal=False, feature=None): def _register_notification(self, name, handler, internal=False, sensitive_params=False, feature=None):
self._server.register_notification(name, handler, internal) self._server.register_notification(name, handler, internal, sensitive_params)
if feature is not None: if feature is not None:
self._feature_methods.setdefault(feature, []).append(handler) self._feature_methods.setdefault(feature, []).append(handler)
@@ -170,7 +171,6 @@ class Plugin():
"""Plugin main coorutine""" """Plugin main coorutine"""
async def pass_control(): async def pass_control():
while self._active: while self._active:
logging.debug("Passing control to plugin")
try: try:
self.tick() self.tick()
except Exception: except Exception:
@@ -201,7 +201,7 @@ class Plugin():
"""Notify client to store plugin credentials. """Notify client to store plugin credentials.
They will be pass to next authencicate calls. They will be pass to next authencicate calls.
""" """
self._notification_client.notify("store_credentials", credentials) self._notification_client.notify("store_credentials", credentials, sensitive_params=True)
def add_game(self, game): def add_game(self, game):
params = {"owned_game" : game} params = {"owned_game" : game}
@@ -274,6 +274,9 @@ class Plugin():
""" """
raise NotImplementedError() raise NotImplementedError()
async def pass_login_credentials(self, step, credentials, cookies):
raise NotImplementedError()
async def get_owned_games(self): async def get_owned_games(self):
raise NotImplementedError() raise NotImplementedError()
@@ -298,7 +301,7 @@ class Plugin():
async def get_users(self, user_id_list): async def get_users(self, user_id_list):
raise NotImplementedError() raise NotImplementedError()
async def send_message(self, room_id, message): async def send_message(self, room_id, message_text):
raise NotImplementedError() raise NotImplementedError()
async def mark_as_read(self, room_id, last_message_id): async def mark_as_read(self, room_id, last_message_id):
@@ -316,29 +319,7 @@ class Plugin():
async def get_game_times(self): async def get_game_times(self):
raise NotImplementedError() raise NotImplementedError()
def _prepare_logging(logger_file):
root = logging.getLogger()
root.setLevel(logging.DEBUG)
if logger_file:
# ensure destination folder exists
os.makedirs(os.path.dirname(os.path.abspath(logger_file)), exist_ok=True)
handler = logging.handlers.RotatingFileHandler(
logger_file,
mode="a",
maxBytes=10000000,
backupCount=10,
encoding="utf-8"
)
else:
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
def create_and_run_plugin(plugin_class, argv): def create_and_run_plugin(plugin_class, argv):
logger_file = argv[3] if len(argv) >= 4 else None
_prepare_logging(logger_file)
if len(argv) < 3: if len(argv) < 3:
logging.critical("Not enough parameters, required: token, port") logging.critical("Not enough parameters, required: token, port")
sys.exit(1) sys.exit(1)

View File

@@ -1,5 +1,5 @@
from dataclasses import dataclass from dataclasses import dataclass
from typing import List, Optional from typing import List, Dict, Optional
from galaxy.api.consts import LicenseType, LocalGameState, PresenceState from galaxy.api.consts import LicenseType, LocalGameState, PresenceState
@@ -8,6 +8,19 @@ class Authentication():
user_id: str user_id: str
user_name: str user_name: str
@dataclass
class Cookie():
name: str
value: str
domain: Optional[str] = None
path: Optional[str] = None
@dataclass
class NextStep():
next_step: str
auth_params: Dict[str, str]
cookies: Optional[List[Cookie]] = None
@dataclass @dataclass
class LicenseInfo(): class LicenseInfo():
license_type: LicenseType license_type: LicenseType
@@ -23,7 +36,7 @@ class Dlc():
class Game(): class Game():
game_id: str game_id: str
game_title: str game_title: str
dlcs: List[Dlc] dlcs: Optional[List[Dlc]]
license_info: LicenseInfo license_info: LicenseInfo
@dataclass @dataclass

20
galaxy/tools.py Normal file
View File

@@ -0,0 +1,20 @@
import io
import os
import zipfile
from glob import glob
def zip_folder(folder):
files = glob(os.path.join(folder, "**"), recursive=True)
files = [file.replace(folder + os.sep, "") for file in files]
files = [file for file in files if file]
zip_buffer = io.BytesIO()
with zipfile.ZipFile(zip_buffer, mode="w", compression=zipfile.ZIP_DEFLATED) as zipf:
for file in files:
zipf.write(os.path.join(folder, file), arcname=file)
return zip_buffer
def zip_folder_to_file(folder, filename):
zip_content = zip_folder(folder).getbuffer()
with open(filename, "wb") as archive:
archive.write(zip_content)

View File

@@ -2,5 +2,4 @@ from unittest.mock import MagicMock
class AsyncMock(MagicMock): class AsyncMock(MagicMock):
async def __call__(self, *args, **kwargs): async def __call__(self, *args, **kwargs):
# pylint: disable=useless-super-delegation
return super(AsyncMock, self).__call__(*args, **kwargs) return super(AsyncMock, self).__call__(*args, **kwargs)

View File

@@ -2,9 +2,9 @@ from setuptools import setup, find_packages
setup( setup(
name="galaxy.plugin.api", name="galaxy.plugin.api",
version="0.13", version="0.22",
description="Galaxy python plugin API", description="Galaxy python plugin API",
author='Galaxy team', author='Galaxy team',
author_email='galaxy@gog.com', author_email='galaxy@gog.com',
packages=find_packages() packages=find_packages(exclude=["tests"])
) )

View File

@@ -6,7 +6,7 @@ import pytest
from galaxy.api.plugin import Plugin from galaxy.api.plugin import Plugin
from galaxy.api.consts import Platform from galaxy.api.consts import Platform
from tests.async_mock import AsyncMock from galaxy.unittest.mock import AsyncMock
@pytest.fixture() @pytest.fixture()
def reader(): def reader():
@@ -60,7 +60,7 @@ def plugin(reader, writer):
stack.enter_context(patch.object(Plugin, method, new_callable=AsyncMock)) stack.enter_context(patch.object(Plugin, method, new_callable=AsyncMock))
for method in methods: for method in methods:
stack.enter_context(patch.object(Plugin, method)) stack.enter_context(patch.object(Plugin, method))
yield Plugin(Platform.Generic, reader, writer, "token") yield Plugin(Platform.Generic, "0.1", reader, writer, "token")
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def my_caplog(caplog): def my_caplog(caplog):

View File

@@ -2,14 +2,14 @@ from galaxy.api.plugin import Plugin
from galaxy.api.consts import Platform, Feature from galaxy.api.consts import Platform, Feature
def test_base_class(): def test_base_class():
plugin = Plugin(Platform.Generic, None, None, None) plugin = Plugin(Platform.Generic, "0.1", None, None, None)
assert plugin.features == [] assert plugin.features == []
def test_no_overloads(): def test_no_overloads():
class PluginImpl(Plugin): #pylint: disable=abstract-method class PluginImpl(Plugin): #pylint: disable=abstract-method
pass pass
plugin = PluginImpl(Platform.Generic, None, None, None) plugin = PluginImpl(Platform.Generic, "0.1", None, None, None)
assert plugin.features == [] assert plugin.features == []
def test_one_method_feature(): def test_one_method_feature():
@@ -17,7 +17,7 @@ def test_one_method_feature():
async def get_owned_games(self): async def get_owned_games(self):
pass pass
plugin = PluginImpl(Platform.Generic, None, None, None) plugin = PluginImpl(Platform.Generic, "0.1", None, None, None)
assert plugin.features == [Feature.ImportOwnedGames] assert plugin.features == [Feature.ImportOwnedGames]
def test_multiple_methods_feature_all(): def test_multiple_methods_feature_all():
@@ -33,7 +33,7 @@ def test_multiple_methods_feature_all():
async def get_room_history_from_timestamp(self, room_id, timestamp): async def get_room_history_from_timestamp(self, room_id, timestamp):
pass pass
plugin = PluginImpl(Platform.Generic, None, None, None) plugin = PluginImpl(Platform.Generic, "0.1", None, None, None)
assert plugin.features == [Feature.Chat] assert plugin.features == [Feature.Chat]
def test_multiple_methods_feature_not_all(): def test_multiple_methods_feature_not_all():
@@ -41,5 +41,5 @@ def test_multiple_methods_feature_not_all():
async def send_message(self, room_id, message): async def send_message(self, room_id, message):
pass pass
plugin = PluginImpl(Platform.Generic, None, None, None) plugin = PluginImpl(Platform.Generic, "0.1", None, None, None)
assert plugin.features == [] assert plugin.features == []

View File

@@ -15,7 +15,7 @@ def test_get_capabilites(reader, writer, readline, write):
"method": "get_capabilities" "method": "get_capabilities"
} }
token = "token" token = "token"
plugin = PluginImpl(Platform.Generic, reader, writer, token) plugin = PluginImpl(Platform.Generic, "0.1", reader, writer, token)
readline.side_effect = [json.dumps(request), ""] readline.side_effect = [json.dumps(request), ""]
asyncio.run(plugin.run()) asyncio.run(plugin.run())
response = json.loads(write.call_args[0][0]) response = json.loads(write.call_args[0][0])

View File

@@ -17,8 +17,9 @@ def test_success(plugin, readline, write):
readline.side_effect = [json.dumps(request), ""] readline.side_effect = [json.dumps(request), ""]
plugin.get_local_games.return_value = [ plugin.get_local_games.return_value = [
LocalGame("1", "Running"), LocalGame("1", LocalGameState.Running),
LocalGame("2", "Installed") LocalGame("2", LocalGameState.Installed),
LocalGame("3", LocalGameState.Installed | LocalGameState.Running)
] ]
asyncio.run(plugin.run()) asyncio.run(plugin.run())
plugin.get_local_games.assert_called_with() plugin.get_local_games.assert_called_with()
@@ -31,11 +32,15 @@ def test_success(plugin, readline, write):
"local_games" : [ "local_games" : [
{ {
"game_id": "1", "game_id": "1",
"local_game_state": "Running" "local_game_state": LocalGameState.Running.value
}, },
{ {
"game_id": "2", "game_id": "2",
"local_game_state": "Installed" "local_game_state": LocalGameState.Installed.value
},
{
"game_id": "3",
"local_game_state": (LocalGameState.Installed | LocalGameState.Running).value
} }
] ]
} }
@@ -85,7 +90,7 @@ def test_local_game_state_update(plugin, write):
"params": { "params": {
"local_game": { "local_game": {
"game_id": "1", "game_id": "1",
"local_game_state": "Running" "local_game_state": LocalGameState.Running.value
} }
} }
} }