From aa6c44a4703997a40fe0dedd7b14f6e874bcb383 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 16 Mar 2016 16:10:06 +0100 Subject: [PATCH] Fix crash when a n hypervisor return no body --- gns3server/controller/hypervisor.py | 2 +- tests/controller/test_hypervisor.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gns3server/controller/hypervisor.py b/gns3server/controller/hypervisor.py index b1710508..fdd11fa9 100644 --- a/gns3server/controller/hypervisor.py +++ b/gns3server/controller/hypervisor.py @@ -148,7 +148,7 @@ class Hypervisor: raise aiohttp.web.HTTPConflict(text="Conflict {} {}".format(url, body)) else: raise NotImplemented("{} status code is not supported".format(e.status)) - if len(body): + if body and len(body): try: response.json = json.loads(body) except json.JSONDecodeError: diff --git a/tests/controller/test_hypervisor.py b/tests/controller/test_hypervisor.py index 23258e9a..554c9371 100644 --- a/tests/controller/test_hypervisor.py +++ b/tests/controller/test_hypervisor.py @@ -78,7 +78,7 @@ def test_hypervisor_httpQueryAuth(hypervisor, async_run): def test_hypervisor_httpQueryNotConnected(hypervisor, async_run): hypervisor._connected = False response = AsyncioMagicMock() - response.read = AsyncioMagicMock(return_value = json.dumps({"version": __version__}).encode()) + response.read = AsyncioMagicMock(return_value=json.dumps({"version": __version__}).encode()) response.status = 200 with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock: async_run(hypervisor.post("/projects", {"a": "b"})) @@ -90,7 +90,7 @@ def test_hypervisor_httpQueryNotConnected(hypervisor, async_run): def test_hypervisor_httpQueryNotConnectedInvalidVersion(hypervisor, async_run): hypervisor._connected = False response = AsyncioMagicMock() - response.read = AsyncioMagicMock(return_value = json.dumps({"version": "1.42.4"}).encode()) + response.read = AsyncioMagicMock(return_value=json.dumps({"version": "1.42.4"}).encode()) response.status = 200 with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock: with pytest.raises(aiohttp.web.HTTPConflict): @@ -101,7 +101,7 @@ def test_hypervisor_httpQueryNotConnectedInvalidVersion(hypervisor, async_run): def test_hypervisor_httpQueryNotConnectedNonGNS3Server(hypervisor, async_run): hypervisor._connected = False response = AsyncioMagicMock() - response.read = AsyncioMagicMock(return_value = b'Blocked by super antivirus') + response.read = AsyncioMagicMock(return_value=b'Blocked by super antivirus') response.status = 200 with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock: with pytest.raises(aiohttp.web.HTTPConflict): @@ -112,7 +112,7 @@ def test_hypervisor_httpQueryNotConnectedNonGNS3Server(hypervisor, async_run): def test_hypervisor_httpQueryNotConnectedNonGNS3Server2(hypervisor, async_run): hypervisor._connected = False response = AsyncioMagicMock() - response.read = AsyncioMagicMock(return_value = b'{}') + response.read = AsyncioMagicMock(return_value=b'{}') response.status = 200 with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock: with pytest.raises(aiohttp.web.HTTPConflict):