Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'key': 'test-key',
}
action = ara_record.ActionModule(task, self.connection,
self.play_context, loader=None,
templar=None, shared_loader_obj=None)
action.run()
r_playbook = m.Playbook.query.first()
self.assertIsNotNone(r_playbook)
# There is no exception raised in the action module, we instead
# properly return a failure status to Ansible.
# If there is a failure, no data will be recorded so we can catch this.
with self.assertRaises(Exception):
m.Data.query.filter_by(playbook_id=r_playbook.id).one()
task.async = MagicMock()
task.args = {
'key': 'test-key',
'value': 'test-value',
'type': 'text'
}
action = ara_record.ActionModule(task, self.connection,
self.play_context, loader=None,
templar=None, shared_loader_obj=None)
action.run()
r_playbook = m.Playbook.query.first()
self.assertIsNotNone(r_playbook)
r_data = m.Data.query.filter_by(playbook_id=r_playbook.id,
key='test-key').one()
self.assertIsNotNone(r_data)
self.assertEqual(r_data.playbook_id, r_playbook.id)
self.assertEqual(r_data.key, 'test-key')
self.assertEqual(r_data.value, 'test-value')
self.assertEqual(r_data.type, 'text')
"""
task = MagicMock(Task)
task.async = MagicMock()
task.args = {
'key': 'test-key',
}
action = ara_read.ActionModule(task, self.connection,
self.play_context, loader=None,
templar=None, shared_loader_obj=None)
data = action.run()
r_playbook = m.Playbook.query.first()
self.assertIsNotNone(r_playbook)
r_data = m.Data.query.filter_by(playbook_id=r_playbook.id,
key='test-key').one()
self.assertIsNotNone(r_data)
self.assertEqual(r_data.playbook_id, r_playbook.id)
self.assertEqual(r_data.key, 'test-key')
self.assertEqual(r_data.value, 'test-value')
self.assertEqual(r_data.type, 'text')
self.assertEqual(data['playbook_id'], r_data.playbook_id)
self.assertEqual(data['key'], r_data.key)
self.assertEqual(data['value'], r_data.value)
self.assertEqual(data['type'], r_data.type)
'value': 'test-value'
}
action = ara_record.ActionModule(task, self.connection,
self.play_context, loader=None,
templar=None, shared_loader_obj=None)
action.run()
r_playbook = m.Playbook.query.first()
self.assertIsNotNone(r_playbook)
# There is no exception raised in the action module, we instead
# properly return a failure status to Ansible.
# If there is a failure, no data will be recorded so we can catch this.
with self.assertRaises(Exception):
m.Data.query.filter_by(playbook_id=r_playbook.id).one()
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
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
def get_key(self, playbook_id, key):
try:
data = (models.Data.query
.filter_by(key=key)
.filter_by(playbook_id=playbook_id)
.one())
except models.NoResultFound:
return False
return data
def get_key(self, playbook_id, key):
try:
data = (models.Data.query
.filter_by(key=key)
.filter_by(playbook_id=playbook_id)
.one())
except models.NoResultFound:
return False
return data