def test_authenticateUser(self): newUser = user.addUser("dust", "goodPassword") self.assertIsNone(user.authenticateUser("dust", "badPassword")) self.assertEqual(user.authenticateUser("dust", "goodPassword"), newUser) self.assertIsNone(user.authenticateUser("fakeUsername", "goodPassword"))
def test_editUser(self): user1 = user.getUser("username") user1new = user.editUser(user1, username="******") self.assertEqual(user1.id, user1new.id) self.assertEqual(user1new.username, "farquad") user1 = user.addUser("Test1", "Test1", "Test1") self.assertRaises(ValueError, lambda: user.editUser(user1, "Test2", "ah")) user1new = user.getUser(user1.id) self.assertEqual(user1.username, user1new.username) #Test rollback user1new = user.editUser(user1, password="******") self.assertTrue(user.authenticateUser(user1new.username, "newPassword"))
def login(): error = None if request.method == 'POST': # Authenticate the given user with this username and password username = request.form['username'] password = request.form['password'] user = authenticateUser(username, password) if user: user_login(user) return redirect(url_for('home')) else: error = 'Incorrect username or password entered.' return render_template('login.html', error=error)