From f7cd09d5fb1ac2783809412551588e73b0ffff98 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 23 Feb 2015 11:27:07 +0100 Subject: [PATCH] Display an upload form (upload is not yet ready) --- gns3server/handlers/__init__.py | 28 ++++++++++----- gns3server/handlers/api/__init__.py | 9 +++++ .../{ => api}/dynamips_device_handler.py | 14 ++++---- .../handlers/{ => api}/dynamips_vm_handler.py | 18 +++++----- gns3server/handlers/{ => api}/iou_handler.py | 18 +++++----- .../handlers/{ => api}/network_handler.py | 6 ++-- .../handlers/{ => api}/project_handler.py | 8 ++--- gns3server/handlers/{ => api}/qemu_handler.py | 16 ++++----- .../handlers/{ => api}/version_handler.py | 6 ++-- .../handlers/{ => api}/virtualbox_handler.py | 16 ++++----- gns3server/handlers/{ => api}/vpcs_handler.py | 12 +++---- gns3server/handlers/upload_handler.py | 34 ++++++++++++++++++ gns3server/templates/layout.html | 12 +++++++ gns3server/templates/upload.html | 36 +++++++++---------- gns3server/web/response.py | 25 +++++++++++++ gns3server/web/route.py | 16 ++++++--- requirements.txt | 1 + setup.py | 3 +- tests/conftest.py | 2 +- tests/{ => handlers}/api/__init__.py | 0 tests/{ => handlers}/api/base.py | 23 +++++++----- tests/{ => handlers}/api/test_dynamips.py | 0 tests/{ => handlers}/api/test_iou.py | 0 tests/{ => handlers}/api/test_network.py | 0 tests/{ => handlers}/api/test_project.py | 0 tests/{ => handlers}/api/test_qemu.py | 0 tests/{ => handlers}/api/test_version.py | 0 tests/{ => handlers}/api/test_virtualbox.py | 0 tests/{ => handlers}/api/test_vpcs.py | 0 tests/handlers/test_upload.py | 31 ++++++++++++++++ 30 files changed, 234 insertions(+), 100 deletions(-) create mode 100644 gns3server/handlers/api/__init__.py rename gns3server/handlers/{ => api}/dynamips_device_handler.py (95%) rename gns3server/handlers/{ => api}/dynamips_vm_handler.py (97%) rename gns3server/handlers/{ => api}/iou_handler.py (96%) rename gns3server/handlers/{ => api}/network_handler.py (91%) rename gns3server/handlers/{ => api}/project_handler.py (95%) rename gns3server/handlers/{ => api}/qemu_handler.py (96%) rename gns3server/handlers/{ => api}/version_handler.py (93%) rename gns3server/handlers/{ => api}/virtualbox_handler.py (96%) rename gns3server/handlers/{ => api}/vpcs_handler.py (96%) create mode 100644 gns3server/handlers/upload_handler.py create mode 100644 gns3server/templates/layout.html rename tests/{ => handlers}/api/__init__.py (100%) rename tests/{ => handlers}/api/base.py (84%) rename tests/{ => handlers}/api/test_dynamips.py (100%) rename tests/{ => handlers}/api/test_iou.py (100%) rename tests/{ => handlers}/api/test_network.py (100%) rename tests/{ => handlers}/api/test_project.py (100%) rename tests/{ => handlers}/api/test_qemu.py (100%) rename tests/{ => handlers}/api/test_version.py (100%) rename tests/{ => handlers}/api/test_virtualbox.py (100%) rename tests/{ => handlers}/api/test_vpcs.py (100%) create mode 100644 tests/handlers/test_upload.py diff --git a/gns3server/handlers/__init__.py b/gns3server/handlers/__init__.py index 5d558245..9f824c16 100644 --- a/gns3server/handlers/__init__.py +++ b/gns3server/handlers/__init__.py @@ -1,9 +1,19 @@ -__all__ = ["version_handler", - "network_handler", - "vpcs_handler", - "project_handler", - "virtualbox_handler", - "dynamips_vm_handler", - "dynamips_device_handler", - "iou_handler", - "qemu_handler"] +# +# 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 . + +from gns3server.handlers.api import * +from gns3server.handlers.upload_handler import UploadHandler + diff --git a/gns3server/handlers/api/__init__.py b/gns3server/handlers/api/__init__.py new file mode 100644 index 00000000..5d558245 --- /dev/null +++ b/gns3server/handlers/api/__init__.py @@ -0,0 +1,9 @@ +__all__ = ["version_handler", + "network_handler", + "vpcs_handler", + "project_handler", + "virtualbox_handler", + "dynamips_vm_handler", + "dynamips_device_handler", + "iou_handler", + "qemu_handler"] diff --git a/gns3server/handlers/dynamips_device_handler.py b/gns3server/handlers/api/dynamips_device_handler.py similarity index 95% rename from gns3server/handlers/dynamips_device_handler.py rename to gns3server/handlers/api/dynamips_device_handler.py index 4be6be4c..3a6f8588 100644 --- a/gns3server/handlers/dynamips_device_handler.py +++ b/gns3server/handlers/api/dynamips_device_handler.py @@ -17,13 +17,13 @@ import os import asyncio -from ..web.route import Route -from ..schemas.dynamips_device import DEVICE_CREATE_SCHEMA -from ..schemas.dynamips_device import DEVICE_UPDATE_SCHEMA -from ..schemas.dynamips_device import DEVICE_CAPTURE_SCHEMA -from ..schemas.dynamips_device import DEVICE_OBJECT_SCHEMA -from ..schemas.dynamips_device import DEVICE_NIO_SCHEMA -from ..modules.dynamips import Dynamips +from ...web.route import Route +from ...schemas.dynamips_device import DEVICE_CREATE_SCHEMA +from ...schemas.dynamips_device import DEVICE_UPDATE_SCHEMA +from ...schemas.dynamips_device import DEVICE_CAPTURE_SCHEMA +from ...schemas.dynamips_device import DEVICE_OBJECT_SCHEMA +from ...schemas.dynamips_device import DEVICE_NIO_SCHEMA +from ...modules.dynamips import Dynamips class DynamipsDeviceHandler: diff --git a/gns3server/handlers/dynamips_vm_handler.py b/gns3server/handlers/api/dynamips_vm_handler.py similarity index 97% rename from gns3server/handlers/dynamips_vm_handler.py rename to gns3server/handlers/api/dynamips_vm_handler.py index aa674e4c..c2855a29 100644 --- a/gns3server/handlers/dynamips_vm_handler.py +++ b/gns3server/handlers/api/dynamips_vm_handler.py @@ -19,16 +19,16 @@ import os import base64 import asyncio -from ..web.route import Route -from ..schemas.dynamips_vm import VM_CREATE_SCHEMA -from ..schemas.dynamips_vm import VM_UPDATE_SCHEMA -from ..schemas.dynamips_vm import VM_CAPTURE_SCHEMA -from ..schemas.dynamips_vm import VM_OBJECT_SCHEMA -from ..schemas.dynamips_vm import VM_NIO_SCHEMA -from ..schemas.dynamips_vm import VM_CONFIGS_SCHEMA -from ..modules.dynamips import Dynamips -from ..modules.project_manager import ProjectManager +from ...web.route import Route +from ...schemas.dynamips_vm import VM_CREATE_SCHEMA +from ...schemas.dynamips_vm import VM_UPDATE_SCHEMA +from ...schemas.dynamips_vm import VM_CAPTURE_SCHEMA +from ...schemas.dynamips_vm import VM_OBJECT_SCHEMA +from ...schemas.dynamips_vm import VM_NIO_SCHEMA +from ...schemas.dynamips_vm import VM_CONFIGS_SCHEMA +from ...modules.dynamips import Dynamips +from ...modules.project_manager import ProjectManager class DynamipsVMHandler: diff --git a/gns3server/handlers/iou_handler.py b/gns3server/handlers/api/iou_handler.py similarity index 96% rename from gns3server/handlers/iou_handler.py rename to gns3server/handlers/api/iou_handler.py index 05d34614..30aada83 100644 --- a/gns3server/handlers/iou_handler.py +++ b/gns3server/handlers/api/iou_handler.py @@ -18,15 +18,15 @@ import os -from ..web.route import Route -from ..modules.port_manager import PortManager -from ..schemas.iou import IOU_CREATE_SCHEMA -from ..schemas.iou import IOU_UPDATE_SCHEMA -from ..schemas.iou import IOU_OBJECT_SCHEMA -from ..schemas.iou import IOU_NIO_SCHEMA -from ..schemas.iou import IOU_CAPTURE_SCHEMA -from ..schemas.iou import IOU_INITIAL_CONFIG_SCHEMA -from ..modules.iou import IOU +from ...web.route import Route +from ...modules.port_manager import PortManager +from ...schemas.iou import IOU_CREATE_SCHEMA +from ...schemas.iou import IOU_UPDATE_SCHEMA +from ...schemas.iou import IOU_OBJECT_SCHEMA +from ...schemas.iou import IOU_NIO_SCHEMA +from ...schemas.iou import IOU_CAPTURE_SCHEMA +from ...schemas.iou import IOU_INITIAL_CONFIG_SCHEMA +from ...modules.iou import IOU class IOUHandler: diff --git a/gns3server/handlers/network_handler.py b/gns3server/handlers/api/network_handler.py similarity index 91% rename from gns3server/handlers/network_handler.py rename to gns3server/handlers/api/network_handler.py index 87dedc29..e84cdb4f 100644 --- a/gns3server/handlers/network_handler.py +++ b/gns3server/handlers/api/network_handler.py @@ -15,9 +15,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from ..web.route import Route -from ..modules.port_manager import PortManager -from ..utils.interfaces import interfaces +from ...web.route import Route +from ...modules.port_manager import PortManager +from ...utils.interfaces import interfaces class NetworkHandler: diff --git a/gns3server/handlers/project_handler.py b/gns3server/handlers/api/project_handler.py similarity index 95% rename from gns3server/handlers/project_handler.py rename to gns3server/handlers/api/project_handler.py index 880b5473..00559dca 100644 --- a/gns3server/handlers/project_handler.py +++ b/gns3server/handlers/api/project_handler.py @@ -15,10 +15,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from ..web.route import Route -from ..schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA, PROJECT_UPDATE_SCHEMA -from ..modules.project_manager import ProjectManager -from ..modules import MODULES +from ...web.route import Route +from ...schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA, PROJECT_UPDATE_SCHEMA +from ...modules.project_manager import ProjectManager +from ...modules import MODULES class ProjectHandler: diff --git a/gns3server/handlers/qemu_handler.py b/gns3server/handlers/api/qemu_handler.py similarity index 96% rename from gns3server/handlers/qemu_handler.py rename to gns3server/handlers/api/qemu_handler.py index a802e3b2..74102dbe 100644 --- a/gns3server/handlers/qemu_handler.py +++ b/gns3server/handlers/api/qemu_handler.py @@ -18,14 +18,14 @@ import os -from ..web.route import Route -from ..modules.port_manager import PortManager -from ..schemas.qemu import QEMU_CREATE_SCHEMA -from ..schemas.qemu import QEMU_UPDATE_SCHEMA -from ..schemas.qemu import QEMU_OBJECT_SCHEMA -from ..schemas.qemu import QEMU_NIO_SCHEMA -from ..schemas.qemu import QEMU_BINARY_LIST_SCHEMA -from ..modules.qemu import Qemu +from ...web.route import Route +from ...modules.port_manager import PortManager +from ...schemas.qemu import QEMU_CREATE_SCHEMA +from ...schemas.qemu import QEMU_UPDATE_SCHEMA +from ...schemas.qemu import QEMU_OBJECT_SCHEMA +from ...schemas.qemu import QEMU_NIO_SCHEMA +from ...schemas.qemu import QEMU_BINARY_LIST_SCHEMA +from ...modules.qemu import Qemu class QEMUHandler: diff --git a/gns3server/handlers/version_handler.py b/gns3server/handlers/api/version_handler.py similarity index 93% rename from gns3server/handlers/version_handler.py rename to gns3server/handlers/api/version_handler.py index 6d020967..a935e3ca 100644 --- a/gns3server/handlers/version_handler.py +++ b/gns3server/handlers/api/version_handler.py @@ -15,9 +15,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from ..web.route import Route -from ..schemas.version import VERSION_SCHEMA -from ..version import __version__ +from ...web.route import Route +from ...schemas.version import VERSION_SCHEMA +from ...version import __version__ from aiohttp.web import HTTPConflict diff --git a/gns3server/handlers/virtualbox_handler.py b/gns3server/handlers/api/virtualbox_handler.py similarity index 96% rename from gns3server/handlers/virtualbox_handler.py rename to gns3server/handlers/api/virtualbox_handler.py index 51768bd3..be75c4cf 100644 --- a/gns3server/handlers/virtualbox_handler.py +++ b/gns3server/handlers/api/virtualbox_handler.py @@ -16,14 +16,14 @@ # along with this program. If not, see . import os -from ..web.route import Route -from ..schemas.virtualbox import VBOX_CREATE_SCHEMA -from ..schemas.virtualbox import VBOX_UPDATE_SCHEMA -from ..schemas.virtualbox import VBOX_NIO_SCHEMA -from ..schemas.virtualbox import VBOX_CAPTURE_SCHEMA -from ..schemas.virtualbox import VBOX_OBJECT_SCHEMA -from ..modules.virtualbox import VirtualBox -from ..modules.project_manager import ProjectManager +from ...web.route import Route +from ...schemas.virtualbox import VBOX_CREATE_SCHEMA +from ...schemas.virtualbox import VBOX_UPDATE_SCHEMA +from ...schemas.virtualbox import VBOX_NIO_SCHEMA +from ...schemas.virtualbox import VBOX_CAPTURE_SCHEMA +from ...schemas.virtualbox import VBOX_OBJECT_SCHEMA +from ...modules.virtualbox import VirtualBox +from ...modules.project_manager import ProjectManager class VirtualBoxHandler: diff --git a/gns3server/handlers/vpcs_handler.py b/gns3server/handlers/api/vpcs_handler.py similarity index 96% rename from gns3server/handlers/vpcs_handler.py rename to gns3server/handlers/api/vpcs_handler.py index 24458405..588ff50c 100644 --- a/gns3server/handlers/vpcs_handler.py +++ b/gns3server/handlers/api/vpcs_handler.py @@ -15,12 +15,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from ..web.route import Route -from ..schemas.vpcs import VPCS_CREATE_SCHEMA -from ..schemas.vpcs import VPCS_UPDATE_SCHEMA -from ..schemas.vpcs import VPCS_OBJECT_SCHEMA -from ..schemas.vpcs import VPCS_NIO_SCHEMA -from ..modules.vpcs import VPCS +from ...web.route import Route +from ...schemas.vpcs import VPCS_CREATE_SCHEMA +from ...schemas.vpcs import VPCS_UPDATE_SCHEMA +from ...schemas.vpcs import VPCS_OBJECT_SCHEMA +from ...schemas.vpcs import VPCS_NIO_SCHEMA +from ...modules.vpcs import VPCS class VPCSHandler: diff --git a/gns3server/handlers/upload_handler.py b/gns3server/handlers/upload_handler.py new file mode 100644 index 00000000..7bc6a5b7 --- /dev/null +++ b/gns3server/handlers/upload_handler.py @@ -0,0 +1,34 @@ +# -*- 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 . + +from ..web.route import Route +from ..schemas.version import VERSION_SCHEMA +from ..version import __version__ +from aiohttp.web import HTTPConflict + + +class UploadHandler: + + @classmethod + @Route.get( + r"/upload", + description="Manage upload of GNS3 images", + api_version=None + ) + def index(request, response): + response.template("upload.html") + diff --git a/gns3server/templates/layout.html b/gns3server/templates/layout.html new file mode 100644 index 00000000..9ecbc82c --- /dev/null +++ b/gns3server/templates/layout.html @@ -0,0 +1,12 @@ + + + +GNS3 Server + + +{% block body %}{% endblock %} + + + Powered by GNS3 {{gns3_version}} + + diff --git a/gns3server/templates/upload.html b/gns3server/templates/upload.html index ceec7f68..c912e49d 100644 --- a/gns3server/templates/upload.html +++ b/gns3server/templates/upload.html @@ -1,20 +1,16 @@ - - - -Upload Form for GNS3 server {{version}} - - -

