Test start / stop. And check if the mocked function is really called

This commit is contained in:
Julien Duponchelle committed 2015-01-21 17:11:21 +01:00
1 parent 87a089457f
commit ce9fd3cb25
4 files changed
+15 -10

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@ class Query:
self._port = port
self._host = host
def post(self, path, body, **kwargs):
def post(self, path, body={}, **kwargs):
return self._fetch("POST", path, body, **kwargs)
def get(self, path, **kwargs):
+11 -7
View File
@@ -19,7 +19,7 @@ import pytest
import os
from tests.api.base import server, loop, project
from tests.utils import asyncio_patch
from unittest.mock import patch
from unittest.mock import patch, Mock
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
@@ -99,11 +99,15 @@ def test_vpcs_delete_nio(server, vm):
assert response.route == "/vpcs/{uuid}/ports/{port_id}/nio"
def test_vpcs_start():
# assert True == False
pass
def test_vpcs_start(server, vm):
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.start", return_value=True) as mock:
response = server.post("/vpcs/{}/start".format(vm["uuid"]))
assert mock.called
assert response.status == 200
def test_vpcs_stop():
# assert True == False
pass
def test_vpcs_stop(server, vm):
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.stop", return_value=True) as mock:
response = server.post("/vpcs/{}/stop".format(vm["uuid"]))
assert mock.called
assert response.status == 200
+2 -1
View File
@@ -39,7 +39,8 @@ class _asyncio_patch:
def __enter__(self):
"""Used when enter in the with block"""
self._patcher = patch(self.function, return_value=self._fake_anwser())
self._patcher.start()
mock_class = self._patcher.start()
return mock_class
def __exit__(self, *exc_info):
"""Used when leaving the with block"""