import asyncio
import json
-import mock
-import pytest
from collections import deque
+import mock
+from juju.client.connection import Connection
from websockets.exceptions import ConnectionClosed
+import pytest
+
from .. import base
-from juju.client.connection import Connection
class WebsocketMock:
@pytest.mark.asyncio
async def test_out_of_order(event_loop):
- con = Connection(*[None]*4)
ws = WebsocketMock([
{'request-id': 1},
{'request-id': 3},
{'request-id': 2},
{'request-id': 3},
]
- con._get_sll = mock.MagicMock()
+ minimal_facades = [{'name': 'Pinger', 'versions': [1]}]
+ con = None
try:
- with mock.patch('websockets.connect', base.AsyncMock(return_value=ws)):
- await con.open()
+ with \
+ mock.patch('websockets.connect', base.AsyncMock(return_value=ws)), \
+ mock.patch(
+ 'juju.client.connection.Connection.login',
+ base.AsyncMock(return_value={'response': {
+ 'facades': minimal_facades,
+ }}),
+ ), \
+ mock.patch('juju.client.connection.Connection._get_ssl'), \
+ mock.patch('juju.client.connection.Connection._pinger', base.AsyncMock()):
+ con = await Connection.connect('0.1.2.3:999')
actual_responses = []
for i in range(3):
actual_responses.append(await con.rpc({'version': 1}))
assert actual_responses == expected_responses
finally:
- await con.close()
+ if con:
+ await con.close()