def setUp(self): service.provide('dbconnector', MemConnector) database.ensure_current_version(userdb.DBNAME) self.users = userdb.UserDB() self.users.addUser('user', 'password', False) #unittest2 compability if not hasattr(self, 'assertTupleEqual'): def assertTupEq(t1, t2, msg): if not all(i == j for i, j in zip(t1, t2)): raise AssertionError(msg) self.assertTupleEqual = assertTupEq
def testChangePassword(self): connector = TmpConnector() # use different connections, don't share self.setUp(connector) #create new user self.users.addUser('newpwuser', 'password', False) msg = self.users.changePassword('newpwuser', 'newpassword') self.assertEqual(msg, "success") authuser = self.users.auth('newpwuser', 'password') self.assertTupleEqual( userdb.User.nobody(), authuser, 'authentication with old password after change must fail') self.users = userdb.UserDB() # force different DB connection authuser = self.users.auth('newpwuser', 'newpassword') self.assertEqual('newpwuser', authuser.name, 'authentication with new password failed')