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 testActivateUserIdFoundAndInactive(self): conn = self.inMemoryDatabaseConnection(); userId = 3 c = conn.cursor() c.execute("insert into user(id, status) values(?, ?)", (userId, UserDatabase.inactiveStatus)) userDb = UserDatabase() userDb.emailSender = DummyEmailSender() userDb.activateUser(userId, conn) row = c.execute("select status from user where id = ?", (userId,)).fetchone() self.assertEquals((UserDatabase.activeStatus,), row) self.assertEquals([Settings.adminEmail], userDb.emailSender.messages[0].addressees)
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 testActivateUserIdFoundAndInactive(self): conn = self.inMemoryDatabaseConnection() userId = 3 c = conn.cursor() c.execute("insert into user(id, status) values(?, ?)", (userId, UserDatabase.inactiveStatus)) userDb = UserDatabase() userDb.emailSender = DummyEmailSender() userDb.activateUser(userId, conn) row = c.execute("select status from user where id = ?", (userId, )).fetchone() self.assertEquals((UserDatabase.activeStatus, ), row) self.assertEquals([Settings.adminEmail], userDb.emailSender.messages[0].addressees)
class UserActivation(Page): def __init__(self, pageId, params={}): Page.__init__(self, pageId, params) self.userDb = UserDatabase() def getTitle(self): answer = "SEHICL User Activation" return answer def getContent(self): answer = self.getActivationPage() return answer def getActivationPage(self): html = """ <h1>Activation successful</h1> <p>You have successfully activated the following account:</p> <ul> <li>Name: {user.name}</li> <li>E-mail: {user.email}</li> <li>Club: {user.club}</li> </ul> """ userId = self.allParams.get("user") try: userDetails = self.userDb.activateUser(userId) answer = html.format(user=userDetails) except UserException: answer = """ <h1>Activation failed</h1> <p>No user was found with the specified identity.</p> """ return answer
class UserActivation(Page): def __init__(self, pageId, params={}): Page.__init__(self, pageId, params) self.userDb = UserDatabase() def getTitle(self): answer = "SEHICL User Activation" return answer def getContent(self): answer = self.getActivationPage() return answer def getActivationPage(self): html = """ <h1>Activation successful</h1> <p>You have successfully activated the following account:</p> <ul> <li>Name: {user.name}</li> <li>E-mail: {user.email}</li> <li>Club: {user.club}</li> </ul> """ userId = self.allParams.get("user") try: userDetails = self.userDb.activateUser(userId) answer = html.format(user=userDetails) except UserException: answer = """ <h1>Activation failed</h1> <p>No user was found with the specified identity.</p> """ return answer
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()