From 12e22b32e6023e06769761788738cd6dc5a9cea3 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 23 Jul 2018 15:54:14 +0300 Subject: Change: allow projects, pipelines, etc, have a foo/bar/baz syntax --- ick2/apibase.py | 7 ++++--- ick2/projectapi.py | 4 +--- yarns/100-projects.yarn | 30 +++++++++++++++--------------- yarns/150-pipelines.yarn | 24 ++++++++++++------------ yarns/900-local.yarn | 2 ++ 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/ick2/apibase.py b/ick2/apibase.py index 9e3eaff..b629f68 100644 --- a/ick2/apibase.py +++ b/ick2/apibase.py @@ -23,6 +23,7 @@ class APIbase: self._trans = ick2.TransactionalState(state) def get_routes(self, path): + resource_path = '{}/'.format(path) return [ { 'method': 'POST', @@ -36,17 +37,17 @@ class APIbase: }, { 'method': 'GET', - 'path': '{}/'.format(path), + 'path': resource_path, 'callback': self.GET(self.show), }, { 'method': 'PUT', - 'path': '{}/'.format(path), + 'path': resource_path, 'callback': self.PUT(self.update), }, { 'method': 'DELETE', - 'path': '{}/'.format(path), + 'path': resource_path, 'callback': self.DELETE(self.delete), }, ] diff --git a/ick2/projectapi.py b/ick2/projectapi.py index f351e8d..90197ae 100644 --- a/ick2/projectapi.py +++ b/ick2/projectapi.py @@ -39,9 +39,7 @@ class ProjectAPI(ick2.ResourceApiBase): return super().get_routes(path) + self.get_status_routes(path) def get_status_routes(self, path): # pragma: no cover - all_statuses_path = '/status' - status_path = '{}//status'.format(path) - trigger_path = '{}//+trigger'.format(path) + trigger_path = '{}//+trigger'.format(path) return [ { 'needs-authorization': False, diff --git a/yarns/100-projects.yarn b/yarns/100-projects.yarn index 2fddded..b75dea4 100644 --- a/yarns/100-projects.yarn +++ b/yarns/100-projects.yarn @@ -75,23 +75,23 @@ building them. We start by starting an instance of the controller. ... } WHEN user makes request POST /projects with a valid token and body ... { - ... "project": "website", + ... "project": "foo/website", ... "pipelines": ["build"] ... } THEN result has status code 201 AND body matches ... { - ... "project": "website", + ... "project": "foo/website", ... "pipelines": ["build"], ... "next_build_id": null ... } - AND controller state directory contains project website + AND controller state directory contains project foo/website Creating a new project with the same name is forbidden. WHEN user makes request POST /projects with a valid token and body ... { - ... "project": "website", + ... "project": "foo/website", ... "pipelines": [] ... } THEN result has status code 409 @@ -102,7 +102,7 @@ Creating a new project with the same name is forbidden. ... { ... "projects": [ ... { - ... "project": "website", + ... "project": "foo/website", ... "pipelines": ["build"], ... "next_build_id": null ... } @@ -111,45 +111,45 @@ Creating a new project with the same name is forbidden. WHEN user stops ick controller GIVEN a running ick controller - WHEN user makes request GET /projects/website + WHEN user makes request GET /projects/foo/website THEN result has status code 200 AND body matches ... { - ... "project": "website", + ... "project": "foo/website", ... "pipelines": ["build"], ... "next_build_id": null ... } - WHEN user makes request PUT /projects/website with a valid token + WHEN user makes request PUT /projects/foo/website with a valid token ... and body ... { - ... "project": "website", + ... "project": "foo/website", ... "parameters": {"foo": "bar"}, ... "pipelines": ["build"] ... } THEN result has status code 200 AND body matches ... { - ... "project": "website", + ... "project": "foo/website", ... "parameters": {"foo": "bar"}, ... "pipelines": ["build"], ... "next_build_id": null ... } - AND controller state directory contains project website + AND controller state directory contains project foo/website - WHEN user makes request GET /projects/website + WHEN user makes request GET /projects/foo/website THEN result has status code 200 AND body matches ... { - ... "project": "website", + ... "project": "foo/website", ... "parameters": {"foo": "bar"}, ... "pipelines": ["build"], ... "next_build_id": null ... } - WHEN user makes request DELETE /projects/website + WHEN user makes request DELETE /projects/foo/website THEN result has status code 200 - WHEN user makes request GET /projects/website + WHEN user makes request GET /projects/foo/website THEN result has status code 404 WHEN user makes request PUT /projects/nosuchproject with a valid token and body diff --git a/yarns/150-pipelines.yarn b/yarns/150-pipelines.yarn index e2416a8..d828935 100644 --- a/yarns/150-pipelines.yarn +++ b/yarns/150-pipelines.yarn @@ -77,7 +77,7 @@ running them. We start by starting an instance of the controller. WHEN user makes request POST /pipelines with a valid token and body ... { - ... "pipeline": "build_website", + ... "pipeline": "foo/build_website", ... "actions": [ ... { "where": "host", "shell": "git clone git://repo src" }, ... { "where": "host", "shell": "mkdir html" }, @@ -87,7 +87,7 @@ running them. We start by starting an instance of the controller. THEN result has status code 201 AND body matches ... { - ... "pipeline": "build_website", + ... "pipeline": "foo/build_website", ... "actions": [ ... { "where": "host", "shell": "git clone git://repo src" }, ... { "where": "host", "shell": "mkdir html" }, @@ -99,7 +99,7 @@ Creating a new pipeline with the same name is forbidden. WHEN user makes request POST /pipelines with a valid token and body ... { - ... "pipeline": "build_website" + ... "pipeline": "foo/build_website" ... } THEN result has status code 409 @@ -109,7 +109,7 @@ Creating a new pipeline with the same name is forbidden. ... { ... "pipelines": [ ... { - ... "pipeline": "build_website", + ... "pipeline": "foo/build_website", ... "actions": [ ... { "where": "host", "shell": "git clone git://repo src" }, ... { "where": "host", "shell": "mkdir html" }, @@ -121,11 +121,11 @@ Creating a new pipeline with the same name is forbidden. WHEN user stops ick controller GIVEN a running ick controller - WHEN user makes request GET /pipelines/build_website + WHEN user makes request GET /pipelines/foo/build_website THEN result has status code 200 AND body matches ... { - ... "pipeline": "build_website", + ... "pipeline": "foo/build_website", ... "actions": [ ... { "where": "host", "shell": "git clone git://repo src" }, ... { "where": "host", "shell": "mkdir html" }, @@ -136,7 +136,7 @@ Creating a new pipeline with the same name is forbidden. WHEN user makes request PUT /pipelines/build_websitte with a valid token ... and body ... { - ... "pipeline": "build_website", + ... "pipeline": "foo/build_website", ... "actions": [ ... { "where": "host", "shell": "build-it" } ... ] @@ -144,25 +144,25 @@ Creating a new pipeline with the same name is forbidden. THEN result has status code 200 AND body matches ... { - ... "pipeline": "build_website", + ... "pipeline": "foo/build_website", ... "actions": [ ... { "where": "host", "shell": "build-it" } ... ] ... } - WHEN user makes request GET /pipelines/build_website + WHEN user makes request GET /pipelines/foo/build_website THEN result has status code 200 AND body matches ... { - ... "pipeline": "build_website", + ... "pipeline": "foo/build_website", ... "actions": [ ... { "where": "host", "shell": "build-it" } ... ] ... } - WHEN user makes request DELETE /pipelines/build_website + WHEN user makes request DELETE /pipelines/foo/build_website THEN result has status code 200 - WHEN user makes request GET /pipelines/build_website + WHEN user makes request GET /pipelines/foo/build_website THEN result has status code 404 WHEN user makes request PUT /pipelines/doesnotexist with a valid token and body diff --git a/yarns/900-local.yarn b/yarns/900-local.yarn index 1318eb9..6c83ce6 100644 --- a/yarns/900-local.yarn +++ b/yarns/900-local.yarn @@ -112,6 +112,8 @@ along with this program. If not, see . name = get_next_match() basename = encode_basename(name) filename = os.path.join(vars['statedir'], 'projects', basename) + print 'name', name + print 'basename', basename print 'filename', filename assertTrue(os.path.exists(filename)) -- cgit v1.2.1