UMS Email Password Change 22
# tests/test_user_model.py
# ...
class BasicTestCase(unittest.TestCase):
# ...
def test_email_change(self):
u = User(email='john@example.com', username='john', password='cat')
db.session.add(u)
db.session.commit()
token = u.generate_email_change_token('john@example.com')
self.assertFalse(u.email_change(token))
token = u.generate_email_change_token('mary@example.com')
self.assertTrue(u.email_change(token))
self.assertEqual(u.email, 'mary@example.com')
self.assertNotEqual(u.email, 'john@example.com')
token = u.generate_email_change_token(None)
self.assertFalse(u.email_change(token))
token = u.generate_email_change_token('john@example.com')
db.session.delete(u)
db.session.commit()
self.assertFalse(u.email_change(token))