2013-10-30 21:58:17 +00:00
|
|
|
from tornado.testing import AsyncHTTPTestCase
|
2013-12-06 04:39:27 +00:00
|
|
|
from tornado.escape import json_decode
|
2013-10-30 21:58:17 +00:00
|
|
|
from gns3server.server import VersionHandler
|
2013-12-06 04:39:27 +00:00
|
|
|
from gns3server.version import __version__
|
2013-10-30 21:58:17 +00:00
|
|
|
import tornado.web
|
|
|
|
|
2013-12-06 04:39:27 +00:00
|
|
|
"""
|
|
|
|
Tests for the web server version handler
|
|
|
|
"""
|
2013-10-30 21:58:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestVersionHandler(AsyncHTTPTestCase):
|
|
|
|
|
2013-12-06 04:39:27 +00:00
|
|
|
URL = "/version"
|
|
|
|
|
2013-10-30 21:58:17 +00:00
|
|
|
def get_app(self):
|
2013-12-06 04:39:27 +00:00
|
|
|
|
|
|
|
return tornado.web.Application([(self.URL, VersionHandler)])
|
2013-10-30 21:58:17 +00:00
|
|
|
|
|
|
|
def test_endpoint(self):
|
2013-12-06 04:39:27 +00:00
|
|
|
"""
|
|
|
|
Tests if the response HTTP code is 200 (success)
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.http_client.fetch(self.get_url(self.URL), self.stop)
|
2013-10-30 21:58:17 +00:00
|
|
|
response = self.wait()
|
|
|
|
assert response.code == 200
|
|
|
|
|
2013-12-06 04:39:27 +00:00
|
|
|
def test_received_version(self):
|
|
|
|
"""
|
|
|
|
Tests if the returned content type is JSON and
|
|
|
|
if the received version is the same as the server
|
|
|
|
"""
|
2013-10-30 21:58:17 +00:00
|
|
|
|
2013-12-06 04:39:27 +00:00
|
|
|
self.http_client.fetch(self.get_url(self.URL), self.stop)
|
|
|
|
response = self.wait()
|
2014-05-28 12:26:20 +00:00
|
|
|
assert response.headers['Content-Type'].startswith('application/json')
|
|
|
|
assert response.body
|
2013-12-06 04:39:27 +00:00
|
|
|
body = json_decode(response.body)
|
|
|
|
assert body['version'] == __version__
|