Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
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()