def test_expected_data_mismatch(self):
     """Test token validation."""
     s = EmailConfirmationSerializer()
     t = s.create_token(1, self.extra_data)
     self.assertIsNotNone(s.validate_token(t))
     self.assertIsNone(s.validate_token(t, dict(notvalid=1)))
     self.assertIsNone(s.validate_token(t, dict(email='another@email')))
 def test_expired(self):
     """Test token expiry."""
     s = EmailConfirmationSerializer(expires_in=-20)
     t = s.create_token(1, self.extra_data)
     self.assertIsNone(s.validate_token(t))
     self.assertIsNone(s.validate_token(t, expected_data=self.extra_data))
     self.assertRaises(SignatureExpired, s.load_token, t)
     self.assertIsNotNone(s.load_token(t, force=True))
def test_email_confirmation_serializer_expected_data_mismatch(app, db):
    """Test token validation."""
    extra_data = dict(email="*****@*****.**")
    with app.app_context():
        s = EmailConfirmationSerializer()
        t = s.create_token(1, extra_data)
        assert s.validate_token(t) is not None
        assert s.validate_token(t, dict(notvalid=1)) is None
        assert s.validate_token(t, dict(email='another@email')) is None
def test_email_confirmation_serializer_expired(app, db):
    """Test token expiry."""
    extra_data = dict(email="*****@*****.**")
    with app.app_context():
        s = EmailConfirmationSerializer(expires_in=-20)
        t = s.create_token(1, extra_data)
        assert s.validate_token(t) is None
        assert s.validate_token(t, expected_data=extra_data) is None
        with pytest.raises(SignatureExpired):
            s.load_token(t)
        assert s.load_token(t, force=True) is not None
 def test_create_validate(self):
     """Test token creation."""
     s = EmailConfirmationSerializer()
     t = s.create_token(1, self.extra_data)
     data = s.validate_token(t, expected_data=self.extra_data)
     self.assertEqual(data['id'], 1)
     self.assertEqual(data['data'], dict(email="*****@*****.**"))
def test_email_confirmation_serializer_create_validate(app, db):
    """Test token creation."""
    extra_data = dict(email="*****@*****.**")
    with app.app_context():
        s = EmailConfirmationSerializer()
        t = s.create_token(1, extra_data)
        data = s.validate_token(t, expected_data=extra_data)
        assert data['id'] == 1
        assert data['data'] == extra_data