示例#1
0
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')
示例#2
0
文件: status.py 项目: magnuslim/h
def status(request):
    try:
        request.db.execute("SELECT 1")
    except Exception as exc:
        log.exception(exc)
        raise APIError("Database connection failed")
    return {"status": "okay"}
示例#3
0
def status(request):
    try:
        request.db.execute('SELECT 1')
    except Exception as exc:
        log.exception(exc)
        raise APIError('Database connection failed')
    return {'status': 'okay'}
示例#4
0
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!'
示例#5
0
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!"
示例#6
0
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')
示例#7
0
文件: api_profile.py 项目: ziqizh/h
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)
示例#8
0
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)
示例#9
0
    def test_message(self):
        exc = APIError('some message')

        assert exc.message == 'some message'
示例#10
0
    def test_custom_status_code(self):
        exc = APIError('some message', status_code=418)

        assert exc.status_code == 418
示例#11
0
    def test_default_status_code(self):
        exc = APIError('some message')

        assert exc.status_code == 500
示例#12
0
def _check_database(request):
    try:
        request.db.execute('SELECT 1')
    except Exception as exc:
        log.exception(exc)
        raise APIError('Database connection failed')
示例#13
0
    def test_message(self):
        exc = APIError('some message')

        assert str(exc) == 'some message'