From 3a6a04b8e55745a47ac5e7634f225564e430e6e3 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 16 Mar 2015 10:18:37 +0100 Subject: [PATCH] Fix version test --- gns3server/handlers/api/version_handler.py | 2 +- tests/handlers/api/test_version.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gns3server/handlers/api/version_handler.py b/gns3server/handlers/api/version_handler.py index 10dc138a..22a2131c 100644 --- a/gns3server/handlers/api/version_handler.py +++ b/gns3server/handlers/api/version_handler.py @@ -32,7 +32,7 @@ class VersionHandler: def version(request, response): config = Config.instance() - local_server =config.get_section_config("Server").getboolean("local", False) + local_server = config.get_section_config("Server").getboolean("local", False) response.json({"version": __version__, "local": local_server}) @classmethod diff --git a/tests/handlers/api/test_version.py b/tests/handlers/api/test_version.py index 0691d8f9..1af2ac89 100644 --- a/tests/handlers/api/test_version.py +++ b/tests/handlers/api/test_version.py @@ -20,13 +20,23 @@ This test suite check /version endpoint It's also used for unittest the HTTP implementation. """ +from unittest.mock import patch, MagicMock +from configparser import ConfigParser + from gns3server.version import __version__ def test_version_output(server): - response = server.get('/version', example=True) - assert response.status == 200 - assert response.json == {'version': __version__} + gns_config = MagicMock() + config = ConfigParser() + config.add_section("Server") + config.set("Server", "local", "true") + gns_config.get_section_config.return_value = config["Server"] + + with patch("gns3server.config.Config.instance", return_value=gns_config): + response = server.get('/version', example=True) + assert response.status == 200 + assert response.json == {'local': True, 'version': __version__} def test_version_input(server):