【发布时间】:2015-07-16 03:11:22
【问题描述】:
我正在尝试从数据库中的会话表中检索用户。在我的单元测试中,我得到一个错误:
line 138, in test_session_user
self.assertEqual(nick_from_cookie, nick)
AssertionError: ('Bobalooba',) != 'Bobalooba'
我知道这是因为当测试将我的返回值与字符串进行比较时,我的代码返回了一个元组,因此它不匹配。
有没有办法让我使用元组进行比较,或者他们是查询我需要的结果的更好方法。下面是我使用的表格以及我的功能:
def session_user(db):
"""try to
retrieve the user from the sessions table
return usernick or None if no valid session is present
"""
cursor = db.cursor()
sessionid = bottle.request.get_cookie(COOKIE_NAME)
usernick = None
if sessionid:
cursor.execute("SELECT usernick FROM sessions WHERE sessionid=?", (sessionid,))
usernick = cursor.fetchone()
return usernick
【问题讨论】:
标签: python sqlite python-3.4 bottle