def init(): """ 初始化数据 """ su_role = Role.get_by_name(name="SuperUser") # create super user root = User.create( username="******", password="******", email="*****@*****.**", phonenum="1234567", active=True, confirmed_at=datetime.utcnow(), ) avator = Storages( name="AdminAvator.jpg", storetype="avator", saved=True, filetype="image/jpeg", path="default/AdminAvator.jpg", uid=1, ) UserInfo.create(user=root, avator=avator) root.roles.append(su_role) root.save()
def init_development_users(password: Optional[str] = None) -> None: """ 初始化数据 """ su_role = Role.get_by_name(name="SuperUser") if not password: print("请输入初始超级用户密码") password = getpass("Password:"******"wisdom", password=password, email="*****@*****.**", phonenum="1234567", active=True, confirmed_at=datetime.utcnow(), ) avator = Storages( name="AdminAvator.jpg", storetype="avator", saved=True, filetype="image/jpeg", path="default/AdminAvator.jpg", uid=1, store=load_avator_from_path("default/AdminAvator.jpg"), ) UserInfo.create(user=root, avator=avator) root.roles.append(su_role) root.save()
def test_model_creation(db: SQLAlchemy) -> None: from smorest_sfs.modules.users.models import User, UserInfo user = User.create(username="******", password="******", userinfo=UserInfo()) db.session.commit() assert ( user.nickname == "1212" and user.password == "1212" and str(user.userinfo) == "1212" ) UserInfo.where(id_=user.userinfo.id_).delete() User.where(id_=user.id_).delete()