mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-26 00:38:10 +00:00
Test compute notifications and run tests on macOS and Windows.
This commit is contained in:
parent
6af8c8933e
commit
596ee9b66d
3
.github/workflows/testing.yml
vendored
3
.github/workflows/testing.yml
vendored
@ -13,7 +13,8 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [3.6, 3.7, 3.8]
|
python-version: [3.6, 3.7, 3.8]
|
||||||
|
@ -22,22 +22,9 @@ sys.original_platform = sys.platform
|
|||||||
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from gns3server.app import app
|
from gns3server.app import app
|
||||||
|
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
|
|
||||||
|
|
||||||
# @pytest.fixture
|
|
||||||
# async def client(controller):
|
|
||||||
#
|
|
||||||
# async with AsyncClient(app=app, base_url="http://test") as ac:
|
|
||||||
# response = await ac.get("/")
|
|
||||||
#
|
|
||||||
# assert response.status_code == 200
|
|
||||||
# assert response.json() == {"message": "Tomato"}
|
|
||||||
#
|
|
||||||
# return TestClient(app)
|
|
||||||
|
|
||||||
|
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
@pytest.yield_fixture(scope="session")
|
@pytest.yield_fixture(scope="session")
|
||||||
def loop(request):
|
def loop(request):
|
||||||
@ -55,6 +42,12 @@ def http_client():
|
|||||||
return AsyncClient(app=app, base_url="http://test-api")
|
return AsyncClient(app=app, base_url="http://test-api")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def ws_client():
|
||||||
|
|
||||||
|
return TestClient(app)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def controller_config_path(tmpdir):
|
def controller_config_path(tmpdir):
|
||||||
|
|
||||||
@ -96,21 +89,21 @@ def compute_project(tmpdir):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def compute_api(http_client):
|
def compute_api(http_client, ws_client):
|
||||||
"""
|
"""
|
||||||
Return an helper allowing you to call the hypervisor API via HTTP
|
Return an helper allowing you to call the hypervisor API via HTTP
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return Query(http_client, prefix="/compute", api_version=2)
|
return Query(http_client, ws_client, prefix="/compute", api_version=2)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def controller_api(http_client, controller):
|
def controller_api(http_client, ws_client, controller):
|
||||||
"""
|
"""
|
||||||
Return an helper allowing you to call the server API without any prefix
|
Return an helper allowing you to call the server API without any prefix
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return Query(http_client, api_version=2)
|
return Query(http_client, ws_client, api_version=2)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -28,13 +28,14 @@ class Query:
|
|||||||
Helper to make queries against the test server
|
Helper to make queries against the test server
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, http_client, prefix='', api_version=None):
|
def __init__(self, http_client, ws_client, prefix='', api_version=None):
|
||||||
"""
|
"""
|
||||||
:param prefix: Prefix added before path (ex: /compute)
|
:param prefix: Prefix added before path (ex: /compute)
|
||||||
:param api_version: Version of the API
|
:param api_version: Version of the API
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._http_client = http_client
|
self._http_client = http_client
|
||||||
|
self._ws_client = ws_client
|
||||||
self._prefix = prefix
|
self._prefix = prefix
|
||||||
self._api_version = api_version
|
self._api_version = api_version
|
||||||
|
|
||||||
@ -53,6 +54,10 @@ class Query:
|
|||||||
def patch(self, path, **kwargs):
|
def patch(self, path, **kwargs):
|
||||||
return self._request("PATCH", path, **kwargs)
|
return self._request("PATCH", path, **kwargs)
|
||||||
|
|
||||||
|
def ws(self, path):
|
||||||
|
|
||||||
|
return self._ws_client.websocket_connect(self.get_url(path))
|
||||||
|
|
||||||
def get_url(self, path):
|
def get_url(self, path):
|
||||||
|
|
||||||
if self._api_version is None:
|
if self._api_version is None:
|
||||||
|
@ -21,20 +21,18 @@ import json
|
|||||||
from gns3server.compute.notification_manager import NotificationManager
|
from gns3server.compute.notification_manager import NotificationManager
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
# async def test_notification_ws(compute_api, http_client):
|
async def test_notification_ws(compute_api):
|
||||||
#
|
|
||||||
# ws = await http_client.ws_connect(compute_api.get_url("/notifications/ws"))
|
with compute_api.ws("/notifications/ws") as ws:
|
||||||
# answer = await ws.receive()
|
|
||||||
# answer = json.loads(answer.data)
|
answer = ws.receive_text()
|
||||||
#
|
answer = json.loads(answer)
|
||||||
# assert answer["action"] == "ping"
|
|
||||||
#
|
assert answer["action"] == "ping"
|
||||||
# NotificationManager.instance().emit("test", {})
|
|
||||||
#
|
NotificationManager.instance().emit("test", {})
|
||||||
# answer = await ws.receive()
|
|
||||||
# answer = json.loads(answer.data)
|
answer = ws.receive_text()
|
||||||
# assert answer["action"] == "test"
|
answer = json.loads(answer)
|
||||||
#
|
assert answer["action"] == "test"
|
||||||
# if not ws.closed:
|
|
||||||
# await ws.close()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user