From 7d69a1eae658fae6c7437e0a8316312cb625acb5 Mon Sep 17 00:00:00 2001 From: akhilbatra898 Date: Sat, 18 Mar 2017 14:16:26 +0530 Subject: Add unit tests for List and get in API. - refactor controllers - remove abspath and other irrelvant data in response - move fixtures - refactor decorators JIRA: QTIP-226 Change-Id: I5fac5b1bc998da198098992e7ddb47ba49685f31 Signed-off-by: akhilbatra898 (cherry picked from commit bef693f40ad87170b7233b9fef62f2fd8abfc8d8) --- qtip/api/controllers/common.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'qtip/api/controllers/common.py') diff --git a/qtip/api/controllers/common.py b/qtip/api/controllers/common.py index 6cabbc7f..96101f80 100644 --- a/qtip/api/controllers/common.py +++ b/qtip/api/controllers/common.py @@ -5,15 +5,22 @@ import connexion from qtip.base import error -def get_one_exceptions(resource): +def check_endpoint_for_error(resource, operation=None): def _decorator(func): - def _execute(name): + def _execute(name=None): try: return func(name), httplib.OK except error.NotFoundError: return connexion.problem( httplib.NOT_FOUND, - '{} Not Found'.format(resource), - 'Requested {} `{}` not found.'.format(resource, name)) + '{} not found'.format(resource), + 'Requested {} `{}` not found.' + .format(resource.lower(), name)) + except error.ToBeDoneError: + return connexion.problem( + httplib.NOT_IMPLEMENTED, + '{} handler not implemented'.format(operation), + 'Requested operation `{}` on {} not implemented.' + .format(operation.lower(), resource.lower())) return _execute return _decorator -- cgit 1.2.3-korg