Add HTTP client to reuse the aiohttp session where needed.

Remove unnecessary aiohttp exceptions.
This commit is contained in:
grossmj committed 2020-10-22 16:19:44 +10:30
1 parent 36c8920cd1
commit a92c47b310
17 files changed
+221 -151

No files matched your search

+5 -4
View File
@@ -15,9 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import aiohttp
import pytest
import uuid
from fastapi import HTTPException
from unittest.mock import patch
from gns3server.compute.port_manager import PortManager
@@ -94,7 +95,7 @@ def test_reserve_udp_port():
pm = PortManager()
project = Project(project_id=str(uuid.uuid4()))
pm.reserve_udp_port(20000, project)
with pytest.raises(aiohttp.web.HTTPConflict):
with pytest.raises(HTTPException):
pm.reserve_udp_port(20000, project)
@@ -102,7 +103,7 @@ def test_reserve_udp_port_outside_range():
pm = PortManager()
project = Project(project_id=str(uuid.uuid4()))
with pytest.raises(aiohttp.web.HTTPConflict):
with pytest.raises(HTTPException):
pm.reserve_udp_port(80, project)
@@ -123,7 +124,7 @@ def test_find_unused_port():
def test_find_unused_port_invalid_range():
with pytest.raises(aiohttp.web.HTTPConflict):
with pytest.raises(HTTPException):
p = PortManager().find_unused_port(10000, 1000)
@@ -74,8 +74,6 @@ async def test_compute_get(controller_api):
response = await controller_api.get("/computes/my_compute_id")
assert response.status_code == 200
print(response.json)
#assert response.json["protocol"] == "http"
@pytest.mark.asyncio
+2 -2
View File
@@ -17,8 +17,8 @@
import os
import pytest
import aiohttp
from fastapi import HTTPException
from gns3server.utils.path import check_path_allowed, get_default_project_directory
@@ -27,7 +27,7 @@ def test_check_path_allowed(config, tmpdir):
config.set("Server", "local", False)
config.set("Server", "projects_path", str(tmpdir))
with pytest.raises(aiohttp.web.HTTPForbidden):
with pytest.raises(HTTPException):
check_path_allowed("/private")
config.set("Server", "local", True)