diff options
author | Milo Casagrande <milo.casagrande@linaro.org> | 2014-12-02 09:31:42 +0100 |
---|---|---|
committer | Milo Casagrande <milo.casagrande@linaro.org> | 2014-12-02 09:31:42 +0100 |
commit | 08d1e3f0eb03d74fb8446edfd472ab23fbd0a7c2 (patch) | |
tree | b78328a5e1b82a7220859c0984214b52643626b1 | |
parent | b773905cfc4a2b6d22f88e5142d26146da8cb354 (diff) | |
parent | e2605aa619872fd71b97a22a405a54fbde4c7477 (diff) |
Merge branch 'version-handler' into boot-labs
-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 | ||||
-rw-r--r-- | doc/collection-version.rst | 62 | ||||
-rw-r--r-- | doc/collections.rst | 1 | ||||
-rw-r--r-- | doc/conf.py | 2 |
9 files changed, 196 insertions, 3 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 e4ebfe2..de1c0fc 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -106,6 +106,7 @@ USERNAME_KEY = 'username' VERSION_KEY = 'version' WARNINGS_KEY = 'warnings' 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, ] diff --git a/doc/collection-version.rst b/doc/collection-version.rst new file mode 100644 index 0000000..025295d --- /dev/null +++ b/doc/collection-version.rst @@ -0,0 +1,62 @@ +version +------- + +GET +*** + +.. http:get:: /version + + Provide the version number of the software running. + + :reqheader Accept-Encoding: Accept the ``gzip`` coding. + + :resheader Content-Type: Will be ``application/json; charset=UTF-8``. + + :status 200: Resuslts found. + + .. note:: + + This collection does not require authentication. + + **Example Requests** + + .. sourcecode:: http + + GET /version HTTP/1.1 + Host: api.armcloud.us + Accept: */* + + **Example Responses** + + .. sourcecode:: http + + HTTP/1.1 200 OK + Vary: Accept-Encoding + Date: Mon, 24 Nov 2014 18:08:12 GMT + Content-Type: application/json; charset=UTF-8 + + { + "code": 200, + "result": + [ + { + "version": "2014.11", + "full_version": "2014.11" + } + ] + } + +POST +**** + +.. caution:: + Not implemented. Will return a :ref:`status code <http_status_code>` + of ``501``. + + +DELETE +****** + +.. caution:: + Not implemented. Will return a :ref:`status code <http_status_code>` + of ``501``. diff --git a/doc/collections.rst b/doc/collections.rst index a3f48a8..b1bc434 100644 --- a/doc/collections.rst +++ b/doc/collections.rst @@ -12,3 +12,4 @@ Collections collection-boot collection-batch collection-lab + collection-version diff --git a/doc/conf.py b/doc/conf.py index 55f5b08..c1e1a10 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -24,7 +24,7 @@ sys.path.insert( 0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) ) -from app import __version__, __versionfull__ +from app.handlers import __version__, __versionfull__ # -- General configuration ------------------------------------------------ |