diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-11-18 20:42:04 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-11-18 20:42:04 +0100 |
commit | ab4060f964f4ec55d0bf671aa85c3f99af9fa21a (patch) | |
tree | e5cce9ea3ac040763e1c4aed45b7025739e40e63 | |
parent | 4e45654544c65741de49f2929664de84a76712e0 (diff) | |
download | ick2-ab4060f964f4ec55d0bf671aa85c3f99af9fa21a.tar.gz |
Refactor: move BuildsAPI to its own module
-rw-r--r-- | ick2/__init__.py | 1 | ||||
-rw-r--r-- | ick2/buildsapi.py | 38 | ||||
-rw-r--r-- | ick2/controllerapi.py | 24 | ||||
-rw-r--r-- | without-tests | 1 |
4 files changed, 41 insertions, 23 deletions
diff --git a/ick2/__init__.py b/ick2/__init__.py index 4321f67..3ed21c8 100644 --- a/ick2/__init__.py +++ b/ick2/__init__.py @@ -29,6 +29,7 @@ from .responses import ( text_plain, ) from .apibase import APIbase, ResourceApiBase +from .buildsapi import BuildsAPI from .versionapi import VersionAPI from .workerapi import WorkerAPI from .controllerapi import ( diff --git a/ick2/buildsapi.py b/ick2/buildsapi.py new file mode 100644 index 0000000..2d5b5f9 --- /dev/null +++ b/ick2/buildsapi.py @@ -0,0 +1,38 @@ +# Copyright (C) 2017 Lars Wirzenius +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +import ick2 + + +class BuildsAPI(ick2.ResourceApiBase): # pragma: no cover + + def __init__(self, state): + super().__init__('builds', state) + + def get_resource_name(self, resource): + return resource['build'] + + def create(self, body): # pragma: no cover + raise ick2.MethodNotAllowed('Creating builds directly is not allowed') + + def update(self, body, name): # pragma: no cover + raise ick2.MethodNotAllowed('Updating builds directly is not allowed') + + def list(self): + result = super().list() + items = result[self._type_name] + items.sort(key=lambda x: x.get('build_id')) + result[self._type_name] = items + return result diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py index 62b7056..433d3d0 100644 --- a/ick2/controllerapi.py +++ b/ick2/controllerapi.py @@ -30,7 +30,7 @@ class ControllerAPI: def find_missing_route(self, missing_path): # pragma: no cover apis = { '/version': ick2.VersionAPI, - '/builds': BuildsAPI, + '/builds': ick2.BuildsAPI, '/logs': LogAPI, '/projects': ProjectAPI, '/work': WorkAPI, @@ -46,28 +46,6 @@ class ControllerAPI: return routes -class BuildsAPI(ick2.ResourceApiBase): # pragma: no cover - - def __init__(self, state): - super().__init__('builds', state) - - def get_resource_name(self, resource): - return resource['build'] - - def create(self, body): # pragma: no cover - raise ick2.MethodNotAllowed('Creating builds directly is not allowed') - - def update(self, body, name): # pragma: no cover - raise ick2.MethodNotAllowed('Updating builds directly is not allowed') - - def list(self): - result = super().list() - items = result[self._type_name] - items.sort(key=lambda x: x.get('build_id')) - result[self._type_name] = items - return result - - class LogAPI(ick2.ResourceApiBase): # pragma: no cover def __init__(self, state): diff --git a/without-tests b/without-tests index 097472c..6c767d5 100644 --- a/without-tests +++ b/without-tests @@ -1,5 +1,6 @@ ick2/__init__.py ick2/apibase.py +ick2/buildsapi.py ick2/exceptions.py ick2/logging.py ick2/responses.py |