Exemplo 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 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)
Exemplo n.º 12
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)