2010-09-13 89 views
0

我根據燒瓶樣本寫這篇文章,我可以用瀏覽器登錄,但測試失敗。謝謝你的幫助!如何測試燒瓶中的登錄功能?

@app.route('/login', methods=['GET', 'POST']) 
def login(): 
    error = None   
    if request.method == 'POST': 
     username = request.form['username'] 
     password = request.form['password'] 
     if lib.authenticate_user(username, password): 
      session['logged_in'] = True 
      flash('You were logged in') 
      return render_template('www.html') 
    return render_template('login.html', error=error) 

tests.py

def login(self, username, password): 
    #print username, password 
    return self.app.post('/Login', data=dict(
     username=username, 
     password=password 
    ), follow_redirects=True) 


# testing functions 


def test_login_logout(self): 
    """Make sure login and logout works""" 
    rv = self.login('c1','123') 
    assert 'You were logged in' in rv.data 

回答

7

變化到後( '/登錄',