def create(): data = request.get_json() try: result = User.create(**data) except CRUDError as e: result = e.messages except valid_crud_errors as e: result = CRUDError(e).messages except ValidationError as e: result = {'errors': e.messages} return jsonify(result)
def install(username, password): if not database_exists(db.engine.url): create_database(db.engine.url) db.create_all() if database_exists(db.engine.url): user = User.query.filter_by(name=username).first() if user: user.password = password else: user = User.create( name=username, password=password, permission=Permission.ADMINISTRATOR, active=True) user.save() else: click.secho("User table does not exists, please create User table!")
def app(): db_fd, db_file = tempfile.mkstemp() app = create_app() app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + db_file print('pytest start') with app.app_context(): db.drop_all() db.create_all() user = User.create(name=DEFAULT_USERNAME, password=DEFAULT_PASSWORD, permission=Permission.ADMINISTRATOR, active=True) yield app print('pytest stop') with app.app_context(): db.session.remove() db.drop_all() os.close(db_fd) os.unlink(db_file)