Search code examples
pythonpython-3.xsqlitepycharmbottle

Python sqlite3 assertion error


I am pretty sure the code I am doing is logical and makes sense but when I run it against my test the result comes back quite unusual, I am trying find a session from a cookie, and then use it to retrieve the user from the sessions table. I am using the bottle framework to test my program

    active_session = bottle.request.get_cookie(COOKIE_NAME)
cursor = db.cursor()

if active_session:
    cursor.execute("SELECT usernick FROM sessions WHERE sessionid=?", (active_session, ))
    active_user = cursor.fetchone()
    return active_user
else:
    return None

The result is as follows

    self.assertEqual(nick_from_cookie, nick)
AssertionError: ('Bobalooba',) != 'Bobalooba'\

I know I am so close could someone point me in the right direction


Solution

  • if active_session:
        cursor.execute("SELECT usernick FROM sessions WHERE sessionid=?", (active_session, ))
        active_user = cursor.fetchone()
        return active_user[0] if active_user else active_user