예제 #1
0
def testTodoFilterBy():
    completed_todos = get("Todo", filter_by={"state": u"completed"})
    todo = put("Todo", u"TESTDESCRIPTION")
    set_completed(todo)
    assert todo["state"] == u"completed"
    new_completed_todos = get("Todo", filter_by={"state": u"completed"})
    assert len(new_completed_todos) - len(completed_todos) == 1
예제 #2
0
def testTodoCommit():
    todos = get("Todo", all=True)
    for todo in todos:
        delete_from_db(todo)
        del todo
    commit()
    todos = get("Todo", all=True)
    assert len(todos) == 0
    todo = put("Todo", u"TESTDESCRIPTION")
    commit()
    del todo
    todos = get("Todo", all=True)
    assert len(todos) == 1
    assert todos[0]["description"] == u"TESTDESCRIPTION"
예제 #3
0
def create(request):
    model_type = request.matchdict['model_type']
    primary_descriptor = None
    if model_type == 'todos':
        model_type = 'Todo'
        primary_descriptor = 'description'
    elif model_type == 'projects':
        model_type = 'Project'
        primary_descriptor = 'description'
    elif model_type == 'tags':
        model_type = 'Tag'
        primary_descriptor = 'name'

    new_thing = b.put(model_type, request.json_body[primary_descriptor])
    return json.dumps(b.get(model_type, filter_by={'id': new_thing['id']}), default=datetime_handler)
예제 #4
0
def get(request):
    model_type = request.matchdict['model_type']
    if model_type == 'todos':
        model_type = 'Todo'
    elif model_type == 'projects':
        model_type = 'Project'
    elif model_type == 'tags':
        model_type = 'Tag'

    filter_by = {}
    if len(request.matchdict['id']) > 0:
        filter_by['id'] = request.matchdict['id'][0] # Not supporting multiple for now
    else:
        if model_type in ('Todo', 'Project'): # Tags don't have a state
            filter_by['state'] = 'active'

    return json.dumps(b.get(model_type, filter_by=filter_by), default=datetime_handler)
예제 #5
0
def edit(request):
    model_type = request.matchdict['model_type']
    primary_descriptor = None
    if model_type == 'todos':
        model_type = 'Todo'
        primary_descriptor = 'description'
    elif model_type == 'projects':
        model_type = 'Project'
        primary_descriptor = 'description'
    elif model_type == 'tags':
        model_type = 'Tag'
        primary_descriptor = 'name'

    to_update = b.get(model_type, filter_by={'id': request.matchdict['id']})[0]
    control = None
    if 'pydiditweb_control' in request.json_body:
        control = request.json_body['pydiditweb_control']
        del request.json_body['pydiditweb_control']
    # Right now, you can only do one thing per call: set completed, move, update other attributes
    # These are in no particular order, really
    if 'state' in request.json_body and request.json_body['state'] == 'completed':
        b.set_completed(to_update)
    elif control is not None:
        if 'move_to_anchor' in control:
            to_update['display_position'] = b.move(to_update, anchor=control['move_to_anchor'], model_name=model_type)
        elif 'sink_all_the_way' in control and control['sink_all_the_way']:
            to_update['display_position'] = b.move(to_update, direction='sink', all_the_way=True)
    else:
        # Todo: Convert all timestamps to datetime in json_body so that the whole thing can be passed below.
        new_attributes = {}
        new_attributes[primary_descriptor] = request.json_body[primary_descriptor]
        b.set_attributes(to_update, new_attributes)
    # I don't really understand why this flush() is needed, but it is.  Without it, sqlalchemy/transaction does a rollback inside the backend when DBSession.close() is called.
    b.flush()
    b.commit()
    return json.dumps(to_update, default=datetime_handler)
예제 #6
0
def testCheckForCleanDB():
    assert len(get("Todo", all=True)) == 0