1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-18 14:28:08 +00:00
gns3-server/tests/test_version_handler.py

41 lines
1.1 KiB
Python
Raw Normal View History

from tornado.testing import AsyncHTTPTestCase
2013-12-06 04:39:27 +00:00
from tornado.escape import json_decode
from gns3server.server import VersionHandler
2013-12-06 04:39:27 +00:00
from gns3server.version import __version__
import tornado.web
2013-12-06 04:39:27 +00:00
"""
Tests for the web server version handler
"""
class TestVersionHandler(AsyncHTTPTestCase):
2013-12-06 04:39:27 +00:00
URL = "/version"
def get_app(self):
2013-12-06 04:39:27 +00:00
return tornado.web.Application([(self.URL, VersionHandler)])
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)
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-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__