mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 16:51:11 +03:00
Merge pull request #687 from AlanCoding/new_kill
allow deletion of new jobs
This commit is contained in:
commit
ce6d96feda
@ -140,7 +140,8 @@ class UnifiedJobDeletionMixin(object):
|
||||
raise PermissionDenied(detail=_('Cannot delete job resource when associated workflow job is running.'))
|
||||
except self.model.unified_job_node.RelatedObjectDoesNotExist:
|
||||
pass
|
||||
if obj.status in ACTIVE_STATES:
|
||||
# Still allow deletion of new status, because these can be manually created
|
||||
if obj.status in ACTIVE_STATES and obj.status != 'new':
|
||||
raise PermissionDenied(detail=_("Cannot delete running job resource."))
|
||||
obj.delete()
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
|
@ -6,6 +6,10 @@ from awx.main.tests.base import URI
|
||||
from awx.main.models.unified_jobs import ACTIVE_STATES
|
||||
|
||||
|
||||
TEST_STATES = list(ACTIVE_STATES)
|
||||
TEST_STATES.remove('new')
|
||||
|
||||
|
||||
TEST_STDOUTS = []
|
||||
uri = URI(scheme="https", username="Dhh3U47nmC26xk9PKscV", password="PXPfWW8YzYrgS@E5NbQ2H@", host="github.ginger.com/theirrepo.git/info/refs")
|
||||
TEST_STDOUTS.append({
|
||||
@ -93,7 +97,7 @@ def test_options_fields_choices(instance, options, user):
|
||||
assert UnifiedJob.STATUS_CHOICES == response.data['actions']['GET']['status']['choices']
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", list(ACTIVE_STATES))
|
||||
@pytest.mark.parametrize("status", list(TEST_STATES))
|
||||
@pytest.mark.django_db
|
||||
def test_delete_job_in_active_state(job_factory, delete, admin, status):
|
||||
j = job_factory(initial_state=status)
|
||||
@ -101,7 +105,7 @@ def test_delete_job_in_active_state(job_factory, delete, admin, status):
|
||||
delete(url, None, admin, expect=403)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", list(ACTIVE_STATES))
|
||||
@pytest.mark.parametrize("status", list(TEST_STATES))
|
||||
@pytest.mark.django_db
|
||||
def test_delete_project_update_in_active_state(project, delete, admin, status):
|
||||
p = ProjectUpdate(project=project, status=status)
|
||||
@ -110,7 +114,7 @@ def test_delete_project_update_in_active_state(project, delete, admin, status):
|
||||
delete(url, None, admin, expect=403)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", list(ACTIVE_STATES))
|
||||
@pytest.mark.parametrize("status", list(TEST_STATES))
|
||||
@pytest.mark.django_db
|
||||
def test_delete_inventory_update_in_active_state(inventory_source, delete, admin, status):
|
||||
i = InventoryUpdate.objects.create(inventory_source=inventory_source, status=status)
|
||||
@ -118,7 +122,7 @@ def test_delete_inventory_update_in_active_state(inventory_source, delete, admin
|
||||
delete(url, None, admin, expect=403)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", list(ACTIVE_STATES))
|
||||
@pytest.mark.parametrize("status", list(TEST_STATES))
|
||||
@pytest.mark.django_db
|
||||
def test_delete_workflow_job_in_active_state(workflow_job_factory, delete, admin, status):
|
||||
wj = workflow_job_factory(initial_state=status)
|
||||
@ -126,7 +130,7 @@ def test_delete_workflow_job_in_active_state(workflow_job_factory, delete, admin
|
||||
delete(url, None, admin, expect=403)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", list(ACTIVE_STATES))
|
||||
@pytest.mark.parametrize("status", list(TEST_STATES))
|
||||
@pytest.mark.django_db
|
||||
def test_delete_system_job_in_active_state(system_job_factory, delete, admin, status):
|
||||
sys_j = system_job_factory(initial_state=status)
|
||||
@ -134,7 +138,7 @@ def test_delete_system_job_in_active_state(system_job_factory, delete, admin, st
|
||||
delete(url, None, admin, expect=403)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", list(ACTIVE_STATES))
|
||||
@pytest.mark.parametrize("status", list(TEST_STATES))
|
||||
@pytest.mark.django_db
|
||||
def test_delete_ad_hoc_command_in_active_state(ad_hoc_command_factory, delete, admin, status):
|
||||
adhoc = ad_hoc_command_factory(initial_state=status)
|
||||
|
@ -171,7 +171,8 @@ def project_factory(organization):
|
||||
@pytest.fixture
|
||||
def job_factory(job_template, admin):
|
||||
def factory(job_template=job_template, initial_state='new', created_by=admin):
|
||||
return job_template.create_job(created_by=created_by, status=initial_state)
|
||||
return job_template.create_unified_job(_eager_fields={
|
||||
'status': initial_state, 'created_by': created_by})
|
||||
return factory
|
||||
|
||||
|
||||
@ -528,18 +529,19 @@ def _request(verb):
|
||||
middleware.process_response(request, response)
|
||||
if expect:
|
||||
if response.status_code != expect:
|
||||
data_copy = response.data.copy()
|
||||
try:
|
||||
# Make translated strings printable
|
||||
for key, value in response.data.items():
|
||||
if isinstance(value, list):
|
||||
response.data[key] = []
|
||||
for item in value:
|
||||
response.data[key].append(str(value))
|
||||
else:
|
||||
response.data[key] = str(value)
|
||||
except Exception:
|
||||
response.data = data_copy
|
||||
if response.data is not None:
|
||||
try:
|
||||
data_copy = response.data.copy()
|
||||
# Make translated strings printable
|
||||
for key, value in response.data.items():
|
||||
if isinstance(value, list):
|
||||
response.data[key] = []
|
||||
for item in value:
|
||||
response.data[key].append(str(item))
|
||||
else:
|
||||
response.data[key] = str(value)
|
||||
except Exception:
|
||||
response.data = data_copy
|
||||
print(response.data)
|
||||
assert response.status_code == expect
|
||||
response.render()
|
||||
@ -665,7 +667,8 @@ def workflow_job_template(organization):
|
||||
@pytest.fixture
|
||||
def workflow_job_factory(workflow_job_template, admin):
|
||||
def factory(workflow_job_template=workflow_job_template, initial_state='new', created_by=admin):
|
||||
return workflow_job_template.create_unified_job(created_by=created_by, status=initial_state)
|
||||
return workflow_job_template.create_unified_job(_eager_fields={
|
||||
'status': initial_state, 'created_by': created_by})
|
||||
return factory
|
||||
|
||||
|
||||
@ -679,7 +682,8 @@ def system_job_template():
|
||||
@pytest.fixture
|
||||
def system_job_factory(system_job_template, admin):
|
||||
def factory(system_job_template=system_job_template, initial_state='new', created_by=admin):
|
||||
return system_job_template.create_unified_job(created_by=created_by, status=initial_state)
|
||||
return system_job_template.create_unified_job(_eager_fields={
|
||||
'status': initial_state, 'created_by': created_by})
|
||||
return factory
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user