def testRegisterEmailDoesNotAlreadyExistClubSpecifiedConnectionNotSpecified( self): dbName = "users/users.db" userDb = UserDatabase(dbName) userDb.emailSender = DummyEmailSender() userDb.createDatabase(None, True) email = "jeremy" name = "Jeremy" club = "Rotherham" password = "******" result = userDb.registerUser(email, name, club, password) conn = userDb.getConnection(None) c = conn.cursor() try: row = c.execute( "select id, email, name, club, status from user").fetchone() self.assertEquals( (result, email, name, club, UserDatabase.inactiveStatus), row) row = c.execute("select password from password where id = ?", (result, )).fetchone() self.assertEquals((password, ), row) finally: conn.close() self.assertEquals([email], userDb.emailSender.messages[0].addressees) self.assertEquals([Settings.adminEmail], userDb.emailSender.messages[1].addressees)
def testLoginConnectionNotSpecifiedIDNotFound(self): dbName = "users/users.db" database = UserDatabase(dbName) database.createDatabase(None, True) try: database.login("hello", "goodbye") self.fail("Should have thrown an exception") except UserException as ex: self.assertEquals(UserException.emailOrPasswordNotFound, ex.message) self.assertEquals(None, ex.cause)
def testActivateUserIdNotFoundConnectionNotSpecified(self): dbName = "users/users.db" database = UserDatabase(dbName) database.createDatabase(None, True) userId = 3 try: database.activateUser(userId) self.fail("Should have thrown an exception") except UserException as ex: self.assertEqual(UserException.userNotFound, ex.message) self.assertEqual(None, ex.cause)
def testCheckSessionConnectionNotSpecifiedTokenDoesNotExist(self): token = "theToken" dbName = "users/users.db" database = UserDatabase(dbName) database.createDatabase(None, True) try: UserDatabase(dbName).checkSessionToken(token) self.fail("Should have thrown an exception") except UserException as ex: self.assertEquals(UserException.sessionExpired, ex.message) self.assertEquals(None, ex.cause)
def testRegisterEmailDoesNotAlreadyExistClubSpecifiedConnectionNotSpecified(self): dbName = "users/users.db" userDb = UserDatabase(dbName) userDb.emailSender = DummyEmailSender() userDb.createDatabase(None, True) email = "jeremy" name = "Jeremy" club = "Rotherham" password = "******" result = userDb.registerUser(email, name, club, password) conn = userDb.getConnection(None) c = conn.cursor() try: row = c.execute("select id, email, name, club, status from user").fetchone() self.assertEquals((result, email, name, club, UserDatabase.inactiveStatus), row) row = c.execute("select password from password where id = ?", (result,)).fetchone() self.assertEquals((password,), row) finally: conn.close() self.assertEquals([email], userDb.emailSender.messages[0].addressees) self.assertEquals([Settings.adminEmail], userDb.emailSender.messages[1].addressees)
import sqlite3 from userdb.userdb import UserDatabase from test.users.userdbtest import DummyEmailSender conn = sqlite3.connect("users/users.db") userDb = UserDatabase(emailSender=DummyEmailSender()) userDb.createDatabase(conn, True) userId = userDb.registerUser("*****@*****.**", "User Admin", None, "wceag1es", conn) userDb.activateUser(userId, conn) conn.cursor().execute("insert into role (id, role) values(?, 'admin')", (userId, )) conn.commit() conn.close()