def index(request): """首页视图函数""" # 倒序排序,最近添加的 todo 排在前面 todo_list = Todo.all(sort=True, reverse=True) context = { 'todo_list': todo_list, } return render_template('todo/index.html', **context)
def test_todo(): """测试 Todo 模型类""" content = uuid.uuid4().hex t = Todo(content=content) t.save() ts = Todo.all() find_todo = Todo.get(t.id) t.delete() assert t.content == content assert t.id in [t.id for t in ts] assert t.id == find_todo.id
def test_todo(): """测试 Todo 模型类""" username = uuid.uuid4().hex raw_password = '******' password = User.generate_password(raw_password) u = User(username=username, password=password) u.save() content = uuid.uuid4().hex t = Todo(user_id=u.id, content=content) t.save() ts = Todo.all() find_todo = Todo.get(t.id) u.delete() t.delete() assert t.user_id == u.id assert t.content == content assert t.id in [t.id for t in ts] assert t.id == find_todo.id