diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-10-04 20:49:03 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-10-04 20:49:03 +0300 |
commit | f065856c67dcd8e6c88cfa454fe2596c024284f4 (patch) | |
tree | 7482f885f2e23f89203a0ed89819ae608c2b7411 /ick2 | |
parent | 6da3c5e6a2f6478ea3fecc723eadf2a4562a97d2 (diff) | |
download | ick2-f065856c67dcd8e6c88cfa454fe2596c024284f4.tar.gz |
Add: /version to controller API
Diffstat (limited to 'ick2')
-rw-r--r-- | ick2/controllerapi.py | 17 | ||||
-rw-r--r-- | ick2/controllerapi_tests.py | 11 |
2 files changed, 28 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': []}) |