Exemplo n.º 1
0
 def test_expired_confirmation_token(self):
     u = User(password='******')
     db.session.add(u)
     db.session.commit()
     token = u.generate_confirmation_token()
     time.sleep(2)
     self.assertFalse(u.confirm(token, 1))
Exemplo n.º 2
0
 def test_expired_confirmation_token(self):
     u = User(password='******')
     db.session.add(u)
     db.session.commit()
     token = u.generate_confirmation_token()
     time.sleep(2)
     self.assertFalse(u.confirm(token, 1))
Exemplo n.º 3
0
 def test_valid_reset_token(self):
     u = User(password='******')
     db.session.add(u)
     db.session.commit()
     token = u.generate_reset_token()
     self.assertTrue(u.reset_password(token, 'dog'))
     self.assertTrue(u.verify_password('dog'))
Exemplo n.º 4
0
 def test_valid_reset_token(self):
     u = User(password='******')
     db.session.add(u)
     db.session.commit()
     token = u.generate_reset_token()
     self.assertTrue(u.reset_password(token, 'dog'))
     self.assertTrue(u.verify_password('dog'))
Exemplo n.º 5
0
 def test_invalid_confirmation_token(self):
     u1 = User(password='******')
     u2 = User(password='******')
     db.session.add(u1)
     db.session.add(u2)
     db.session.commit()
     token = u1.generate_confirmation_token()
     self.assertFalse(u2.confirm(token))
Exemplo n.º 6
0
 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 == "*****@*****.**")
Exemplo n.º 7
0
 def test_invalid_reset_token(self):
     u1 = User(password="******")
     u2 = User(password="******")
     db.session.add(u1)
     db.session.add(u2)
     db.session.commit()
     token = u1.generate_reset_token()
     self.assertFalse(u2.reset_password(token, "horse"))
     self.assertTrue(u2.verify_password("dog"))
Exemplo n.º 8
0
 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 == '*****@*****.**')
Exemplo n.º 9
0
 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 == '*****@*****.**')
Exemplo n.º 10
0
 def test_invalid_reset_token(self):
     u1 = User(password='******')
     u2 = User(password='******')
     db.session.add(u1)
     db.session.add(u2)
     db.session.commit()
     token = u1.generate_reset_token()
     self.assertFalse(u2.reset_password(token, 'horse'))
     self.assertTrue(u2.verify_password('dog'))
Exemplo n.º 11
0
 def test_make_unique_nickname(self):
     u = User(username="******", email="*****@*****.**")
     db.session.add(u)
     db.session.commit()
     username = User.make_unique_username("john")
     assert username != "john"
     u = User(username=username, email="*****@*****.**")
     db.session.add(u)
     db.session.commit()
     username2 = User.make_unique_username("john")
     assert username2 != "john"
     assert username2 != username
Exemplo n.º 12
0
 def test_make_unique_nickname(self):
     u = User(username = '******', email = '*****@*****.**')
     db.session.add(u)
     db.session.commit()
     username = User.make_unique_username('john')
     assert username != 'john'
     u = User(username = username, email = '*****@*****.**')
     db.session.add(u)
     db.session.commit()
     username2 = User.make_unique_username('john')
     assert username2 != 'john'
     assert username2 != username
Exemplo n.º 13
0
 def test_make_unique_nickname(self):
     u = User(username='******', email='*****@*****.**')
     db.session.add(u)
     db.session.commit()
     username = User.make_unique_username('john')
     assert username != 'john'
     u = User(username=username, email='*****@*****.**')
     db.session.add(u)
     db.session.commit()
     username2 = User.make_unique_username('john')
     assert username2 != 'john'
     assert username2 != username
Exemplo n.º 14
0
 def test_invalid_reset_token(self):
     u1 = User(password='******')
     u2 = User(password='******')
     db.session.add(u1)
     db.session.add(u2)
     db.session.commit()
     token = u1.generate_reset_token()
     self.assertFalse(u2.reset_password(token, 'horse'))
     self.assertTrue(u2.verify_password('dog'))
