mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 03:47:36 -02:30
make arguments to mk_ methods explicit
This commit is contained in:
@@ -25,108 +25,100 @@ def mk_instance(persisted=True):
|
|||||||
return Instance.objects.get_or_create(uuid=settings.SYSTEM_UUID, primary=True, hostname="instance.example.org")
|
return Instance.objects.get_or_create(uuid=settings.SYSTEM_UUID, primary=True, hostname="instance.example.org")
|
||||||
|
|
||||||
|
|
||||||
def mk_organization(name, desc, persisted=True):
|
def mk_organization(name, description=None, persisted=True):
|
||||||
org = Organization(name=name, description=desc)
|
description = description or '{}-description'.format(name)
|
||||||
|
org = Organization(name=name, description=description)
|
||||||
if persisted:
|
if persisted:
|
||||||
mk_instance(True)
|
mk_instance(persisted)
|
||||||
org.save()
|
org.save()
|
||||||
return org
|
return org
|
||||||
|
|
||||||
|
|
||||||
def mk_label(name, **kwargs):
|
def mk_label(name, organization=None, description=None, persisted=True):
|
||||||
label = Label(name=name, description="%s-desc".format(name))
|
description = description or '{}-description'.format(name)
|
||||||
organization = kwargs.get('organization')
|
label = Label(name=name, description=description)
|
||||||
if organization is not None:
|
if organization is not None:
|
||||||
label.organization = organization
|
label.organization = organization
|
||||||
if kwargs.get('persisted', True):
|
if persisted:
|
||||||
label.save()
|
label.save()
|
||||||
return label
|
return label
|
||||||
|
|
||||||
|
|
||||||
def mk_team(name, **kwargs):
|
def mk_team(name, organization=None, persisted=True):
|
||||||
team = Team(name=name)
|
team = Team(name=name)
|
||||||
organization = kwargs.get('organization')
|
|
||||||
if organization is not None:
|
if organization is not None:
|
||||||
team.organization = organization
|
team.organization = organization
|
||||||
if kwargs.get('persisted', True):
|
if persisted:
|
||||||
mk_instance(True)
|
mk_instance(persisted)
|
||||||
team.save()
|
team.save()
|
||||||
return team
|
return team
|
||||||
|
|
||||||
|
|
||||||
def mk_user(name, **kwargs):
|
def mk_user(name, is_superuser=False, organization=None, team=None, persisted=True):
|
||||||
user = User(username=name, is_superuser=kwargs.get('is_superuser', False))
|
user = User(username=name, is_superuser=is_superuser)
|
||||||
|
if persisted:
|
||||||
if kwargs.get('persisted', True):
|
|
||||||
user.save()
|
user.save()
|
||||||
organization = kwargs.get('organization')
|
|
||||||
if organization is not None:
|
if organization is not None:
|
||||||
organization.member_role.members.add(user)
|
organization.member_role.members.add(user)
|
||||||
team = kwargs.get('team')
|
|
||||||
if team is not None:
|
if team is not None:
|
||||||
team.member_role.members.add(user)
|
team.member_role.members.add(user)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def mk_project(name, **kwargs):
|
def mk_project(name, organization=None, description=None, persisted=True):
|
||||||
project = Project(name=name)
|
description = description or '{}-description'.format(name)
|
||||||
organization = kwargs.get('organization')
|
project = Project(name=name, description=description)
|
||||||
if organization is not None:
|
if organization is not None:
|
||||||
project.organization = organization
|
project.organization = organization
|
||||||
if kwargs.get('persisted', True):
|
if persisted:
|
||||||
project.save()
|
project.save()
|
||||||
return project
|
return project
|
||||||
|
|
||||||
|
|
||||||
def mk_credential(name, **kwargs):
|
def mk_credential(name, cloud=False, kind='ssh', persisted=True):
|
||||||
cred = Credential(name=name)
|
cred = Credential(name=name, cloud=cloud, kind=kind)
|
||||||
cred.cloud = kwargs.get('cloud', False)
|
if persisted:
|
||||||
cred.kind = kwargs.get('kind', 'ssh')
|
|
||||||
if kwargs.get('persisted', True):
|
|
||||||
cred.save()
|
cred.save()
|
||||||
return cred
|
return cred
|
||||||
|
|
||||||
|
|
||||||
def mk_notification_template(name, **kwargs):
|
def mk_notification_template(name, notification_type='webhook', configuration=None, organization=None, persisted=True):
|
||||||
nt = NotificationTemplate(name=name)
|
nt = NotificationTemplate(name=name)
|
||||||
nt.notification_type = kwargs.get('type', 'webhook')
|
nt.notification_type = notification_type
|
||||||
|
nt.notification_configuration = configuration or dict(url="http://localhost", headers={"Test": "Header"})
|
||||||
|
|
||||||
configuration = kwargs.get('configuration',
|
|
||||||
dict(url="http://localhost", headers={"Test": "Header"}))
|
|
||||||
nt.notification_configuration = configuration
|
|
||||||
|
|
||||||
organization = kwargs.get('organization')
|
|
||||||
if organization is not None:
|
if organization is not None:
|
||||||
nt.organization = organization
|
nt.organization = organization
|
||||||
if kwargs.get('persisted', True):
|
if persisted:
|
||||||
nt.save()
|
nt.save()
|
||||||
return nt
|
return nt
|
||||||
|
|
||||||
|
|
||||||
def mk_inventory(name, **kwargs):
|
def mk_inventory(name, organization=None, persisted=True):
|
||||||
inv = Inventory(name=name)
|
inv = Inventory(name=name)
|
||||||
organization = kwargs.get('organization', None)
|
|
||||||
if organization is not None:
|
if organization is not None:
|
||||||
inv.organization = organization
|
inv.organization = organization
|
||||||
if kwargs.get('persisted', True):
|
if persisted:
|
||||||
inv.save()
|
inv.save()
|
||||||
return inv
|
return inv
|
||||||
|
|
||||||
|
|
||||||
def mk_job_template(name, **kwargs):
|
def mk_job_template(name, job_type='run',
|
||||||
jt = JobTemplate(name=name, job_type=kwargs.get('job_type', 'run'))
|
organization=None, inventory=None,
|
||||||
|
credential=None, persisted=True,
|
||||||
|
project=None):
|
||||||
|
jt = JobTemplate(name=name, job_type=job_type)
|
||||||
|
|
||||||
jt.inventory = kwargs.get('inventory', None)
|
jt.inventory = inventory
|
||||||
if jt.inventory is None:
|
if jt.inventory is None:
|
||||||
jt.ask_inventory_on_launch = True
|
jt.ask_inventory_on_launch = True
|
||||||
|
|
||||||
jt.credential = kwargs.get('credential', None)
|
jt.credential = credential
|
||||||
if jt.credential is None:
|
if jt.credential is None:
|
||||||
jt.ask_credential_on_launch = True
|
jt.ask_credential_on_launch = True
|
||||||
|
|
||||||
jt.project = kwargs.get('project', None)
|
jt.project = project
|
||||||
|
|
||||||
if kwargs.get('persisted', True):
|
if persisted:
|
||||||
jt.save()
|
jt.save()
|
||||||
return jt
|
return jt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user