mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2026-05-19 03:54:40 -04:00
SDK-2521 switch plugin transport to sockets
This commit is contained in:
committed by
Romuald Bierbasz
parent
853ecf1d3b
commit
70a1d5cd1f
@@ -1,16 +1,36 @@
|
||||
from contextlib import ExitStack
|
||||
import logging
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from galaxy.api.plugin import Plugin
|
||||
from galaxy.api.stream import StdinReader, StdoutWriter
|
||||
from galaxy.api.consts import Platform
|
||||
from tests.async_mock import AsyncMock
|
||||
|
||||
@pytest.fixture()
|
||||
def plugin():
|
||||
def reader():
|
||||
stream = MagicMock(name="stream_reader")
|
||||
stream.readline = AsyncMock()
|
||||
yield stream
|
||||
|
||||
@pytest.fixture()
|
||||
def writer():
|
||||
stream = MagicMock(name="stream_writer")
|
||||
stream.write = MagicMock()
|
||||
stream.drain = AsyncMock()
|
||||
yield stream
|
||||
|
||||
@pytest.fixture()
|
||||
def readline(reader):
|
||||
yield reader.readline
|
||||
|
||||
@pytest.fixture()
|
||||
def write(writer):
|
||||
yield writer.write
|
||||
|
||||
@pytest.fixture()
|
||||
def plugin(reader, writer):
|
||||
"""Return plugin instance with all feature methods mocked"""
|
||||
async_methods = (
|
||||
"authenticate",
|
||||
@@ -40,17 +60,7 @@ def plugin():
|
||||
stack.enter_context(patch.object(Plugin, method, new_callable=AsyncMock))
|
||||
for method in methods:
|
||||
stack.enter_context(patch.object(Plugin, method))
|
||||
yield Plugin(Platform.Generic)
|
||||
|
||||
@pytest.fixture()
|
||||
def readline():
|
||||
with patch.object(StdinReader, "readline", new_callable=AsyncMock) as mock:
|
||||
yield mock
|
||||
|
||||
@pytest.fixture()
|
||||
def write():
|
||||
with patch.object(StdoutWriter, "write") as mock:
|
||||
yield mock
|
||||
yield Plugin(Platform.Generic, reader, writer, "token")
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def my_caplog(caplog):
|
||||
|
||||
@@ -2,14 +2,14 @@ from galaxy.api.plugin import Plugin
|
||||
from galaxy.api.consts import Platform, Feature
|
||||
|
||||
def test_base_class():
|
||||
plugin = Plugin(Platform.Generic)
|
||||
plugin = Plugin(Platform.Generic, None, None, None)
|
||||
assert plugin.features == []
|
||||
|
||||
def test_no_overloads():
|
||||
class PluginImpl(Plugin): #pylint: disable=abstract-method
|
||||
pass
|
||||
|
||||
plugin = PluginImpl(Platform.Generic)
|
||||
plugin = PluginImpl(Platform.Generic, None, None, None)
|
||||
assert plugin.features == []
|
||||
|
||||
def test_one_method_feature():
|
||||
@@ -17,7 +17,7 @@ def test_one_method_feature():
|
||||
async def get_owned_games(self):
|
||||
pass
|
||||
|
||||
plugin = PluginImpl(Platform.Generic)
|
||||
plugin = PluginImpl(Platform.Generic, None, None, None)
|
||||
assert plugin.features == [Feature.ImportOwnedGames]
|
||||
|
||||
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):
|
||||
pass
|
||||
|
||||
plugin = PluginImpl(Platform.Generic)
|
||||
plugin = PluginImpl(Platform.Generic, None, None, None)
|
||||
assert plugin.features == [Feature.Chat]
|
||||
|
||||
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):
|
||||
pass
|
||||
|
||||
plugin = PluginImpl(Platform.Generic)
|
||||
plugin = PluginImpl(Platform.Generic, None, None, None)
|
||||
assert plugin.features == []
|
||||
|
||||
@@ -4,7 +4,7 @@ import json
|
||||
from galaxy.api.plugin import Plugin
|
||||
from galaxy.api.consts import Platform
|
||||
|
||||
def test_get_capabilites(readline, write):
|
||||
def test_get_capabilites(reader, writer, readline, write):
|
||||
class PluginImpl(Plugin): #pylint: disable=abstract-method
|
||||
async def get_owned_games(self):
|
||||
pass
|
||||
@@ -14,7 +14,8 @@ def test_get_capabilites(readline, write):
|
||||
"id": "3",
|
||||
"method": "get_capabilities"
|
||||
}
|
||||
plugin = PluginImpl(Platform.Generic)
|
||||
token = "token"
|
||||
plugin = PluginImpl(Platform.Generic, reader, writer, token)
|
||||
readline.side_effect = [json.dumps(request), ""]
|
||||
asyncio.run(plugin.run())
|
||||
response = json.loads(write.call_args[0][0])
|
||||
@@ -25,7 +26,8 @@ def test_get_capabilites(readline, write):
|
||||
"platform_name": "generic",
|
||||
"features": [
|
||||
"ImportOwnedGames"
|
||||
]
|
||||
],
|
||||
"token": token
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user