1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-30 20:28:08 +00:00

Drop decorator for async test

This commit is contained in:
Julien Duponchelle 2015-01-20 18:55:17 +01:00
parent db31afeb63
commit 54eb8d9e81
6 changed files with 30 additions and 36 deletions

View File

@ -1,21 +1,23 @@
curl -i -xPOST 'http://localhost:8000/vpcs' -d '{"name": "PC TEST 1"}'
curl -i -X POST 'http://localhost:8000/vpcs' -d '{"name": "PC TEST 1", "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80"}'
POST /vpcs HTTP/1.1
{
"name": "PC TEST 1"
"name": "PC TEST 1",
"project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80"
}
HTTP/1.1 200
CONNECTION: close
CONTENT-LENGTH: 66
CONTENT-LENGTH: 160
CONTENT-TYPE: application/json
DATE: Thu, 08 Jan 2015 16:09:15 GMT
SERVER: Python/3.4 aiohttp/0.13.1
X-ROUTE: /vpcs
{
"console": 4242,
"console": 2000,
"name": "PC TEST 1",
"vpcs_id": 1
"project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80",
"uuid": "0adee348-1ce4-417b-9b5c-ff96f62ce35a"
}

View File

@ -1 +1 @@
__all__ = ['version_handler', 'vpcs_handler', 'project_handler']
__all__ = ['version_handler', 'vpcs_handler', 'project_handler', 'virtualbox_handler']

View File

@ -51,9 +51,9 @@ def test_version_invalid_input_schema(server):
assert response.status == 400
@asyncio_patch("gns3server.handlers.version_handler.VersionHandler", return_value={})
def test_version_invalid_output_schema(server):
query = {'version': "0.4.2"}
with asyncio_patch("gns3server.handlers.version_handler.VersionHandler", return_value={}):
query = {'version': __version__}
response = server.post('/version', query)
assert response.status == 400

View File

@ -15,27 +15,28 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from tests.api.base import server, loop
from tests.utils import asyncio_patch
@asyncio_patch("gns3server.modules.VirtualBox.create_vm", return_value="61d61bdd-aa7d-4912-817f-65a9eb54d3ab")
def test_vbox_create(server):
with asyncio_patch("gns3server.modules.VirtualBox.create_vm", return_value="61d61bdd-aa7d-4912-817f-65a9eb54d3ab"):
response = server.post("/virtualbox", {"name": "VM1"}, example=False)
assert response.status == 200
assert response.status == 400
assert response.route == "/virtualbox"
assert response.json["name"] == "VM1"
assert response.json["uuid"] == "61d61bdd-aa7d-4912-817f-65a9eb54d3ab"
@asyncio_patch("gns3server.modules.VirtualBox.start_vm", return_value=True)
def test_vbox_start(server):
with asyncio_patch("gns3server.modules.VirtualBox.start_vm", return_value=True):
response = server.post("/virtualbox/61d61bdd-aa7d-4912-817f-65a9eb54d3ab/start", {}, example=False)
assert response.status == 204
assert response.route == "/virtualbox/61d61bdd-aa7d-4912-817f-65a9eb54d3ab/start"
assert response.status == 200
assert response.route == "/virtualbox/{uuid}/start"
@asyncio_patch("gns3server.modules.VirtualBox.stop_vm", return_value=True)
def test_vbox_stop(server):
with asyncio_patch("gns3server.modules.VirtualBox.stop_vm", return_value=True):
response = server.post("/virtualbox/61d61bdd-aa7d-4912-817f-65a9eb54d3ab/stop", {}, example=False)
assert response.status == 204
assert response.route == "/virtualbox/61d61bdd-aa7d-4912-817f-65a9eb54d3ab/stop"
assert response.status == 200
assert response.route == "/virtualbox/{uuid}/stop"

View File

@ -19,6 +19,7 @@ import pytest
from tests.api.base import server, loop, project
from tests.utils import asyncio_patch
from unittest.mock import patch
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
@pytest.fixture(scope="module")
@ -28,14 +29,12 @@ def vm(server, project):
return response.json
@asyncio_patch("gns3server.modules.VPCS.create_vm", return_value="61d61bdd-aa7d-4912-817f-65a9eb54d3ab")
def test_vpcs_create(server, project):
response = server.post("/vpcs", {"name": "PC TEST 1", "project_uuid": project.uuid}, example=True)
assert response.status == 200
assert response.route == "/vpcs"
assert response.json["name"] == "PC TEST 1"
assert response.json["uuid"] == "61d61bdd-aa7d-4912-817f-65a9eb54d3ab"
assert response.json["project_uuid"] == "61d61bdd-aa7d-4912-817f-65a9eb54d3ab"
assert response.json["project_uuid"] == project.uuid
def test_vpcs_nio_create_udp(server, vm):

View File

@ -24,7 +24,7 @@ class _asyncio_patch:
"""
A wrapper around python patch supporting asyncio.
Like the original patch you can use it as context
manager (with) or decorator
manager (with)
The original patch source code is the main source of
inspiration:
@ -45,14 +45,6 @@ class _asyncio_patch:
"""Used when leaving the with block"""
self._patcher.stop()
def __call__(self, func, *args, **kwargs):
"""Call is used when asyncio_patch is used as decorator"""
@patch(self.function, return_value=self._fake_anwser())
@asyncio.coroutine
def inner(*a, **kw):
return func(*a, **kw)
return inner
def _fake_anwser(self):
future = asyncio.Future()
future.set_result(self.kwargs["return_value"])