Exemplo n.º 15
0
 def test_invalid_confirmation_token(self):
     u1 = User(password='******')
     u2 = User(password='******')
     db.session.add(u1)
     db.session.add(u2)
     db.session.commit()
     token = u1.generate_confirmation_token()
     self.assertFalse(u2.confirm(token))
Exemplo n.º 16
0
 def test_valid_confirmation_token(self):
     u = User(password='******')
     db.session.add(u)
     db.session.commit()
     token = u.generate_confirmation_token()
     self.assertTrue(u.confirm(token))
Exemplo n.º 17
0
 def test_password_salts_are_random(self):
     u = User(password='******')
     u2 = User(password='******')
     self.assertTrue(u.password_hash != u2.password_hash)
Exemplo n.º 18
0
 def test_password_verification(self):
     u = User(password='******')
     self.assertTrue(u.verify_password('cat'))
     self.assertFalse(u.verify_password('dog'))
Exemplo n.º 19
0
 def test_no_password_getter(self):
     u = User(password='******')
     with self.assertRaises(AttributeError):
         u.password
Exemplo n.º 20
0
 def test_password_verification(self):
     u = User(password='******')
     self.assertTrue(u.verify_password('cat'))
     self.assertFalse(u.verify_password('dog'))
Exemplo n.º 21
0
 def test_avatar(self):
     u = User(username='******', email='*****@*****.**')
     with self.app.test_request_context('/'):
         avatar = u.gravatar(128)
         expected = 'https://secure.gravatar.com/avatar/d4c74594d841139328695756648b6bd6'
         assert avatar[0:len(expected)] == expected
Exemplo n.º 22
0
 def test_roles_and_permissions(self):
     u = User(email='*****@*****.**', password='******')
     self.assertTrue(u.can(Permission.WRITE_ARTICLES))
     self.assertFalse(u.can(Permission.PUBLISH_ARTICLES))
Exemplo n.º 23
0
"""
Just for development time
"""

from manage import db
from wtxlog.models import User, Role, Category

if __name__ == '__main__':
    # init database
    db.create_all()

    # create user roles
    Role.insert_roles()

    # add administrator
    user = User()
    user.username = '******'
    user.password = '******'
    user.email = '*****@*****.**'
    user.role = Role.query.filter_by(permissions=0xff).first()
    user.confirmed = True

    # add default category
    category = Category()
    category.slug = 'default'
    category.name = 'Default'

    # commit
    db.session.add(user)
    db.session.add(category)
    db.session.commit()
Exemplo n.º 24
0
 def test_avatar(self):
     u = User(username = '******', email = '*****@*****.**')
     with self.app.test_request_context('/'):
         avatar = u.gravatar(128)
         expected = 'http://www.gravatar.com/avatar/d4c74594d841139328695756648b6bd6'
         assert avatar[0:len(expected)] == expected
Exemplo n.º 25
0
 def test_roles_and_permissions(self):
     u = User(email='*****@*****.**', password='******')
     self.assertTrue(u.can(Permission.WRITE_ARTICLES))
     self.assertFalse(u.can(Permission.PUBLISH_ARTICLES))
Exemplo n.º 26
0
 def test_password_verification(self):
     u = User(password="******")
     self.assertTrue(u.verify_password("cat"))
     self.assertFalse(u.verify_password("dog"))
Exemplo n.º 27
0
 def test_password_setter(self):
     u = User(password='******')
     self.assertTrue(u.password_hash is not None)
Exemplo n.º 28
0
 def test_avatar(self):
     u = User(username="******", email="*****@*****.**")
     with self.app.test_request_context("/"):
         avatar = u.gravatar(128)
         expected = "https://secure.gravatar.com/avatar/d4c74594d841139328695756648b6bd6"
         assert avatar[0 : len(expected)] == expected
Exemplo n.º 29
0
 def test_valid_confirmation_token(self):
     u = User(password='******')
     db.session.add(u)
     db.session.commit()
     token = u.generate_confirmation_token()
     self.assertTrue(u.confirm(token))