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 testRemindOfPasswordEmailDoesNotExist(self): conn = self.inMemoryDatabaseConnection() email = "jeremy" userDb = UserDatabase() userDb.emailSender = DummyEmailSender() try: userDb.remindOfPassword(email, conn) self.fail("Should have thrown an exception") except UserException as ex: self.assertEquals(UserException.emailNotFound, ex.message) self.assertEquals(None, ex.cause)
def testRemindOfPasswordEmailExists(self): conn = self.inMemoryDatabaseConnection() email = "jeremy" password = "******" c = conn.cursor() c.execute("insert into user (id, email) values (?, ?)", (1, email)) c.execute("insert into password (id, password) values (?, ?)", (1, password)) userDb = UserDatabase() userDb.emailSender = DummyEmailSender() userDb.remindOfPassword(email, conn) self.assertEquals([email], userDb.emailSender.messages[0].addressees)
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 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 testRegisterBlocked(self): conn = self.inMemoryDatabaseConnection() email = "*****@*****.**" name = "Jeremy" club = None password = "******" userDb = UserDatabase() userDb.emailSender = DummyEmailSender() result = userDb.registerUser(email, name, club, password, conn) self.assertEquals(-1, result) c = conn.cursor() row = c.execute("select id, email, name, club, status from user").fetchone() self.assertEquals(None, row) row = c.execute("select password from password where id = ?", (result,)).fetchone() self.assertEquals(None, row) self.assertEquals([], userDb.emailSender.messages)
def testRegisterEmailDoesNotAlreadyExistClubNotSpecified(self): conn = self.inMemoryDatabaseConnection() email = "jeremy" name = "Jeremy" club = None password = "******" userDb = UserDatabase() userDb.emailSender = DummyEmailSender() result = userDb.registerUser(email, name, club, password, conn) c = conn.cursor() 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) self.assertEquals([email], userDb.emailSender.messages[0].addressees) self.assertEquals([Settings.adminEmail], userDb.emailSender.messages[1].addressees)
def testRegisterBlocked(self): conn = self.inMemoryDatabaseConnection() email = "*****@*****.**" name = "Jeremy" club = None password = "******" userDb = UserDatabase() userDb.emailSender = DummyEmailSender() result = userDb.registerUser(email, name, club, password, conn) self.assertEquals(-1, result) c = conn.cursor() row = c.execute( "select id, email, name, club, status from user").fetchone() self.assertEquals(None, row) row = c.execute("select password from password where id = ?", (result, )).fetchone() self.assertEquals(None, row) self.assertEquals([], userDb.emailSender.messages)
def testRegisterEmailDoesNotAlreadyExistClubNotSpecified(self): conn = self.inMemoryDatabaseConnection() email = "jeremy" name = "Jeremy" club = None password = "******" userDb = UserDatabase() userDb.emailSender = DummyEmailSender() result = userDb.registerUser(email, name, club, password, conn) c = conn.cursor() 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) self.assertEquals([email], userDb.emailSender.messages[0].addressees) self.assertEquals([Settings.adminEmail], userDb.emailSender.messages[1].addressees)
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)