mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -03:30
remove user from jobs (redundant, since we have created_by) and add start of jobs REST testing.
This commit is contained in:
parent
7d224d8cf3
commit
6bb4f4f255
@ -208,7 +208,7 @@ class JobTemplateAdmin(BaseModelAdmin):
|
||||
(None, {'fields': ('name', 'active', 'description',
|
||||
'get_create_link_display', 'get_jobs_link_display')}),
|
||||
(_('Job Parameters'), {'fields': ('inventory', 'project', 'credential',
|
||||
'user', 'job_type')}),
|
||||
'job_type')}),
|
||||
#(_('Tags'), {'fields': ('tags',)}),
|
||||
(_('Audit Trail'), {'fields': ('creation_date', 'created_by',
|
||||
'audit_trail',)}),
|
||||
@ -231,8 +231,8 @@ class JobTemplateAdmin(BaseModelAdmin):
|
||||
create_opts['project'] = obj.project.pk
|
||||
if obj.credential:
|
||||
create_opts['credential'] = obj.credential.pk
|
||||
if obj.user:
|
||||
create_opts['user'] = obj.user.pk
|
||||
#if obj.user:
|
||||
# create_opts['user'] = obj.user.pk
|
||||
create_url += '?%s' % urllib.urlencode(create_opts)
|
||||
return format_html('<a href="{0}">{1}</a>', create_url, 'Create Job')
|
||||
get_create_link_display.short_description = _('Create Job')
|
||||
@ -265,7 +265,7 @@ class JobAdmin(BaseModelAdmin):
|
||||
fieldsets = (
|
||||
(None, {'fields': ('name', 'job_template', 'description')}),
|
||||
(_('Job Parameters'), {'fields': ('inventory', 'project', 'credential',
|
||||
'user', 'job_type')}),
|
||||
'job_type')}),
|
||||
#(_('Tags'), {'fields': ('tags',)}),
|
||||
(_('Audit Trail'), {'fields': ('creation_date', 'created_by',
|
||||
'audit_trail',)}),
|
||||
|
||||
111
lib/main/tests/jobs.py
Normal file
111
lib/main/tests/jobs.py
Normal file
@ -0,0 +1,111 @@
|
||||
# Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
#
|
||||
# This file is part of Ansible Commander.
|
||||
#
|
||||
# Ansible Commander is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Ansible Commander is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible Commander. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
import json
|
||||
|
||||
from django.contrib.auth.models import User as DjangoUser
|
||||
import django.test
|
||||
from django.test.client import Client
|
||||
from lib.main.models import *
|
||||
from lib.main.tests.base import BaseTest
|
||||
|
||||
class JobsTest(BaseTest):
|
||||
|
||||
def collection(self):
|
||||
# not really used
|
||||
return '/api/v1/job_templates/'
|
||||
|
||||
def setUp(self):
|
||||
super(JobsTest, self).setUp()
|
||||
self.setup_users()
|
||||
|
||||
self.organization = Organization.objects.create(
|
||||
name = 'engineering',
|
||||
created_by = self.normal_django_user
|
||||
)
|
||||
|
||||
self.inventory = Inventory.objects.create(
|
||||
name = 'prod',
|
||||
organization = self.organization,
|
||||
created_by = self.normal_django_user
|
||||
)
|
||||
|
||||
self.group_a = Group.objects.create(
|
||||
name = 'group1',
|
||||
inventory = self.inventory,
|
||||
created_by = self.normal_django_user
|
||||
)
|
||||
|
||||
self.host_a = Host.objects.create(
|
||||
name = '127.0.0.1',
|
||||
inventory = self.inventory,
|
||||
created_by = self.normal_django_user
|
||||
)
|
||||
|
||||
self.host_b = Host.objects.create(
|
||||
name = '127.0.0.2',
|
||||
inventory = self.inventory,
|
||||
created_by = self.normal_django_user
|
||||
)
|
||||
|
||||
self.group_a.hosts.add(self.host_a)
|
||||
self.group_a.hosts.add(self.host_b)
|
||||
self.group_a.save()
|
||||
|
||||
self.project = Project.objects.create(
|
||||
name = 'testProject',
|
||||
created_by = self.normal_django_user,
|
||||
local_repository = '/tmp/',
|
||||
scm_type = 'git',
|
||||
default_playbook = 'site.yml',
|
||||
)
|
||||
|
||||
self.credential = Credential.objects.create(
|
||||
ssh_key_data = 'xxx',
|
||||
created_by = self.normal_django_user
|
||||
)
|
||||
|
||||
self.organization.projects.add(self.project)
|
||||
self.organization.admins.add(self.normal_django_user)
|
||||
self.organization.users.add(self.normal_django_user)
|
||||
self.organization.save()
|
||||
|
||||
self.template1 = JobTemplate.objects.create(
|
||||
name = 'job-run',
|
||||
job_type = 'run',
|
||||
inventory = self.inventory,
|
||||
credential = self.credential,
|
||||
project = self.project,
|
||||
)
|
||||
self.template2 = JobTemplate.objects.create(
|
||||
name = 'job-check',
|
||||
job_type = 'check',
|
||||
inventory = self.inventory,
|
||||
credential = self.credential,
|
||||
project = self.project,
|
||||
)
|
||||
|
||||
|
||||
def test_get_list(self):
|
||||
|
||||
# no credentials == 401
|
||||
data = self.get('/api/v1/job_templates/', expect=401)
|
||||
data = self.get('/api/v1/job_templates/', expect=200, auth=self.get_normal_credentials())
|
||||
#print data
|
||||
self.assertTrue(data['count'], 99)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user