SDK-2880: Fix readline

This commit is contained in:
Romuald Juchnowicz-Bierbasz
2019-06-26 12:02:25 +02:00
parent 05042fe430
commit 207b1e1313
2 changed files with 46 additions and 6 deletions

View File

@@ -12,6 +12,43 @@ def test_chunked_messages(plugin, read):
message = json.dumps(request).encode() + b"\n"
read.side_effect = [message[:5], message[5:], b""]
plugin.get_owned_games.return_value = None
asyncio.run(plugin.run())
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()