aboutsummaryrefslogtreecommitdiff
path: root/app/handlers
diff options
context:
space:
mode:
authorMilo Casagrande <milo.casagrande@linaro.org>2014-11-24 17:54:02 +0100
committerMilo Casagrande <milo.casagrande@linaro.org>2014-11-24 18:00:55 +0100
commite2605aa619872fd71b97a22a405a54fbde4c7477 (patch)
tree9f5876b8de146660ad37e3ad16545d8bb2af84ca /app/handlers
parent076cb88845f0c53d1e45ce172e4bfb1507debb06 (diff)
Add new /version handler.
* Implement a simple handler that accepts GET request to provide the version number of the backend. Change-Id: I6312570f9e91ae64fef07033c90be6e93e176fb4
Diffstat (limited to 'app/handlers')
-rw-r--r--app/handlers/__init__.py2
-rw-r--r--app/handlers/tests/test_version_handler.py78
-rw-r--r--app/handlers/version.py46
3 files changed, 126 insertions, 0 deletions
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)