From cee4e5941ce96e13ec7c779c1702472b7f1516c2 Mon Sep 17 00:00:00 2001 From: Harsha Kethineni <harshakethineni@flywheel.io> Date: Wed, 27 Sep 2017 09:37:42 -0500 Subject: [PATCH] version returns 404 if version doc is missing --- api/handlers/confighandler.py | 6 +++++- test/integration_tests/python/test_handlers.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/api/handlers/confighandler.py b/api/handlers/confighandler.py index 8b341b73..d2482648 100644 --- a/api/handlers/confighandler.py +++ b/api/handlers/confighandler.py @@ -22,4 +22,8 @@ class Version(base.RequestHandler): def get(self): """Return database schema version""" - return config.get_version() + resp = config.get_version() + if resp != None: + return resp + else: + self.abort(404, "Version document does not exist") diff --git a/test/integration_tests/python/test_handlers.py b/test/integration_tests/python/test_handlers.py index 4f2015fd..65b5133c 100644 --- a/test/integration_tests/python/test_handlers.py +++ b/test/integration_tests/python/test_handlers.py @@ -80,8 +80,14 @@ def test_devicehandler(as_user, as_root, as_drone, api_db): api_db.devices.remove({'_id': 'test_drone'}) -def test_config_version(as_user): +def test_config_version(as_user, api_db): + # get database version when no version document exists, It hasn;t been set yet in the tests + r = as_user.get('/version') + assert r.status_code == 404 + api_db.singletons.insert_one({"_id":"version","database":3}) + # get database schema version r = as_user.get('/version') assert r.ok - assert r.text == '' # not set yet + assert r.json()['database'] == 3 + api_db.singletons.find_one_and_delete({'_id':'version'}) -- GitLab