diff options
-rw-r--r-- | ick2/controllerapi.py | 22 | ||||
-rw-r--r-- | ick2/controllerapi_tests.py | 31 |
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 = { |