def users(): if UserModel.table_exists(): UserModel.truncate_table(cascade=True) UserModel.create_table() salt = os.urandom(32) users = [ UserModel.create( username="******", email_address="*****@*****.**", key=get_hash(password="******", salt=salt), salt=salt, role=UserRole.ADMIN, ), UserModel.create( username="******", email_address="*****@*****.**", key=get_hash(password="******", salt=salt), salt=salt, role=UserRole.ADMIN, ), UserModel.create( username="******", email_address="*****@*****.**", key=get_hash(password="******", salt=salt), salt=salt, ), UserModel.create( username="******", email_address="*****@*****.**", key=get_hash(password="******", salt=salt), salt=salt, ), ] yield users UserModel.truncate_table(cascade=True)
def create_user(): validated_body = get_validated_body() salt = os.urandom(32) try: user = UserModel.create( username=validated_body.get("username"), email_address=validated_body.get("email_address"), salt=salt, key=get_hash(password=validated_body.get("password"), salt=salt), ) except IntegrityError: raise BadRequest() except Exception as e: pass return user, 201
def seed_users(): user_data = [ { "username": "******", "password": "******", "salt": os.urandom(32), "email_address": "*****@*****.**", "role": UserRole.ADMIN, }, { "username": "******", "password": "******", "salt": os.urandom(32), "email_address": "*****@*****.**", "role": UserRole.ADMIN, }, { "username": "******", "password": "******", "salt": os.urandom(32), "email_address": "*****@*****.**", }, { "username": "******", "password": "******", "salt": os.urandom(32), "email_address": "*****@*****.**", }, ] for data in user_data: user = UserModel.create( **data, key=get_hash(password=data["password"], salt=data["salt"]), ) logger.info(f"Created {user}") yield user
def seed(): salt = os.urandom(32) password = "******" micko = UserModel.create( username="******", email_address="*****@*****.**", salt=salt, key=get_hash(password=password, salt=salt), role=UserRole.ADMIN, ) logging.info(f"Created {micko.username}") michael = UserModel.create( username="******", email_address="*****@*****.**", salt=salt, key=get_hash(password=password, salt=salt), role=UserRole.ADMIN, ) logging.info(f"Created {michael.username}") angelo = UserModel.create( username="******", email_address="*****@*****.**", salt=salt, key=get_hash(password=password, salt=salt), ) logging.info(f"Created {angelo.username}") rivera = UserModel.create( username="******", email_address="*****@*****.**", salt=salt, key=get_hash(password=password, salt=salt), ) logging.info(f"Created {rivera.username}") for admin in (micko, michael): for list_index in range(2): app_list = ListModel.create( author=admin, title=f"{admin.username} list {list_index}") logging.info(f"{admin.username} created {app_list.title}") for card_index in range(3): card = CardModel.create( author=admin, list=app_list, title=f"{app_list.title} Card {card_index}", description= f"{app_list.title} Card {card_index} Description", ) logging.info( f"{admin.username} created {card.title} on {app_list}") for comment_index in range(5): comment = CommentModel.create( author=admin, card=card, content=f"{card.title} Comment {comment_index}", ) logging.info( f"{admin.username} commented {comment.content} on {card.title}" ) for reply_index in range(5): comment_reply = CommentReplyModel.create( author=admin, comment=comment, content= f"{comment.content} Comment Reply {reply_index}", ) logging.info( f"{admin.username} commented {comment_reply.content} on {comment.content}" )