Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
m.db.create_all()
self.client = self.app.test_client()
def tearDown(self):
m.db.session.remove()
m.db.drop_all()
def tearDown(self):
m.db.session.remove()
m.db.drop_all()
def setUp(self):
m.db.create_all()
self.playbook = m.Playbook(path='testing.yml')
self.play = m.Play(
name='test play',
playbook=self.playbook,
)
self.task = m.Task(
name='test task',
play=self.play,
playbook=self.playbook,
)
self.data = m.Data(
playbook=self.playbook,
def create_or_update_key(self, playbook_id, key, value, type):
try:
data = (models.Data.query
.filter_by(key=key)
.filter_by(playbook_id=playbook_id)
.one())
data.value = value
data.type = type
except models.NoResultFound:
data = models.Data(playbook_id=playbook_id,
key=key,
value=value,
type=type)
db.session.add(data)
db.session.commit()
return data
res = models.Playbook.query.get(pid)
if res is None:
if args.ignore_errors:
self.log.warning('Playbook %s does not exist '
'(ignoring)' % pid)
else:
raise RuntimeError('Playbook %s does not exist' % pid)
else:
pids.append(pid)
for pid in pids:
self.log.warning('deleting playbook %s', pid)
playbook = models.Playbook.query.get(pid)
db.session.delete(playbook)
db.session.commit()
def configure_db(app):
"""
0.10 is the first version of ARA that ships with a stable database schema.
We can identify a database that originates from before this by checking if
there is an alembic revision available.
If there is no alembic revision available, assume we are running the first
revision which contains the latest state of the database prior to this.
"""
models.db.init_app(app)
log = logging.getLogger('ara.webapp.configure_db')
log.debug('Setting up database...')
if app.config.get('ARA_AUTOCREATE_DATABASE'):
with app.app_context():
migrations = app.config['DB_MIGRATIONS']
flask_migrate.Migrate(app, models.db, directory=migrations)
config = app.extensions['migrate'].migrate.get_config(migrations)
# Verify if the database tables have been created at all
inspector = Inspector.from_engine(models.db.engine)
if len(inspector.get_table_names()) == 0:
log.info('Initializing new DB from scratch')
flask_migrate.upgrade(directory=migrations)
# Get current alembic head revision
def createall():
db.create_all()
def configure_db(app):
"""
0.10 is the first version of ARA that ships with a stable database schema.
We can identify a database that originates from before this by checking if
there is an alembic revision available.
If there is no alembic revision available, assume we are running the first
revision which contains the latest state of the database prior to this.
"""
models.db.init_app(app)
log = logging.getLogger('ara.webapp.configure_db')
log.debug('Setting up database...')
if app.config.get('ARA_AUTOCREATE_DATABASE'):
with app.app_context():
migrations = app.config['DB_MIGRATIONS']
flask_migrate.Migrate(app, models.db, directory=migrations)
config = app.extensions['migrate'].migrate.get_config(migrations)
# Verify if the database tables have been created at all
inspector = Inspector.from_engine(models.db.engine)
if len(inspector.get_table_names()) == 0:
log.info('Initializing new DB from scratch')
flask_migrate.upgrade(directory=migrations)
# Get current alembic head revision
script = ScriptDirectory.from_config(config)
head = script.get_current_head()
# Get current revision, if available
connection = models.db.engine.connect()
context = MigrationContext.configure(connection)
current = context.get_current_revision()