def test_valid_email_change_token(self):
     u = User(email='*****@*****.**', password='******')
     db.session.add(u)
     db.session.commit()
     token = u.generate_email_change_token('*****@*****.**')
     self.assertTrue(u.change_email(token))
     self.assertTrue(u.email == '*****@*****.**')
 def test_duplicate_email_change_token(self):
     u1 = User(email='*****@*****.**', password='******')
     u2 = User(email='*****@*****.**', password='******')
     db.session.add(u1)
     db.session.add(u2)
     db.session.commit()
     token = u2.generate_email_change_token('*****@*****.**')
     self.assertFalse(u2.change_email(token))
     self.assertTrue(u2.email == '*****@*****.**')