diff options
author | Milo Casagrande <milo.casagrande@linaro.org> | 2014-09-08 14:04:46 +0200 |
---|---|---|
committer | Milo Casagrande <milo.casagrande@linaro.org> | 2014-09-08 14:04:46 +0200 |
commit | 3fc27de0bc453b7b12d79c5a5093d4026256c3fe (patch) | |
tree | e75e90f3adab02ac8253e268382bb04f3ce06041 /app/handlers/boot.py | |
parent | 2a25e648f0078bc1aca331dc548a7c8a7c52b0d6 (diff) |
boot: Implement DELETE method.
* Add a more complex DELETE method that accepts either an ID
or a query to specify which boot reports to delete. This is
specific only to the boot handler.
* Refactor the base handler and created a new method to retrieve
the date_range query. This is necesary to limit the boot delete
method to not include date range deletion.
* Add boot handler test focused on the DELETE implementation.
Change-Id: I6ac159e8bddd5f0a094692ed891aefa1b0f31a41
Diffstat (limited to 'app/handlers/boot.py')
-rw-r--r-- | app/handlers/boot.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/app/handlers/boot.py b/app/handlers/boot.py index 8839426..062e3e1 100644 --- a/app/handlers/boot.py +++ b/app/handlers/boot.py @@ -18,6 +18,7 @@ from handlers.base import BaseHandler from handlers.response import HandlerResponse from models import ( + BOARD_KEY, CREATED_KEY, DEFCONFIG_KEY, JOB_ID_KEY, @@ -29,6 +30,10 @@ from models import ( ) from models.boot import BOOT_COLLECTION from taskqueue.tasks import import_boot +from utils.db import ( + delete, + find_one, +) class BootHandler(BaseHandler): @@ -45,8 +50,11 @@ class BootHandler(BaseHandler): valid_keys = { 'POST': [JOB_KEY, KERNEL_KEY], 'GET': [ - CREATED_KEY, WARNINGS_KEY, JOB_ID_KEY, + CREATED_KEY, WARNINGS_KEY, JOB_ID_KEY, BOARD_KEY, JOB_KEY, KERNEL_KEY, DEFCONFIG_KEY, TIME_KEY, STATUS_KEY, + ], + 'DELETE': [ + JOB_KEY, KERNEL_KEY, DEFCONFIG_KEY, BOARD_KEY, JOB_ID_KEY ] } @@ -60,3 +68,41 @@ class BootHandler(BaseHandler): import_boot.apply_async([kwargs['json_obj']]) return response + + def execute_delete(self, *args, **kwargs): + response = None + + if kwargs and kwargs.get('id', None): + doc_id = kwargs['id'] + if find_one(self.collection, doc_id): + response = self._delete(doc_id) + if response.status_code == 200: + response.reason = "Resource '%s' deleted" % doc_id + else: + response = HandlerResponse(404) + response.reason = "Resource '%s' not found" % doc_id + else: + spec = self._get_query_spec('DELETE') + if spec: + response = self._delete(spec) + if response.status_code == 200: + response.reason = ( + "Resources identified with '%s' deleted" % spec + ) + else: + response = HandlerResponse(400) + response.result = None + response.reason = ( + "No valid data provided to execute a DELETE" + ) + + return response + + def _delete(self, spec_or_id): + response = HandlerResponse(200) + response.result = None + + response.status_code = delete(self.collection, spec_or_id) + response.reason = self._get_status_message(response.status_code) + + return response |