def _insert_user(self, username, password, role_name): test_role = Role(role_name) db.session.add(test_role) db.session.commit() test_user = User(username) test_user.set_password(password) db.session.add(test_user) db.session.commit()
def generate_roles(): roles = list() for rolename in fake_roles: role = Role.query.filter_by(name=rolename).first() if role: roles.append(role) continue role = Role(rolename) roles.append(role) db.session.add(role) try: db.session.commit() except Exception as e: log.error("Erro inserting role: %s, %s" % (str(role), e)) db.session.rollback() return roles
def _insert_user(self, email, f_name, password, role): """ Create role and user :param email: User's email :param f_name: User's first name :param password: User's account password :param role: User's blog role """ with self.app.app_context(): test_role = Role(role) db.session.add(test_role) db.session.commit() test_user = User(email=email, f_name=f_name) test_user.set_password(password) db.session.add(test_user) db.session.commit()
def generate_users(): users = list() for item in fake_users: user = User.objects(username=item['username']).first() if user: users.append(user) continue user = User() role = Role.objects(name=item['role']).first() user.roles.append(role) user.username = item['username'] user.password = bcrypt.generate_password_hash("password") users.append(user) try: user.save() except Exception as e: log.error("Eror inserting user: %s, %s" % (str(user), e)) return users
from webapp import create_app, db from webapp.auth.models import User, Role app = create_app('config.TestConfig') db.app = app db.create_all() with app.app_context(): user_role = Role("user") author_role = Role("author") db.session.add(user_role) db.session.add(author_role) db.session.commit() test_user = User(email="*****@*****.**", f_name="test") test_user.set_password("test") test_user.roles.append(author_role) db.session.add(test_user) db.session.commit() app.run()
from webapp import create_app, db from webapp.auth.models import User, Role app = create_app("config.TestConfig") db.app = app db.create_all() default = Role("default") poster = Role("poster") db.session.add(default) db.session.add(poster) db.session.commit() test_user = User("test") test_user.set_password("test") test_user.roles.append(poster) db.session.add(test_user) db.session.commit() app.run()