diff options
-rw-r--r-- | ick2/controllerapi.py | 17 | ||||
-rw-r--r-- | ick2/controllerapi_tests.py | 11 | ||||
-rw-r--r-- | yarns/200-version.yarn | 35 |
3 files changed, 63 insertions, 0 deletions
diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py index 70877f1..ef93f54 100644 --- a/ick2/controllerapi.py +++ b/ick2/controllerapi.py @@ -17,6 +17,7 @@ import apifw import ick2 +import ick2version class ControllerAPI: @@ -36,6 +37,11 @@ class ControllerAPI: def find_missing_route(self, path): # pragma: no cover return [ { + 'method': 'GET', + 'path': '/version', + 'callback': self.get_version, + }, + { 'method': 'POST', 'path': '/projects', 'callback': self.post_callback(self.post_projects), @@ -62,6 +68,17 @@ class ControllerAPI: }, ] + def get_version(self, *args, **kwargs): + return apifw.Response({ + 'status': apifw.HTTP_OK, + 'body': { + 'version': ick2version.__version__, + }, + 'headers': { + 'Content-Type': 'application/json', + }, + }) + def get_callback(self, callback): # pragma: no cover def wrapper(content_type, body, **kwargs): try: diff --git a/ick2/controllerapi_tests.py b/ick2/controllerapi_tests.py index ca05e6b..8a914a3 100644 --- a/ick2/controllerapi_tests.py +++ b/ick2/controllerapi_tests.py @@ -20,6 +20,7 @@ import unittest import ick2 +import ick2version class ControllerAPITests(unittest.TestCase): @@ -47,6 +48,16 @@ class ControllerAPITests(unittest.TestCase): self.assertEqual(statedir, self.statedir) self.assertTrue(os.path.exists(statedir)) + def test_returns_version_correcly(self): + api = self.create_api() + response = api.get_version() + self.assertEqual( + response['body'], + { + 'version': ick2version.__version__, + } + ) + def test_has_not_projects_initially(self): api = self.create_api() self.assertEqual(api.get_projects(), {'projects': []}) diff --git a/yarns/200-version.yarn b/yarns/200-version.yarn new file mode 100644 index 0000000..92cccbb --- /dev/null +++ b/yarns/200-version.yarn @@ -0,0 +1,35 @@ +<!-- + +Copyright 2017 Lars Wirzenius + +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/>. + +--> + +# Check controller version + +The Ick controller reports is version upon request. + + SCENARIO checking controller version + GIVEN an RSA key pair for token signing + AND an access token for scopes + ... uapi_version_get + AND controller config uses statedir at the state directory + AND a running ick controller + + WHEN user makes request GET /version + THEN result has status code 200 + AND body matches { "version": "0.2.1+git" } + + FINALLY stop ick controller |