Select & Upload (v{{version}})

-
-File: -
-
- -
-{%if items%} -

Files on {{host}}

-{%for item in items%} -

{{path}}/{{item}}

-{%end%} -{%end%} - \ No newline at end of file +{% extends "layout.html" %} +{% block body %} +

Select & Upload an image for GNS3

+
+ File: +
+
+ +
+ {%if items%} +

Files on {{host}}

+ {%for item in items%} +

{{path}}/{{item}}

+ {%endfor%} + {%endif%} +{% endblock %} diff --git a/gns3server/web/response.py b/gns3server/web/response.py index 9241d0c9..9bd453c6 100644 --- a/gns3server/web/response.py +++ b/gns3server/web/response.py @@ -20,9 +20,12 @@ import jsonschema import aiohttp.web import logging import sys +import jinja2 + from ..version import __version__ log = logging.getLogger(__name__) +renderer = jinja2.Environment(loader=jinja2.PackageLoader('gns3server', 'templates')) class Response(aiohttp.web.Response): @@ -47,6 +50,28 @@ class Response(aiohttp.web.Response): log.debug(json.loads(self.body.decode('utf-8'))) return super().start(request) + def html(self, answer): + """ + Set the response content type to text/html and serialize + the content. + + :param anwser The response as a Python object + """ + + self.content_type = "text/html" + self.body = answer.encode('utf-8') + + def template(self, template_filename, **kwargs): + """ + Render a template + + :params template: Template name + :params kwargs: Template parameters + """ + template = renderer.get_template(template_filename) + kwargs["gns3_version"] = __version__ + self.html(template.render(**kwargs)) + def json(self, answer): """ Set the response content type to application/json and serialize diff --git a/gns3server/web/route.py b/gns3server/web/route.py index 1fee37c7..4ec4d2b8 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -81,8 +81,11 @@ class Route(object): # This block is executed only the first time output_schema = kw.get("output", {}) input_schema = kw.get("input", {}) - api_version = kw.get("version", 1) - cls._path = "/v{version}{path}".format(path=path, version=api_version) + api_version = kw.get("api_version", 1) + if api_version is None: + cls._path = path + else: + cls._path = "/v{version}{path}".format(path=path, version=api_version) def register(func): route = cls._path @@ -123,8 +126,13 @@ class Route(object): response.set_status(500) exc_type, exc_value, exc_tb = sys.exc_info() lines = traceback.format_exception(exc_type, exc_value, exc_tb) - tb = "".join(lines) - response.json({"message": tb, "status": 500}) + if api_version is not None: + tb = "".join(lines) + response.json({"message": tb, "status": 500}) + else: + tb = "\n".join(lines) + response.html("

Internal error

{}
".format(tb)) + return response cls._routes.append((method, cls._path, control_schema)) diff --git a/requirements.txt b/requirements.txt index 1c9c8dbc..cd8c3f8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ python-dateutil==2.3 apache-libcloud==0.16.0 requests==2.5.0 aiohttp==0.14.4 +Jinja2==2.7.3 diff --git a/setup.py b/setup.py index 2a06203d..238efc3d 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,8 @@ class PyTest(TestCommand): dependencies = ["aiohttp==0.14.4", "jsonschema==2.4.0", "apache-libcloud==0.16.0", - "requests==2.5.0"] + "requests==2.5.0", + "Jinja2==2.7.3"] if sys.version_info == (3, 3): dependencies.append("asyncio==3.4.2") diff --git a/tests/conftest.py b/tests/conftest.py index cf146e81..51b5cee6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/api/__init__.py b/tests/handlers/api/__init__.py similarity index 100% rename from tests/api/__init__.py rename to tests/handlers/api/__init__.py diff --git a/tests/api/base.py b/tests/handlers/api/base.py similarity index 84% rename from tests/api/base.py rename to tests/handlers/api/base.py index 312c3175..d0f38878 100644 --- a/tests/api/base.py +++ b/tests/handlers/api/base.py @@ -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 diff --git a/tests/api/test_dynamips.py b/tests/handlers/api/test_dynamips.py similarity index 100% rename from tests/api/test_dynamips.py rename to tests/handlers/api/test_dynamips.py diff --git a/tests/api/test_iou.py b/tests/handlers/api/test_iou.py similarity index 100% rename from tests/api/test_iou.py rename to tests/handlers/api/test_iou.py diff --git a/tests/api/test_network.py b/tests/handlers/api/test_network.py similarity index 100% rename from tests/api/test_network.py rename to tests/handlers/api/test_network.py diff --git a/tests/api/test_project.py b/tests/handlers/api/test_project.py similarity index 100% rename from tests/api/test_project.py rename to tests/handlers/api/test_project.py diff --git a/tests/api/test_qemu.py b/tests/handlers/api/test_qemu.py similarity index 100% rename from tests/api/test_qemu.py rename to tests/handlers/api/test_qemu.py diff --git a/tests/api/test_version.py b/tests/handlers/api/test_version.py similarity index 100% rename from tests/api/test_version.py rename to tests/handlers/api/test_version.py diff --git a/tests/api/test_virtualbox.py b/tests/handlers/api/test_virtualbox.py similarity index 100% rename from tests/api/test_virtualbox.py rename to tests/handlers/api/test_virtualbox.py diff --git a/tests/api/test_vpcs.py b/tests/handlers/api/test_vpcs.py similarity index 100% rename from tests/api/test_vpcs.py rename to tests/handlers/api/test_vpcs.py diff --git a/tests/handlers/test_upload.py b/tests/handlers/test_upload.py new file mode 100644 index 00000000..d53b6302 --- /dev/null +++ b/tests/handlers/test_upload.py @@ -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 . + +""" +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