def _opmuse_setup_server(): configure(config_file=test_config_file, environment='production') remove_db() session = get_raw_session(create_all=True) run_fixtures(session) session.close()
def setup_db(self): configure(config_file=test_config_file, environment='production') remove_db() self.session = get_raw_session(create_all=True) run_fixtures(self.session)
def command_user(action=None, *args): if action == "add_role": if len(args) >= 1: name = args[0] database = get_raw_session() role = Role(name) database.add(role) database.commit() else: parser.error('Needs to provide a name.') elif action == "add": if len(args) >= 3: login = args[0] password = args[1] mail = args[2] if len(args) >= 4: role = args[3] else: role = None database = get_raw_session() salt = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(64)) user = User(login, hash_password(password, salt), mail, salt) database.add(user) if role is not None: role = database.query(Role).filter(Role.name == role).one() role.users.append(user) database.commit() else: parser.error('Needs to provide a login, password, mail and optionally role.') else: parser.error('Needs to provide a valid action (add, add_role).')
def run_fixtures(database=None): if database is None: database = get_raw_session() # begin fixtures salt = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(64)) admin_user = User('admin', hash_password("admin", salt), '*****@*****.**', salt) salt = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(64)) user_user = User('user', hash_password("user", salt), '*****@*****.**', salt) database.add(admin_user) database.add(user_user) admin_role = Role('admin') database.add(admin_role) admin_role.users.append(admin_user) # end fixtures database.commit()