diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/__init__.py | 2 | ||||
-rw-r--r-- | app/handlers/__init__.py | 2 | ||||
-rw-r--r-- | app/handlers/tests/test_version_handler.py | 78 | ||||
-rw-r--r-- | app/handlers/version.py | 46 | ||||
-rw-r--r-- | app/models/__init__.py | 1 | ||||
-rw-r--r-- | app/urls.py | 5 |
6 files changed, 132 insertions, 2 deletions
diff --git a/app/__init__.py b/app/__init__.py index 8aced47..e69de29 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,2 +0,0 @@ -__version__ = "2014.11" -__versionfull__ = __version__ diff --git a/app/handlers/__init__.py b/app/handlers/__init__.py index e69de29..8aced47 100644 --- a/app/handlers/__init__.py +++ b/app/handlers/__init__.py @@ -0,0 +1,2 @@ +__version__ = "2014.11" +__versionfull__ = __version__ diff --git a/app/handlers/tests/test_version_handler.py b/app/handlers/tests/test_version_handler.py new file mode 100644 index 0000000..3406915 --- /dev/null +++ b/app/handlers/tests/test_version_handler.py @@ -0,0 +1,78 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +"""Test module for the JobHandler handler.""" + +import concurrent.futures +import mock +import mongomock +import tornado +import tornado.testing + +import handlers.app +import urls + +# Default Content-Type header returned by Tornado. +DEFAULT_CONTENT_TYPE = 'application/json; charset=UTF-8' + + +class TestVersionHandler( + tornado.testing.AsyncHTTPTestCase, tornado.testing.LogTrapTestCase): + + def setUp(self): + self.mongodb_client = mongomock.Connection() + + super(TestVersionHandler, self).setUp() + + patched_find_token = mock.patch("handlers.base.BaseHandler._find_token") + self.find_token = patched_find_token.start() + self.find_token.return_value = "token" + + patched_validate_token = mock.patch("handlers.common.validate_token") + self.validate_token = patched_validate_token.start() + self.validate_token.return_value = True + + self.addCleanup(patched_find_token.stop) + self.addCleanup(patched_validate_token.stop) + + def get_app(self): + dboptions = { + 'dbpassword': "", + 'dbuser': "" + } + + settings = { + 'dboptions': dboptions, + 'client': self.mongodb_client, + 'executor': concurrent.futures.ThreadPoolExecutor(max_workers=2), + 'default_handler_class': handlers.app.AppHandler, + 'debug': False, + 'version': 'foo' + } + + return tornado.web.Application([urls._VERSION_URL], **settings) + + def get_new_ioloop(self): + return tornado.ioloop.IOLoop.instance() + + def test_get(self): + response = self.fetch("/version", method="GET") + self.assertEqual(response.code, 200,) + + def test_post(self): + response = self.fetch("/version", method="POST", body="") + self.assertEqual(response.code, 501) + + def test_delete(self): + response = self.fetch("/version", method="DELETE") + self.assertEqual(response.code, 501) diff --git a/app/handlers/version.py b/app/handlers/version.py new file mode 100644 index 0000000..265de8e --- /dev/null +++ b/app/handlers/version.py @@ -0,0 +1,46 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +"""Provide a simple /version handler.""" + +import handlers +import handlers.base as hbase +import handlers.response as hresponse +import models + + +# pylint: disable=too-many-public-methods +class VersionHandler(hbase.BaseHandler): + """Handle request to the /version URL. + + Provide the backend version number in use. + """ + + def __init__(self, application, request, **kwargs): + super(VersionHandler, self).__init__(application, request, **kwargs) + + def execute_get(self, *args, **kwargs): + response = hresponse.HandlerResponse() + response.result = [ + { + models.VERSION_FULL_KEY: handlers.__versionfull__, + models.VERSION_KEY: handlers.__version__, + } + ] + return response + + def execute_post(self, *args, **kwargs): + return hresponse.HandlerResponse(501) + + def execute_delete(self, *args, **kwargs): + return hresponse.HandlerResponse(501) diff --git a/app/models/__init__.py b/app/models/__init__.py index 6ff8094..677fd0f 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -104,6 +104,7 @@ WARNINGS_KEY = 'warnings' ARM_ARCHITECTURE_KEY = 'arm' ARM64_ARCHITECTURE_KEY = 'arm64' x86_ARCHITECTURE_KEY = 'x86' +VERSION_FULL_KEY = 'full_version' # Token special fields. ADMIN_KEY = 'admin' diff --git a/app/urls.py b/app/urls.py index 1d598b4..269e15f 100644 --- a/app/urls.py +++ b/app/urls.py @@ -26,6 +26,7 @@ import handlers.job import handlers.lab import handlers.subscription import handlers.token +import handlers.version _JOB_URL = url( @@ -61,6 +62,9 @@ _BISECT_URL = url( _LAB_URL = url( r"/lab(?P<sl>/)?(?P<id>.*)", handlers.lab.LabHandler, name="lab" ) +_VERSION_URL = url( + r"/version", handlers.version.VersionHandler, name="version" +) APP_URLS = [ _BATCH_URL, @@ -72,4 +76,5 @@ APP_URLS = [ _LAB_URL, _SUBSCRIPTION_URL, _TOKEN_URL, + _VERSION_URL, ] |