Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_mutating_job_templates(self):
with self.recorder:
job_template = 'Demo Job Template'
job_template_broken = 'Demo Job TemplateBroken'
with self.assertRaises(InvalidJobTemplate):
self.team.add_job_template_permission_admin(job_template_broken)
self.assertTrue(self.team.add_job_template_permission_admin(job_template))
with self.assertRaises(InvalidJobTemplate):
self.team.remove_job_template_permission_admin(job_template_broken)
self.assertTrue(self.team.remove_job_template_permission_admin(job_template))
with self.assertRaises(InvalidJobTemplate):
self.team.add_job_template_permission_execute(job_template_broken)
self.assertTrue(self.team.add_job_template_permission_execute(job_template))
with self.assertRaises(InvalidJobTemplate):
self.team.remove_job_template_permission_execute(job_template_broken)
self.assertTrue(self.team.remove_job_template_permission_execute(job_template))
def test_mutating_job_templates(self):
with self.recorder:
job_template = 'Demo Job Template'
job_template_broken = 'Demo Job TemplateBroken'
with self.assertRaises(InvalidJobTemplate):
self.team.add_job_template_permission_admin(job_template_broken)
self.assertTrue(self.team.add_job_template_permission_admin(job_template))
with self.assertRaises(InvalidJobTemplate):
self.team.remove_job_template_permission_admin(job_template_broken)
self.assertTrue(self.team.remove_job_template_permission_admin(job_template))
with self.assertRaises(InvalidJobTemplate):
self.team.add_job_template_permission_execute(job_template_broken)
self.assertTrue(self.team.add_job_template_permission_execute(job_template))
with self.assertRaises(InvalidJobTemplate):
self.team.remove_job_template_permission_execute(job_template_broken)
self.assertTrue(self.team.remove_job_template_permission_execute(job_template))
args = copy.deepcopy(arguments)
args['job_type'] = 'Broken'
_ = self.tower.create_job_template(**args)
with self.assertRaises(InvalidVerbosity):
args = copy.deepcopy(arguments)
args['verbosity'] = 11
_ = self.tower.create_job_template(**args)
arguments['instance_groups'] = 'tower'
job_template = self.tower.create_job_template(**arguments)
self.assertIsInstance(job_template, JobTemplate)
self.assertIsNone(self.tower.create_job_template(**arguments))
job_template_by_name = self.tower.get_job_template_by_name(job_template.name)
self.assertEqual(job_template.id, job_template_by_name.id)
job_template_by_id = self.tower.get_job_template_by_id(job_template.id)
self.assertEqual(job_template.id, job_template_by_id.id)
with self.assertRaises(InvalidJobTemplate):
self.tower.delete_job_template('NoneExistentJobTemplate')
self.assertTrue(self.tower.delete_job_template(job_template.name))
def _post_job_template_permission(self, job_template_name, permission_name, remove=False):
job_template = self._tower.get_job_template_by_name(job_template_name)
if not job_template:
raise InvalidJobTemplate(job_template_name)
return self._post_permission(job_template.object_roles, permission_name, remove)
def delete_job_template(self, name):
"""Deletes a job template from tower.
Args:
name: The name of the job template to delete.
Returns:
bool: True on success, False otherwise.
Raises:
InvalidJobTemplate: The job template provided as argument does not exist.
"""
job_template = self.get_job_template_by_name(name)
if not job_template:
raise InvalidJobTemplate(name)
return job_template.delete()
assert InvalidUserLevel
assert InvalidOrganization
assert InvalidVariables
assert InvalidInventory
assert InvalidUser
assert InvalidTeam
assert InvalidCredential
assert InvalidGroup
assert InvalidHost
assert InvalidProject
assert InvalidCredentialType
assert InvalidPlaybook
assert InvalidInstanceGroup
assert InvalidJobType
assert InvalidVerbosity
assert InvalidJobTemplate
assert PermissionNotFound
assert InvalidValue
assert InvalidRole
# assert objects
assert Tower
assert Organization
assert User
assert Role
assert Team
assert Project
assert Group
assert Inventory
assert Host
assert Instance
assert InstanceGroup