mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2026-01-02 20:08:19 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52273e2f8c | ||
|
|
bda867473c | ||
|
|
6885cdc439 | ||
|
|
88e25a93be |
@@ -30,4 +30,9 @@ pip install -r requirements.txt
|
|||||||
Run tests:
|
Run tests:
|
||||||
```bash
|
```bash
|
||||||
pytest
|
pytest
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
|
||||||
|
### 0.14
|
||||||
|
* Added required version parameter to Plugin constructor.
|
||||||
@@ -6,6 +6,7 @@ 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
|
||||||
@@ -22,9 +23,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
|
||||||
@@ -319,6 +321,8 @@ def _prepare_logging(logger_file):
|
|||||||
root = logging.getLogger()
|
root = logging.getLogger()
|
||||||
root.setLevel(logging.DEBUG)
|
root.setLevel(logging.DEBUG)
|
||||||
if logger_file:
|
if logger_file:
|
||||||
|
# ensure destination folder exists
|
||||||
|
os.makedirs(os.path.dirname(os.path.abspath(logger_file)), exist_ok=True)
|
||||||
handler = logging.handlers.RotatingFileHandler(
|
handler = logging.handlers.RotatingFileHandler(
|
||||||
logger_file,
|
logger_file,
|
||||||
mode="a",
|
mode="a",
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="galaxy.plugin.api",
|
name="galaxy.plugin.api",
|
||||||
version="0.12",
|
version="0.14",
|
||||||
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',
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -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 == []
|
||||||
|
|||||||
@@ -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])
|
||||||
|
|||||||
Reference in New Issue
Block a user