Refactor tests

* Use pytest-aiohttp
* Use the async def / await syntax.
* Fix tests to run with Python 3.8
This commit is contained in:
grossmj committed 2020-06-16 13:59:03 +09:30
1 parent f498ab06b4
commit d3ea67da24
87 files changed
+3697 -3528

No files matched your search

+11 -11
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# Copyright (C) 2016 GNS3 Technologies Inc.
# Copyright (C) 2020 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -22,33 +22,30 @@ import os
from tests.utils import AsyncioMagicMock
from gns3server.controller.drawing import Drawing
from gns3server.controller.project import Project
@pytest.fixture
def project(controller, async_run):
return async_run(controller.add_project(name="Test"))
@pytest.fixture
def drawing(project):
return Drawing(project, None, svg="<svg></svg>")
def test_init_without_uuid(project):
drawing = Drawing(project, None, svg="<svg></svg>")
assert drawing.id is not None
def test_init_with_uuid(project):
id = str(uuid.uuid4())
drawing = Drawing(project, id, svg="<svg></svg>")
assert drawing.id == id
def test_json(project):
i = Drawing(project, None, svg="<svg></svg>")
assert i.__json__() == {
"drawing_id": i.id,
@@ -71,11 +68,12 @@ def test_json(project):
}
def test_update(drawing, project, async_run, controller):
async def test_update(drawing, project, controller):
controller._notification = AsyncioMagicMock()
project.dump = MagicMock()
async_run(drawing.update(x=42, svg="<svg><rect></rect></svg>"))
await drawing.update(x=42, svg="<svg><rect></rect></svg>")
assert drawing.x == 42
args, kwargs = controller._notification.project_emit.call_args
assert args[0] == "drawing.updated"
@@ -83,7 +81,7 @@ def test_update(drawing, project, async_run, controller):
assert args[1]["x"] == 42
assert args[1]["svg"] == "<svg><rect></rect></svg>"
async_run(drawing.update(x=12, svg="<svg><rect></rect></svg>"))
await drawing.update(x=12, svg="<svg><rect></rect></svg>")
assert drawing.x == 12
args, kwargs = controller._notification.project_emit.call_args
assert args[0] == "drawing.updated"
@@ -99,6 +97,7 @@ def test_image_base64(project):
"""
If image are embed as base 64 we need to dump them on disk
"""
svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"128\" width=\"128\">\n<image height=\"128\" width=\"128\" xlink:href=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAACXBIWXMAAAN2AAADdgF91YLMAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAHm5JREFUeJztnXl8FGXSx7/VIYAKKCoe4IEIq6ALuQnI4YXXKihulCSACIIsu4qKNyqXByqK67EeiMtyJGrwXnfABSu/L3I31aclPub3oBIQ/YD2zdUBZ+T37l7Dt0OAKoIYcUf07mBhpkieonJe+FcAUOgeX8dL/4ysTCSmTiwwsx1FPLJfuas89mXsByu/N/BR43E09+xMafDrYFI6wmzINu7QreFo1kD4EQIW/m8ICm1iAdBXWp0wuusiJp+Q7ilok3VE02RR+MoWPTYMXTYNlarAx6c6iQU7X/RbQ4DZA2m1F44CnrdYjDPG8ZcLBe/1kzz2Z9ybfUZQALAS\" />\n</svg>"
drawing = Drawing(project, None, svg=svg)
@@ -112,6 +111,7 @@ def test_image_svg(project):
"""
Large SVG are dump on disk
"""
svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"128\" width=\"128\">\n"
for i in range(0, 1000):