mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2026-01-03 12:28:14 -05:00
Compare commits
2 Commits
0.37
...
deployed_0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
692bdbf370 | ||
|
|
207b1e1313 |
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.37",
|
version="0.38",
|
||||||
description="GOG Galaxy Integrations Python API",
|
description="GOG Galaxy Integrations Python API",
|
||||||
author='Galaxy team',
|
author='Galaxy team',
|
||||||
author_email='galaxy@gog.com',
|
author_email='galaxy@gog.com',
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ class Server():
|
|||||||
self._notifications = {}
|
self._notifications = {}
|
||||||
self._eof_listeners = []
|
self._eof_listeners = []
|
||||||
self._input_buffer = bytes()
|
self._input_buffer = bytes()
|
||||||
|
self._input_buffer_it = 0
|
||||||
|
|
||||||
def register_method(self, name, callback, internal, sensitive_params=False):
|
def register_method(self, name, callback, internal, sensitive_params=False):
|
||||||
"""
|
"""
|
||||||
@@ -120,15 +121,17 @@ class Server():
|
|||||||
"""Like StreamReader.readline but without limit"""
|
"""Like StreamReader.readline but without limit"""
|
||||||
while True:
|
while True:
|
||||||
chunk = await self._reader.read(1024)
|
chunk = await self._reader.read(1024)
|
||||||
if not chunk:
|
|
||||||
return chunk
|
|
||||||
previous_size = len(self._input_buffer)
|
|
||||||
self._input_buffer += chunk
|
self._input_buffer += chunk
|
||||||
it = self._input_buffer.find(b"\n", previous_size)
|
it = self._input_buffer.find(b"\n", self._input_buffer_it)
|
||||||
if it < 0:
|
if it < 0:
|
||||||
continue
|
if not chunk:
|
||||||
|
return bytes() # EOF
|
||||||
|
else:
|
||||||
|
self._input_buffer_it = len(self._input_buffer)
|
||||||
|
continue
|
||||||
line = self._input_buffer[:it]
|
line = self._input_buffer[:it]
|
||||||
self._input_buffer = self._input_buffer[it+1:]
|
self._input_buffer = self._input_buffer[it+1:]
|
||||||
|
self._input_buffer_it = 0
|
||||||
return line
|
return line
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
|||||||
@@ -12,6 +12,43 @@ def test_chunked_messages(plugin, read):
|
|||||||
|
|
||||||
message = json.dumps(request).encode() + b"\n"
|
message = json.dumps(request).encode() + b"\n"
|
||||||
read.side_effect = [message[:5], message[5:], b""]
|
read.side_effect = [message[:5], message[5:], b""]
|
||||||
plugin.get_owned_games.return_value = None
|
|
||||||
asyncio.run(plugin.run())
|
asyncio.run(plugin.run())
|
||||||
plugin.install_game.assert_called_with(game_id="3")
|
plugin.install_game.assert_called_with(game_id="3")
|
||||||
|
|
||||||
|
def test_joined_messages(plugin, read):
|
||||||
|
requests = [
|
||||||
|
{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "install_game",
|
||||||
|
"params": {
|
||||||
|
"game_id": "3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "launch_game",
|
||||||
|
"params": {
|
||||||
|
"game_id": "3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
data = b"".join([json.dumps(request).encode() + b"\n" for request in requests])
|
||||||
|
|
||||||
|
read.side_effect = [data, b""]
|
||||||
|
asyncio.run(plugin.run())
|
||||||
|
plugin.install_game.assert_called_with(game_id="3")
|
||||||
|
plugin.launch_game.assert_called_with(game_id="3")
|
||||||
|
|
||||||
|
def test_not_finished(plugin, read):
|
||||||
|
request = {
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "install_game",
|
||||||
|
"params": {
|
||||||
|
"game_id": "3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message = json.dumps(request).encode() # no new line
|
||||||
|
read.side_effect = [message, b""]
|
||||||
|
asyncio.run(plugin.run())
|
||||||
|
plugin.install_game.assert_not_called()
|
||||||
|
|||||||
Reference in New Issue
Block a user