Example #1
0
def note_detail(identifier):
    """
    API endpoint to retrieve, update or delete a note.
    """
    global notes

    if identifier not in notes:
        error = Error(title='Not found',
                      content={'messages': ['This note no longer exists.']})
        accept = request.headers.get('Accept')
        media_type, content = dump(error, accept=accept)
        return Response(content, status=404, mimetype=media_type)

    if request.method == 'DELETE':
        del notes[identifier]
        return Response(status=204)

    elif request.method == 'PUT':
        data = request.get_json()
        note = notes[identifier]
        if 'description' in data:
            note['description'] = str(data['description'])
        if 'complete' in data:
            note['complete'] = bool(data['complete'])

    doc = get_note(identifier)
    accept = request.headers.get('Accept')
    media_type, content = dump(doc, accept=accept)
    return Response(content, mimetype=media_type)
def test_error_does_not_support_property_assignment():
    error = Error(['failed'])
    with pytest.raises(TypeError):
        error.integer = 456
def test_html_error_rendering():
    doc = Error(content={'message': ['something failed']})
    content = HTMLCodec().dump(doc)
    assert 'coreapi-error' in content
    assert 'something failed' in content
def error():
    return Error(title='', content={'messages': ['failed']})
def test_error_keys_must_be_strings():
    with pytest.raises(TypeError):
        Error(content={0: 123})
def test_error_content_must_be_dict():
    with pytest.raises(TypeError):
        Error(content=123)
def test_error_title_must_be_string():
    with pytest.raises(TypeError):
        Error(title=123)
def test_error_does_not_support_property_assignment():
    error = Error(content={'messages': ['failed']})
    with pytest.raises(TypeError):
        error.integer = 456
Example #9
0
def test_error_does_not_support_property_assignment():
    error = Error(content={"messages": ["failed"]})
    with pytest.raises(TypeError):
        error.integer = 456