def test_valid_email_change_token(self): """Test a valid email change token""" usr = User(email='*****@*****.**', password='******') db.session.add(usr) db.session.commit() token = usr.generate_email_change_token('*****@*****.**') self.assertTrue(usr.change_email(token)) self.assertTrue(usr.email == '*****@*****.**')
def test_wrong_email_change_token(self): """Test that a email change token from another user fails""" usr1 = User(email='*****@*****.**', password='******') usr2 = User(email='*****@*****.**', password='******') db.session.add(usr1) db.session.add(usr2) db.session.commit() token = usr2.generate_email_change_token('*****@*****.**') self.assertFalse(usr2.change_email(token)) self.assertTrue(usr2.email == '*****@*****.**')
def test_invalid_email_change_token(self): """Test that an email change token for non-existing user fails""" usr1 = User(email='*****@*****.**', password='******') usr2 = User(email='*****@*****.**', password='******') db.session.add(usr1) db.session.add(usr2) db.session.commit() token = usr1.generate_email_change_token('*****@*****.**') self.assertFalse(usr2.change_email(token)) self.assertTrue(usr2.email == '*****@*****.**')