def _check_search(request): try: info = request.es.conn.cluster.health() if info['status'] not in ('green', 'yellow'): raise APIError('Search cluster state is %s' % info['status']) except Exception as exc: log.exception(exc) raise APIError('Search connection failed')
def status(request): try: request.db.execute("SELECT 1") except Exception as exc: log.exception(exc) raise APIError("Database connection failed") return {"status": "okay"}
def status(request): try: request.db.execute('SELECT 1') except Exception as exc: log.exception(exc) raise APIError('Database connection failed') return {'status': 'okay'}
def test_api_error_view(pyramid_request): context = APIError(message='asplosions!', status_code=418) result = views.api_error(context, pyramid_request) assert pyramid_request.response.status_code == 418 assert result['status'] == 'failure' assert result['reason'] == 'asplosions!'
def test_api_error_view(pyramid_request): context = APIError(message="asplosions!", status_code=418) result = views.api_error(context, pyramid_request) assert pyramid_request.response.status_code == 418 assert result["status"] == "failure" assert result["reason"] == "asplosions!"
def _check_celery(): try: result = celery.control.ping(timeout=0.25) if not result: raise APIError('Celery ping failed') for item in result: if len(item) != 1: continue reply = item.values()[0] if reply.get('ok') == 'pong': return raise APIError('Celery: no worker returned pong') except IOError as exc: log.exception(exc) raise APIError('Celery connection failed')
def update_preferences(request): preferences = request.json_body.get('preferences', {}) svc = request.find_service(name='user') try: svc.update_preferences(request.user, **preferences) except TypeError as e: raise APIError(str(e), status_code=400) return h_session.profile(request)
def update_preferences(request): preferences = request.json_body.get("preferences", {}) svc = request.find_service(name="user") # TODO: The following exception doesn't match convention for validation # used in other endpoints try: svc.update_preferences(request.user, **preferences) except TypeError as e: raise APIError(str(e), status_code=400) return h_session.profile(request)
def test_message(self): exc = APIError('some message') assert exc.message == 'some message'
def test_custom_status_code(self): exc = APIError('some message', status_code=418) assert exc.status_code == 418
def test_default_status_code(self): exc = APIError('some message') assert exc.status_code == 500
def _check_database(request): try: request.db.execute('SELECT 1') except Exception as exc: log.exception(exc) raise APIError('Database connection failed')
def test_message(self): exc = APIError('some message') assert str(exc) == 'some message'