mirror of https://github.com/GNS3/gns3-server
parent
f4e51ea74f
commit
2f23a092e3
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 tornado.web
|
||||
from ..version import __version__
|
||||
|
||||
|
||||
class VersionHandler(tornado.web.RequestHandler):
|
||||
|
||||
def get(self):
|
||||
response = {'version': __version__}
|
||||
self.write(response)
|
@ -0,0 +1,50 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
from gns3server.modules import IModule
|
||||
from .hypervisor import Hypervisor
|
||||
from .hypervisor_manager import HypervisorManager
|
||||
from .dynamips_error import DynamipsError
|
||||
from .nodes.router import Router
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Dynamips(IModule):
|
||||
|
||||
def __init__(self, name=None, args=(), kwargs={}):
|
||||
IModule.__init__(self, name=name, args=args, kwargs=kwargs)
|
||||
#self._hypervisor_manager = HypervisorManager("/usr/bin/dynamips", "/tmp")
|
||||
|
||||
@IModule.route("dynamips/echo")
|
||||
def echo(self, request):
|
||||
print("Echo!")
|
||||
log.debug("received request {}".format(request))
|
||||
self.send_response(request)
|
||||
|
||||
@IModule.route("dynamips/create_vm")
|
||||
def create_vm(self, request):
|
||||
print("Create VM!")
|
||||
log.debug("received request {}".format(request))
|
||||
self.send_response(request)
|
||||
|
||||
@IModule.route("dynamips/start_vm")
|
||||
def start_vm(self, request):
|
||||
print("Start VM!")
|
||||
log.debug("received request {}".format(request))
|
||||
self.send_response(request)
|
@ -1,37 +1,40 @@
|
||||
from tornado.testing import AsyncHTTPTestCase
|
||||
from tornado.escape import json_decode
|
||||
from gns3server.server import VersionHandler
|
||||
from gns3server._compat import urlencode
|
||||
from gns3server.version import __version__
|
||||
import tornado.web
|
||||
import json
|
||||
|
||||
# URL to test
|
||||
URL = "/version"
|
||||
"""
|
||||
Tests for the web server version handler
|
||||
"""
|
||||
|
||||
|
||||
class TestVersionHandler(AsyncHTTPTestCase):
|
||||
|
||||
URL = "/version"
|
||||
|
||||
def get_app(self):
|
||||
return tornado.web.Application([(URL, VersionHandler)])
|
||||
|
||||
return tornado.web.Application([(self.URL, VersionHandler)])
|
||||
|
||||
def test_endpoint(self):
|
||||
self.http_client.fetch(self.get_url(URL), self.stop)
|
||||
"""
|
||||
Tests if the response HTTP code is 200 (success)
|
||||
"""
|
||||
|
||||
self.http_client.fetch(self.get_url(self.URL), self.stop)
|
||||
response = self.wait()
|
||||
assert response.code == 200
|
||||
|
||||
# def test_post(self):
|
||||
# data = urlencode({'test': 'works'})
|
||||
# req = tornado.httpclient.HTTPRequest(self.get_url(URL),
|
||||
# method='POST',
|
||||
# body=data)
|
||||
# self.http_client.fetch(req, self.stop)
|
||||
# response = self.wait()
|
||||
# assert response.code == 200
|
||||
#
|
||||
# def test_endpoint_differently(self):
|
||||
# self.http_client.fetch(self.get_url(URL), self.stop)
|
||||
# response = self.wait()
|
||||
# assert(response.headers['Content-Type'].startswith('application/json'))
|
||||
# assert(response.body != "")
|
||||
# body = json.loads(response.body.decode('utf-8'))
|
||||
# assert body['version'] == "0.1.dev"
|
||||
def test_received_version(self):
|
||||
"""
|
||||
Tests if the returned content type is JSON and
|
||||
if the received version is the same as the server
|
||||
"""
|
||||
|
||||
self.http_client.fetch(self.get_url(self.URL), self.stop)
|
||||
response = self.wait()
|
||||
assert(response.headers['Content-Type'].startswith('application/json'))
|
||||
assert(response.body)
|
||||
body = json_decode(response.body)
|
||||
assert body['version'] == __version__
|
||||
|
Loading…
Reference in new issue