Display an upload form (upload is not yet ready)

This commit is contained in:
Julien Duponchelle committed 2015-02-23 11:28:33 +01:00
1 parent 210aa6f12a
commit f7cd09d5fb
30 files changed
+234 -100

No files matched your search

+1 -1
View File
@@ -30,7 +30,7 @@ from gns3server.handlers import *
from gns3server.modules import MODULES
from gns3server.modules.port_manager import PortManager
from gns3server.modules.project_manager import ProjectManager
from tests.api.base import Query
from tests.handlers.api.base import Query
# Prevent execution of external binaries
File renamed without changes.
@@ -44,22 +44,25 @@ class Query:
def delete(self, path, **kwargs):
return self._fetch("DELETE", path, **kwargs)
def _get_url(self, path):
return "http://{}:{}/v1{}".format(self._host, self._port, path)
def _get_url(self, path, version):
if version is None:
return "http://{}:{}{}".format(self._host, self._port, path)
return "http://{}:{}/v{}{}".format(self._host, self._port, version, path)
def _fetch(self, method, path, body=None, **kwargs):
def _fetch(self, method, path, body=None, api_version = 1, **kwargs):
"""Fetch an url, parse the JSON and return response
Options:
- example if True the session is included inside documentation
- raw do not JSON encode the query
- api_version Version of API, None if no version
"""
if body is not None and not kwargs.get("raw", False):
body = json.dumps(body)
@asyncio.coroutine
def go(future):
response = yield from aiohttp.request(method, self._get_url(path), data=body)
response = yield from aiohttp.request(method, self._get_url(path, api_version), data=body)
future.set_result(response)
future = asyncio.Future()
asyncio.async(go(future))
@@ -79,12 +82,16 @@ class Query:
response.route = x_route.replace("/v1", "")
if response.body is not None:
try:
response.json = json.loads(response.body.decode("utf-8"))
except ValueError:
response.json = None
if response.headers.get("CONTENT-TYPE", "") == "application/json":
try:
response.json = json.loads(response.body.decode("utf-8"))
except ValueError:
response.json = None
else:
response.html = response.body.decode("utf-8")
else:
response.json = {}
response.html = ""
if kwargs.get('example') and os.environ.get("PYTEST_BUILD_DOCUMENTATION") == "1":
self._dump_example(method, response.route, body, response)
return response
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+31
View File
@@ -0,0 +1,31 @@
# -*- 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.version import __version__
def test_version_index_upload(server):
response = server.get('/upload', api_version=None)
assert response.status == 200
html = response.html
assert "GNS3 Server" in html
assert "Select & Upload" in html