mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
API V2
This commit is contained in:
200 files changed
+867
-625
No files matched your search
+2
-11
@@ -119,7 +119,7 @@ def http_controller(loop, http_server):
|
||||
Return an helper allowing you to call the server API without any prefix
|
||||
"""
|
||||
host, port = http_server
|
||||
return Query(loop, host=host, port=port, prefix="/controller", api_version=1)
|
||||
return Query(loop, host=host, port=port, prefix="/controller", api_version=2)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -128,16 +128,7 @@ def http_hypervisor(loop, http_server):
|
||||
Return an helper allowing you to call the hypervisor API via HTTP
|
||||
"""
|
||||
host, port = http_server
|
||||
return Query(loop, host=host, port=port, prefix="/hypervisor", api_version=1)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def http_api(loop, http_server):
|
||||
"""
|
||||
Return an helper allowing you to call the root API via HTTP
|
||||
"""
|
||||
host, port = http_server
|
||||
return Query(loop, host=host, port=port, api_version=1)
|
||||
return Query(loop, host=host, port=port, prefix="/hypervisor", api_version=2)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
|
||||
@@ -135,8 +135,5 @@ class Query:
|
||||
|
||||
def _example_file_path(self, method, path):
|
||||
path = re.sub('[^a-z0-9]', '', path)
|
||||
if len(self._prefix):
|
||||
prefix = self._prefix.replace('/', '')
|
||||
else:
|
||||
prefix = 'common'
|
||||
prefix = self._prefix.replace('/', '')
|
||||
return "docs/api/examples/{}_{}_{}.txt".format(prefix, method.lower(), path)
|
||||
+10
-10
@@ -25,37 +25,37 @@ from gns3server.config import Config
|
||||
from gns3server.version import __version__
|
||||
|
||||
|
||||
def test_version_output(http_api):
|
||||
def test_version_output(http_controller):
|
||||
config = Config.instance()
|
||||
config.set("Server", "local", "true")
|
||||
|
||||
response = http_api.get('/version', example=True)
|
||||
response = http_controller.get('/version', example=True)
|
||||
assert response.status == 200
|
||||
assert response.json == {'local': True, 'version': __version__}
|
||||
|
||||
|
||||
def test_version_input(http_api):
|
||||
def test_version_input(http_controller):
|
||||
query = {'version': __version__}
|
||||
response = http_api.post('/version', query, example=True)
|
||||
response = http_controller.post('/version', query, example=True)
|
||||
assert response.status == 200
|
||||
assert response.json == {'version': __version__}
|
||||
|
||||
|
||||
def test_version_invalid_input(http_api):
|
||||
def test_version_invalid_input(http_controller):
|
||||
query = {'version': "0.4.2"}
|
||||
response = http_api.post('/version', query)
|
||||
response = http_controller.post('/version', query)
|
||||
assert response.status == 409
|
||||
assert response.json == {'message': 'Client version 0.4.2 differs with server version {}'.format(__version__),
|
||||
'status': 409}
|
||||
|
||||
|
||||
def test_version_invalid_input_schema(http_api):
|
||||
def test_version_invalid_input_schema(http_controller):
|
||||
query = {'version': "0.4.2", "bla": "blu"}
|
||||
response = http_api.post('/version', query)
|
||||
response = http_controller.post('/version', query)
|
||||
assert response.status == 400
|
||||
|
||||
|
||||
def test_version_invalid_json(http_api):
|
||||
def test_version_invalid_json(http_controller):
|
||||
query = "BOUM"
|
||||
response = http_api.post('/version', query, raw=True)
|
||||
response = http_controller.post('/version', query, raw=True)
|
||||
assert response.status == 400
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# -*- 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/>.
|
||||
|
||||
"""
|
||||
This test suite check /version endpoint
|
||||
It's also used for unittest the HTTP implementation.
|
||||
"""
|
||||
|
||||
from gns3server.config import Config
|
||||
|
||||
from gns3server.version import __version__
|
||||
|
||||
|
||||
def test_version_output(http_hypervisor):
|
||||
config = Config.instance()
|
||||
config.set("Server", "local", "true")
|
||||
|
||||
response = http_hypervisor.get('/version', example=True)
|
||||
assert response.status == 200
|
||||
assert response.json == {'local': True, 'version': __version__}
|
||||
|
||||
|
||||
def test_version_input(http_hypervisor):
|
||||
query = {'version': __version__}
|
||||
response = http_hypervisor.post('/version', query, example=True)
|
||||
assert response.status == 200
|
||||
assert response.json == {'version': __version__}
|
||||
|
||||
|
||||
def test_version_invalid_input(http_hypervisor):
|
||||
query = {'version': "0.4.2"}
|
||||
response = http_hypervisor.post('/version', query)
|
||||
assert response.status == 409
|
||||
assert response.json == {'message': 'Client version 0.4.2 differs with server version {}'.format(__version__),
|
||||
'status': 409}
|
||||
|
||||
|
||||
def test_version_invalid_input_schema(http_hypervisor):
|
||||
query = {'version': "0.4.2", "bla": "blu"}
|
||||
response = http_hypervisor.post('/version', query)
|
||||
assert response.status == 400
|
||||
|
||||
|
||||
def test_version_invalid_json(http_hypervisor):
|
||||
query = "BOUM"
|
||||
response = http_hypervisor.post('/version', query, raw=True)
|
||||
assert response.status == 400
|
||||
@@ -30,13 +30,13 @@ def test_documentation_write(tmpdir):
|
||||
Documentation(Route, str(tmpdir)).write()
|
||||
|
||||
assert os.path.exists(str(tmpdir / "api"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v1" / "hypervisor"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v1" / "hypervisor" / "virtualbox.rst"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v1" / "hypervisor" / "virtualbox"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v1" / "hypervisor" / "virtualbox" / "virtualboxvms.rst"))
|
||||
with open(str(tmpdir / "api" / "v1" / "hypervisor" / "virtualbox" / "projectsprojectidvirtualboxvms.rst")) as f:
|
||||
assert os.path.exists(str(tmpdir / "api" / "v2" / "hypervisor"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v2" / "hypervisor" / "virtualbox.rst"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v2" / "hypervisor" / "virtualbox"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v2" / "hypervisor" / "virtualbox" / "virtualboxvms.rst"))
|
||||
with open(str(tmpdir / "api" / "v2" / "hypervisor" / "virtualbox" / "projectsprojectidvirtualboxvms.rst")) as f:
|
||||
content = f.read()
|
||||
assert "Sample session" in content
|
||||
assert "literalinclude:: ../../../examples/hypervisor_post_projectsprojectidvirtualboxvms.txt" in content
|
||||
|
||||
assert os.path.exists(str(tmpdir / "api" / "v1" / "controller" / "server.rst"))
|
||||
assert os.path.exists(str(tmpdir / "api" / "v2" / "controller" / "server.rst"))
|
||||
Reference in new issue
Block a user