summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-11-18 20:07:02 +0100
committerLars Wirzenius <liw@liw.fi>2017-11-18 20:24:34 +0100
commitb0c6bce3a8df1ea730a535cd2e3dd8be7ff4422e (patch)
treec0e0d703f3a0c74ee1b07a63c8718d56b160df0b
parent18753714a35b6c8e5af4b6076973f490a1ba2097 (diff)
downloadick2-b0c6bce3a8df1ea730a535cd2e3dd8be7ff4422e.tar.gz
Refactor: move API specific exceptions into a separate module
-rw-r--r--ick2/__init__.py5
-rw-r--r--ick2/controllerapi.py28
-rw-r--r--ick2/exceptions.py30
-rw-r--r--without-tests1
4 files changed, 44 insertions, 20 deletions
diff --git a/ick2/__init__.py b/ick2/__init__.py
index d92de41..1145ca6 100644
--- a/ick2/__init__.py
+++ b/ick2/__init__.py
@@ -16,6 +16,11 @@
from .version import __version__, __version_info__
from .logging import setup_logging, log
from .state import ControllerState, NotFound, WrongPipelineStatus
+from .exceptions import (
+ BadUpdate,
+ IckException,
+ MethodNotAllowed,
+)
from .responses import (
OK,
bad_request,
diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py
index 6d00b9e..6cbf389 100644
--- a/ick2/controllerapi.py
+++ b/ick2/controllerapi.py
@@ -211,7 +211,7 @@ class ResourceApiBase(APIbase):
self._type_name, self.get_resource_name(body), body)
def get_resource_name(self, resource): # pragma: no cover
- raise NotImplementedError
+ raise NotImplementedError()
def update(self, body, name):
return self._state.update_resource(self._type_name, name, body)
@@ -238,10 +238,10 @@ class BuildsAPI(ResourceApiBase): # pragma: no cover
return resource['build']
def create(self, body): # pragma: no cover
- raise MethodNotAllowed('Creating builds directly is not allowed')
+ raise ick2.MethodNotAllowed('Creating builds directly is not allowed')
def update(self, body, name): # pragma: no cover
- raise MethodNotAllowed('Updating builds directly is not allowed')
+ raise ick2.MethodNotAllowed('Updating builds directly is not allowed')
def list(self):
result = super().list()
@@ -260,10 +260,10 @@ class LogAPI(ResourceApiBase): # pragma: no cover
return resource['log']
def create(self, body): # pragma: no cover
- raise MethodNotAllowed('Creating builds directly is not allowed')
+ raise ick2.MethodNotAllowed('Creating builds directly is not allowed')
def update(self, body, name): # pragma: no cover
- raise MethodNotAllowed('Updating builds directly is not allowed')
+ raise ick2.MethodNotAllowed('Updating builds directly is not allowed')
def show(self, name):
log = self._state.get_resource('log', str(name))
@@ -421,7 +421,7 @@ class WorkAPI(APIbase):
def update_work(self, update):
if 'worker' not in update: # pragma: no cover
- raise BadUpdate('no worker specified')
+ raise ick2.BadUpdate('no worker specified')
worker_state = self._get_worker(update['worker'])
doing = worker_state.get('doing', {})
@@ -474,9 +474,9 @@ class WorkAPI(APIbase):
must_match = ['worker', 'project', 'pipeline', 'build_id']
for name in must_match:
if name not in update:
- raise BadUpdate('{} not specified'.format(name))
+ raise ick2.BadUpdate('{} not specified'.format(name))
if doing.get(name) != update[name]:
- raise BadUpdate(
+ raise ick2.BadUpdate(
'{} differs from current work: {} vs {}'.format(
name, doing.get(name), update[name]))
@@ -542,15 +542,3 @@ class WorkAPI(APIbase):
def delete(self, *args, **kwargs): # pragma: no cover
pass
-
-
-class BadUpdate(Exception): # pragma: no cover
-
- def __init__(self, how):
- super().__init__('Work update is BAD: {}'.format(how))
-
-
-class MethodNotAllowed(Exception): # pragma: no cover
-
- def __init__(self, wat):
- super().__init__(wat)
diff --git a/ick2/exceptions.py b/ick2/exceptions.py
new file mode 100644
index 0000000..c99c3e5
--- /dev/null
+++ b/ick2/exceptions.py
@@ -0,0 +1,30 @@
+# 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/>.
+
+
+class IckException(Exception):
+
+ pass
+
+
+class BadUpdate(IckException):
+
+ def __init__(self, how):
+ super().__init__('Work update is BAD: {}'.format(how))
+
+
+class MethodNotAllowed(IckException):
+
+ def __init__(self, wat):
+ super().__init__(wat)
diff --git a/without-tests b/without-tests
index f180f97..b455c2b 100644
--- a/without-tests
+++ b/without-tests
@@ -1,4 +1,5 @@
ick2/__init__.py
+ick2/exceptions.py
ick2/logging.py
ick2/responses.py
ick2/version.py