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
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)
def testTodoDefaultState(): todo = make("Todo", u"TESTDESCRIPTION") add_to_db(todo) set_completed(todo) commit() assert todo["state"] == u"completed"
def testTodoState(): todo = make("Todo", u"TESTDESCRIPTION") set_completed(todo) assert todo["state"] == u"completed"
def testProjectState(): project = make("Project", u"PROJECTDESC") set_completed(project) assert project["state"] == u"completed"