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))
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'))
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))
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 == "*****@*****.**")
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"))
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 == '*****@*****.**')
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'))
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
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
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
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))
def test_password_salts_are_random(self): u = User(password='******') u2 = User(password='******') self.assertTrue(u.password_hash != u2.password_hash)
def test_password_verification(self): u = User(password='******') self.assertTrue(u.verify_password('cat')) self.assertFalse(u.verify_password('dog'))
def test_no_password_getter(self): u = User(password='******') with self.assertRaises(AttributeError): u.password
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
def test_roles_and_permissions(self): u = User(email='*****@*****.**', password='******') self.assertTrue(u.can(Permission.WRITE_ARTICLES)) self.assertFalse(u.can(Permission.PUBLISH_ARTICLES))
""" 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()
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
def test_password_verification(self): u = User(password="******") self.assertTrue(u.verify_password("cat")) self.assertFalse(u.verify_password("dog"))
def test_password_setter(self): u = User(password='******') self.assertTrue(u.password_hash is not None)
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