Ejemplo n.º 1
0
def test_edit():
    """测试编辑 todo"""
    username = uuid.uuid4().hex
    raw_password = '******'
    password = User.generate_password(raw_password)
    u = User(username=username, password=password)
    u.save()
    s = Session(user_id=u.id, expire_in='2099-12-31 00:00:00')
    s.save()
    content = uuid.uuid4().hex
    t = Todo(user_id=u.id, content=content)
    t.save()
    edit_content = 'Edit: ' + content
    request_message = f'POST /edit HTTP/1.1\r\nHost: 127.0.0.1:8000\r\n' \
                      f'Cookie: session_id={s.id}\r\n\r\nid={t.id}&content={edit_content}'
    request = Request(request_message)
    route, method = routes.get(request.path)
    r = route(request)
    t = Todo.find_by(user_id=u.id, content=edit_content, ensure_one=True)
    u.delete()
    s.delete()
    t.delete()
    assert b'302 FOUND' in bytes(r)
    assert b'/index' in bytes(r)
    assert t.content == edit_content

    r = route(request)
    assert b'302 FOUND' in bytes(r)
    assert b'/login' in bytes(r)
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
def test_edit():
    """测试编辑 todo"""
    content = uuid.uuid4().hex
    t = Todo(content=content)
    t.save()
    edit_content = 'Edit: ' + content
    request_message = f'POST /edit HTTP/1.1\r\nHost: 127.0.0.1:8000\r\n\r\n' \
                      f'id={t.id}&content={edit_content}'
    request = Request(request_message)
    route, method = routes.get(request.path)
    r = route(request)
    t = Todo.find_by(content=edit_content, ensure_one=True)
    t.delete()

    assert b'302 FOUND' in bytes(r)
    assert b'/index' in bytes(r)
    assert t.content == edit_content
Ejemplo n.º 4
0
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