jasminefiner
9/21/2018 - 2:42 PM

01: Test Confirmation Tokens

UMS: User Registration 1

# tests/test_user_models.py
# ...
class BasicTestCase(unittest.TestCase):
    # ...
    def test_valid_confirmation_token(self):
        u = User(password='cat')
        token = u.generate_confirmation_token()
        self.assertTrue(u.confirm(token))

    def test_invalid_confirmation_token(self):
        u1 = User(email='john@example.com', username='john', password='cat')
        u2 = User(email='mary@example.com', username='mary', password='cat')
        db.session.add(u1)
        db.session.add(u2)
        db.session.commit()
        token = u1.generate_confirmation_token()
        self.assertFalse(u2.confirm(token))