def test_player_send_json_rpc_request_throws_connection_closed(self): """Tests Player.send_json_rpc_request() when websocket send() throws a ConnectionClosed exception """ websocket = MagicMock() send = AsyncMock(side_effect=ConnectionClosed(0, 'Connection Closed')) websocket.attach_mock(send, 'send') player = Player(None, websocket) string = "Player is " + str([player]) params = dict() params['a'] = 'x' asyncio.run(player.send_json_rpc_request("general_request", params)) # No exception should propage as expected send.assert_called_once()
def test_player_send_json_rpc_request(self): """Tests that Player.send_json_rpc_request() calls websocket send() """ websocket = MagicMock() send = AsyncMock() websocket.attach_mock(send, 'send') player = Player(None, websocket) string = "Player is " + str([player]) params = dict() params['a'] = 'x' asyncio.run(player.send_json_rpc_request("general_request", params)) send.assert_called_once_with( '{"id": 1, "method": "general_request", "params": {"a": "x"}}')