mirror of
https://github.com/ansible/awx.git
synced 2026-02-15 18:20:00 -03:30
Merge pull request #694 from AlanCoding/credentials_not_a_thing
adjust assertions about JT credentials to be correct
This commit is contained in:
@@ -3,7 +3,7 @@ import pytest
|
|||||||
# AWX
|
# AWX
|
||||||
from awx.api.serializers import JobTemplateSerializer
|
from awx.api.serializers import JobTemplateSerializer
|
||||||
from awx.api.versioning import reverse
|
from awx.api.versioning import reverse
|
||||||
from awx.main.models.jobs import Job
|
from awx.main.models.jobs import Job, JobTemplate
|
||||||
from awx.main.migrations import _save_password_keys as save_password_keys
|
from awx.main.migrations import _save_password_keys as save_password_keys
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
@@ -27,13 +27,17 @@ def test_create(post, project, machine_credential, inventory, alice, grant_proje
|
|||||||
if grant_inventory:
|
if grant_inventory:
|
||||||
inventory.use_role.members.add(alice)
|
inventory.use_role.members.add(alice)
|
||||||
|
|
||||||
post(reverse('api:job_template_list'), {
|
r = post(reverse('api:job_template_list'), {
|
||||||
'name': 'Some name',
|
'name': 'Some name',
|
||||||
'project': project.id,
|
'project': project.id,
|
||||||
'credentials': [machine_credential.id],
|
'credential': machine_credential.id, # TODO: remove in 3.3
|
||||||
'inventory': inventory.id,
|
'inventory': inventory.id,
|
||||||
'playbook': 'helloworld.yml',
|
'playbook': 'helloworld.yml',
|
||||||
}, alice, expect=expect)
|
}, alice)
|
||||||
|
if expect == 201:
|
||||||
|
jt = JobTemplate.objects.get(id=r.data['id'])
|
||||||
|
assert set(jt.credentials.values_list('id', flat=True)) == set([machine_credential.id])
|
||||||
|
assert r.status_code == expect
|
||||||
|
|
||||||
|
|
||||||
# TODO: remove in 3.3
|
# TODO: remove in 3.3
|
||||||
@@ -291,31 +295,27 @@ def test_filter_by_v1(get, organization_factory, job_template_factory, credentia
|
|||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"grant_project, grant_credential, grant_inventory, expect", [
|
"grant_project, grant_inventory, expect", [
|
||||||
(True, True, True, 200),
|
(True, True, 200),
|
||||||
(True, True, False, 403),
|
(True, False, 403),
|
||||||
(True, False, True, 403),
|
(False, True, 403),
|
||||||
(False, True, True, 403),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_edit_sensitive_fields(patch, job_template_factory, alice, grant_project, grant_credential, grant_inventory, expect):
|
def test_edit_sensitive_fields(patch, job_template_factory, alice, grant_project, grant_inventory, expect):
|
||||||
objs = job_template_factory('jt', organization='org1', project='prj', inventory='inv', credential='cred')
|
objs = job_template_factory('jt', organization='org1', project='prj', inventory='inv', credential='cred')
|
||||||
objs.job_template.admin_role.members.add(alice)
|
objs.job_template.admin_role.members.add(alice)
|
||||||
|
|
||||||
if grant_project:
|
if grant_project:
|
||||||
objs.project.use_role.members.add(alice)
|
objs.project.use_role.members.add(alice)
|
||||||
if grant_credential:
|
|
||||||
objs.credential.use_role.members.add(alice)
|
|
||||||
if grant_inventory:
|
if grant_inventory:
|
||||||
objs.inventory.use_role.members.add(alice)
|
objs.inventory.use_role.members.add(alice)
|
||||||
|
|
||||||
patch(reverse('api:job_template_detail', kwargs={'pk': objs.job_template.id}), {
|
patch(url=reverse('api:job_template_detail', kwargs={'pk': objs.job_template.id}), data={
|
||||||
'name': 'Some name',
|
'name': 'Some name',
|
||||||
'project': objs.project.id,
|
'project': objs.project.id,
|
||||||
'credentials': [objs.credential.id],
|
|
||||||
'inventory': objs.inventory.id,
|
'inventory': objs.inventory.id,
|
||||||
'playbook': 'alt-helloworld.yml',
|
'playbook': 'alt-helloworld.yml',
|
||||||
}, alice, expect=expect)
|
}, user=alice, expect=expect)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
|||||||
Reference in New Issue
Block a user