mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Polishing base server implementation
This commit is contained in:
1 parent
f4e51ea74f
commit
2f23a092e3
12 files changed
+191
-48
No files matched your search
@@ -7,6 +7,9 @@ import time
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def server(request):
|
||||
"""
|
||||
Starts GNS3 server for all the tests.
|
||||
"""
|
||||
|
||||
cwd = os.path.dirname(os.path.abspath(__file__))
|
||||
server_script = os.path.join(cwd, "../gns3server/main.py")
|
||||
|
||||
@@ -5,6 +5,10 @@ from ws4py.client.tornadoclient import TornadoWebSocketClient
|
||||
from gns3server.stomp import frame as stomp_frame
|
||||
from gns3server.stomp import protocol as stomp_protocol
|
||||
|
||||
"""
|
||||
Tests STOMP protocol over Websockets
|
||||
"""
|
||||
|
||||
|
||||
class Stomp(AsyncTestCase):
|
||||
|
||||
@@ -16,6 +20,10 @@ class Stomp(AsyncTestCase):
|
||||
AsyncTestCase.setUp(self)
|
||||
|
||||
def test_connect(self):
|
||||
"""
|
||||
Sends a STOMP CONNECT frame and
|
||||
check for a STOMP CONNECTED frame.
|
||||
"""
|
||||
|
||||
request = self.stomp.connect("localhost")
|
||||
AsyncWSRequest(self.URL, self.io_loop, self.stop, request)
|
||||
@@ -25,6 +33,11 @@ class Stomp(AsyncTestCase):
|
||||
assert frame.cmd == stomp_protocol.CMD_CONNECTED
|
||||
|
||||
def test_protocol_negotiation_failure(self):
|
||||
"""
|
||||
Sends a STOMP CONNECT frame with protocol version 1.0 required
|
||||
and check for a STOMP ERROR sent back by the server which supports
|
||||
STOMP version 1.2 only.
|
||||
"""
|
||||
|
||||
request = self.stomp.connect("localhost", accept_version='1.0')
|
||||
AsyncWSRequest(self.URL, self.io_loop, self.stop, request)
|
||||
@@ -34,6 +47,9 @@ class Stomp(AsyncTestCase):
|
||||
assert frame.cmd == stomp_protocol.CMD_ERROR
|
||||
|
||||
def test_malformed_frame(self):
|
||||
"""
|
||||
Sends an empty frame and check for a STOMP ERROR.
|
||||
"""
|
||||
|
||||
request = b""
|
||||
AsyncWSRequest(self.URL, self.io_loop, self.stop, request)
|
||||
@@ -43,6 +59,10 @@ class Stomp(AsyncTestCase):
|
||||
assert frame.cmd == stomp_protocol.CMD_ERROR
|
||||
|
||||
def test_send(self):
|
||||
"""
|
||||
Sends a STOMP SEND frame with a message and a destination
|
||||
and check for a STOMP MESSAGE with echoed message and destination.
|
||||
"""
|
||||
|
||||
destination = "dynamips/echo"
|
||||
message = {"ping": "test"}
|
||||
@@ -57,6 +77,10 @@ class Stomp(AsyncTestCase):
|
||||
assert message == json_reply
|
||||
|
||||
def test_unimplemented_frame(self):
|
||||
"""
|
||||
Sends an STOMP BEGIN frame which is not implemented by the server
|
||||
and check for a STOMP ERROR frame.
|
||||
"""
|
||||
|
||||
frame = stomp_frame.Frame(stomp_protocol.CMD_BEGIN)
|
||||
request = frame.encode()
|
||||
@@ -67,6 +91,11 @@ class Stomp(AsyncTestCase):
|
||||
assert frame.cmd == stomp_protocol.CMD_ERROR
|
||||
|
||||
def test_disconnect(self):
|
||||
"""
|
||||
Sends a STOMP DISCONNECT frame is a receipt id
|
||||
and check for a STOMP RECEIPT frame with the same receipt id
|
||||
confirming the disconnection.
|
||||
"""
|
||||
|
||||
myid = str(uuid.uuid4())
|
||||
request = self.stomp.disconnect(myid)
|
||||
@@ -79,6 +108,9 @@ class Stomp(AsyncTestCase):
|
||||
|
||||
|
||||
class AsyncWSRequest(TornadoWebSocketClient):
|
||||
"""
|
||||
Very basic Websocket client for the tests
|
||||
"""
|
||||
|
||||
def __init__(self, url, io_loop, callback, message):
|
||||
TornadoWebSocketClient.__init__(self, url, io_loop=io_loop)
|
||||
|
||||
@@ -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__
|
||||
Reference in new issue
Block a user