From 964e646b2c26bcb007390dc6af625835f98887ec Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 26 Nov 2017 16:41:33 +0100 Subject: Update: project and work apis to handle named pipelines --- ick2/projectapi_tests.py | 56 +++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 24 deletions(-) (limited to 'ick2/projectapi_tests.py') diff --git a/ick2/projectapi_tests.py b/ick2/projectapi_tests.py index ae5190e..4e55ccf 100644 --- a/ick2/projectapi_tests.py +++ b/ick2/projectapi_tests.py @@ -36,28 +36,32 @@ class ProjectAPITests(unittest.TestCase): def create_api(self): return ick2.ProjectAPI(self.state) + def create_pipeline_api(self): + return ick2.PipelineAPI(self.state) + def test_has_not_projects_initially(self): api = self.create_api() self.assertEqual(api.list(), {'projects': []}) def test_creates_project(self): + pipeline = { + 'name': 'build', + 'actions': [ + {'shell': 'step-1'}, + ], + } + pipeapi = self.create_pipeline_api() + pipeapi.create(pipeline) + project = { 'project': 'foo', - 'pipelines': [ - { - 'name': 'build', - 'actions': [ - { - 'shell': 'step-1', - }, - ], - }, - ], + 'pipelines': ['build'], 'parameters': { 'foo': 'bar', } } 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'}) @@ -85,7 +89,7 @@ class ProjectAPITests(unittest.TestCase): def test_loads_projects_from_state_directory(self): project = { 'project': 'foo', - 'shell_steps': ['build'], + 'pipelines': ['build'], } api = self.create_api() api.create(project) @@ -96,7 +100,7 @@ class ProjectAPITests(unittest.TestCase): def test_gets_named_project(self): project = { 'project': 'foo', - 'shell_steps': ['build'], + 'pipelines': ['build'], } api = self.create_api() api.create(project) @@ -105,7 +109,7 @@ class ProjectAPITests(unittest.TestCase): def test_updates_named_project(self): project_v1 = { 'project': 'foo', - 'shell_steps': ['build'], + 'pipelines': ['build'], } project_v2 = dict(project_v1) project_v2['shell_steps'] = ['build it using magic'] @@ -118,7 +122,7 @@ class ProjectAPITests(unittest.TestCase): def test_deletes_named_project(self): project = { 'project': 'foo', - 'shell_steps': ['build'], + 'pipelines': ['build'], } api = self.create_api() api.create(project) @@ -133,27 +137,29 @@ class ProjectAPITests(unittest.TestCase): api.delete('foo') def test_updates_pipeline_status(self): + pipeline = { + 'name': 'build', + 'actions': [ + {'shell': 'step-1'}, + ], + } + pipeapi = self.create_pipeline_api() + pipeapi.create(pipeline) + project = { 'project': 'foo', - 'pipelines': [ - { - 'name': 'build', - 'actions': [ - { - 'shell': 'step-1', - }, - ], - }, - ], + 'pipelines': ['build'], } api = self.create_api() api.create(project) self.assertEqual(api.get_pipeline('foo', 'build'), {'status': 'idle'}) + self.assertEqual(pipeapi.show('build'), pipeline) with self.assertRaises(ick2.WrongPipelineStatus): api.set_pipeline('building', 'foo', 'build') api.set_pipeline('triggered', 'foo', 'build') + self.assertEqual(pipeapi.show('build'), pipeline) self.assertEqual( api.get_pipeline('foo', 'build'), {'status': 'triggered'} @@ -163,6 +169,7 @@ class ProjectAPITests(unittest.TestCase): api.set_pipeline('idle', 'foo', 'build') api.set_pipeline('building', 'foo', 'build') + self.assertEqual(pipeapi.show('build'), pipeline) self.assertEqual( api.get_pipeline('foo', 'build'), {'status': 'building'} @@ -172,6 +179,7 @@ class ProjectAPITests(unittest.TestCase): api.set_pipeline('triggered', 'foo', 'build') api.set_pipeline('idle', 'foo', 'build') + self.assertEqual(pipeapi.show('build'), pipeline) self.assertEqual( api.get_pipeline('foo', 'build'), {'status': 'idle'} -- cgit v1.2.1