summaryrefslogtreecommitdiff
path: root/ick2
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-11-05 14:52:40 +0100
committerLars Wirzenius <liw@liw.fi>2017-11-05 14:52:40 +0100
commitf49ebd90e1d16b51da1523c9767c387e59771b41 (patch)
tree702ef644299d24d141045ff9fab869c68fa8df29 /ick2
parent3fc701a748eecf90956459b5ffe753beb6695e37 (diff)
downloadick2-f49ebd90e1d16b51da1523c9767c387e59771b41.tar.gz
Add: get pipeline status for a project
Diffstat (limited to 'ick2')
-rw-r--r--ick2/controllerapi.py22
-rw-r--r--ick2/controllerapi_tests.py31
2 files changed, 52 insertions, 1 deletions
diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py
index 09d14bc..63daa94 100644
--- a/ick2/controllerapi.py
+++ b/ick2/controllerapi.py
@@ -226,6 +226,28 @@ class ProjectAPI(ResourceApiBase):
def get_resource_name(self, resource):
return resource['project']
+ def get_routes(self, path): # pragma: no cover
+ return super().get_routes(path) + self.get_pipeline_routes(path)
+
+ def get_pipeline_routes(self, path): # pragma: no cover
+ pipeline_path = '{}/<project>/pipelines/<pipeline>'.format(path)
+ return [
+ {
+ 'method': 'GET',
+ 'path': pipeline_path,
+ 'callback': self.GET(self.get_pipeline),
+ },
+ ]
+
+ def get_pipeline(self, project, pipeline):
+ p = self._state.get_resource(self._type_name, project)
+ for pl in p['pipelines']:
+ if pl['name'] == pipeline:
+ return {
+ 'status': pl.get('status', 'idle'),
+ }
+ raise ick2.NotFound()
+
def response(status_code, body, headers): # pragma: no cover
obj = {
diff --git a/ick2/controllerapi_tests.py b/ick2/controllerapi_tests.py
index 42d1003..ec5f1a2 100644
--- a/ick2/controllerapi_tests.py
+++ b/ick2/controllerapi_tests.py
@@ -86,11 +86,40 @@ class ProjectAPITests(unittest.TestCase):
def test_creates_project(self):
project = {
'project': 'foo',
- 'shell_steps': ['build'],
+ 'pipelines': [
+ {
+ 'name': 'build',
+ 'actions': [
+ {
+ 'shell': 'step-1',
+ },
+ ],
+ },
+ ],
}
api = self.create_api()
self.assertEqual(api.create(project), project)
self.assertEqual(api.list(), {'projects': [project]})
+ self.assertEqual(api.get_pipeline('foo', 'build'), {'status': 'idle'})
+
+ def test_raises_error_when_getting_missing_pipeline(self):
+ project = {
+ 'project': 'foo',
+ 'pipelines': [
+ {
+ 'name': 'build',
+ 'actions': [
+ {
+ 'shell': 'step-1',
+ },
+ ],
+ },
+ ],
+ }
+ api = self.create_api()
+ api.create(project)
+ with self.assertRaises(ick2.NotFound):
+ api.get_pipeline('foo', 'does-not-exist')
def test_loads_projects_from_state_directory(self):
project = {