New N2VC interface + updated libjuju
[osm/N2VC.git] / modules / libjuju / tests / unit / test_connection.py
index f69b8d6..0925d84 100644 (file)
@@ -1,13 +1,14 @@
 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:
@@ -31,7 +32,6 @@ 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},
@@ -42,13 +42,24 @@ async def test_out_of_order(event_loop):
         {'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()