mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Refactor tests
* Use pytest-aiohttp * Use the async def / await syntax. * Fix tests to run with Python 3.8
This commit is contained in:
1 parent
f498ab06b4
commit
d3ea67da24
87 files changed
+3697
-3528
No files matched your search
@@ -1,42 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2015 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
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 os
|
||||
|
||||
from gns3server.web.documentation import Documentation
|
||||
from gns3server.handlers import *
|
||||
from gns3server.web.route import Route
|
||||
|
||||
|
||||
def test_documentation_write(tmpdir):
|
||||
os.makedirs(str(tmpdir / "api/examples"))
|
||||
with open(str(tmpdir / "api/examples/compute_post_projectsprojectidvirtualboxnodes.txt"), "w+") as f:
|
||||
f.write("curl test")
|
||||
|
||||
Documentation(Route, str(tmpdir)).write()
|
||||
|
||||
assert os.path.exists(str(tmpdir / "api"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v2" / "compute"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v2" / "compute" / "virtualbox.rst"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v2" / "compute" / "virtualbox"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v2" / "compute" / "virtualbox" / "virtualboxvms.rst"))
|
||||
with open(str(tmpdir / "api" / "v2" / "compute" / "virtualbox" / "projectsprojectidvirtualboxnodes.rst")) as f:
|
||||
content = f.read()
|
||||
assert "Sample session" in content
|
||||
assert "literalinclude:: ../../../examples/compute_post_projectsprojectidvirtualboxnodes.txt" in content
|
||||
|
||||
assert os.path.exists(str(tmpdir / "api" / "v2" / "controller" / "compute.rst"))
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
from tests.utils import AsyncioMagicMock
|
||||
from aiohttp.web import HTTPNotFound
|
||||
|
||||
from gns3server.web.response import Response
|
||||
@@ -25,20 +25,22 @@ from gns3server.web.response import Response
|
||||
|
||||
@pytest.fixture()
|
||||
def response():
|
||||
request = MagicMock()
|
||||
request = AsyncioMagicMock()
|
||||
return Response(request=request)
|
||||
|
||||
|
||||
def test_response_file(async_run, tmpdir, response):
|
||||
async def test_response_file(tmpdir, response):
|
||||
|
||||
filename = str(tmpdir / 'hello')
|
||||
with open(filename, 'w+') as f:
|
||||
f.write('world')
|
||||
|
||||
async_run(response.stream_file(filename))
|
||||
await response.stream_file(filename)
|
||||
assert response.status == 200
|
||||
|
||||
|
||||
def test_response_file_not_found(async_run, tmpdir, response):
|
||||
filename = str(tmpdir / 'hello-not-found')
|
||||
async def test_response_file_not_found(loop, tmpdir, response):
|
||||
|
||||
pytest.raises(HTTPNotFound, lambda: async_run(response.stream_file(filename)))
|
||||
filename = str(tmpdir / 'hello-not-found')
|
||||
with pytest.raises(HTTPNotFound):
|
||||
await response.stream_file(filename)
|
||||
Reference in new issue
Block a user