aboutsummaryrefslogtreecommitdiff
path: root/app/handlers/base.py
diff options
context:
space:
mode:
authorMilo Casagrande <milo.casagrande@linaro.org>2014-04-04 10:38:28 +0200
committerMilo Casagrande <milo.casagrande@linaro.org>2014-04-04 10:38:28 +0200
commit43cdb452ef71c549ad28e024bc2869517f0fecf5 (patch)
tree2b8756f5a97e53b5ce49006e49df1c75048f0852 /app/handlers/base.py
parent14e923fe32a20bb1c109c8976ed4c38a510bdf75 (diff)
Implement firt DELETE version for jobs.
* Simple delete operation for job, that does not take into account the other collections created in import phase. * Rework and refactor the JSON validation. * Fix tests.
Diffstat (limited to 'app/handlers/base.py')
-rw-r--r--app/handlers/base.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/app/handlers/base.py b/app/handlers/base.py
index cbeb060..fd6c70f 100644
--- a/app/handlers/base.py
+++ b/app/handlers/base.py
@@ -31,7 +31,7 @@ from utils.db import (
find,
find_one,
)
-from utils.validator import is_valid_json_put
+from utils.validator import is_valid_json
# Default and maximum limit for how many results to get back from the db.
DEFAULT_LIMIT = 20
@@ -65,6 +65,14 @@ class BaseHandler(RequestHandler):
"""The list of accepted keys to validate a JSON object."""
return ()
+ def _valid_keys(self, method):
+ """The accepted keys for the valid sent content type.
+
+ :param method: The HTTP method that originated the request.
+ :return A list of keys that the method accepts.
+ """
+ return None
+
def _get_status_message(self, status_code):
"""Get custom error message based on the status code.
@@ -101,13 +109,16 @@ class BaseHandler(RequestHandler):
"""
return self.ACCEPTED_CONTENT_TYPE
- def is_valid_put(self, json_obj):
- """Validate PUT requests content.
+ def _has_valid_keys(self, json_obj, keys):
+ """Validate the keys of sent JSON data.
+
+ Just make sure that the JSON data sent contains the required keys.
- :param json_obj: The JSON object to validate.
+ :param json_obj: The JSON data to validate.
+ :param keys: List of keys the JSON data should contain.
:return True or False.
"""
- return is_valid_json_put(json_obj, self.accepted_keys)
+ return is_valid_json(json_obj, keys)
def _create_valid_response(self, response):
"""Create a valid JSON response based on its type.
@@ -143,13 +154,6 @@ class BaseHandler(RequestHandler):
self.write(response)
self.finish()
- def _post_callback(self, result):
- """Callback used for POST operations.
-
- :param result: The result from the future instance.
- """
- self._create_valid_response(result)
-
def _check_content_type(self):
if self.request.headers['Content-Type'] != self.accepted_content_type:
self.send_error(status_code=415)