Merge pull request #687 from AlanCoding/new_kill

allow deletion of new jobs
This commit is contained in:
Alan Rominger
2017-11-21 07:20:05 -05:00
committed by GitHub
3 changed files with 31 additions and 22 deletions

View File

@@ -140,7 +140,8 @@ class UnifiedJobDeletionMixin(object):
raise PermissionDenied(detail=_('Cannot delete job resource when associated workflow job is running.')) raise PermissionDenied(detail=_('Cannot delete job resource when associated workflow job is running.'))
except self.model.unified_job_node.RelatedObjectDoesNotExist: except self.model.unified_job_node.RelatedObjectDoesNotExist:
pass 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.")) raise PermissionDenied(detail=_("Cannot delete running job resource."))
obj.delete() obj.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)

View File

@@ -6,6 +6,10 @@ from awx.main.tests.base import URI
from awx.main.models.unified_jobs import ACTIVE_STATES from awx.main.models.unified_jobs import ACTIVE_STATES
TEST_STATES = list(ACTIVE_STATES)
TEST_STATES.remove('new')
TEST_STDOUTS = [] TEST_STDOUTS = []
uri = URI(scheme="https", username="Dhh3U47nmC26xk9PKscV", password="PXPfWW8YzYrgS@E5NbQ2H@", host="github.ginger.com/theirrepo.git/info/refs") uri = URI(scheme="https", username="Dhh3U47nmC26xk9PKscV", password="PXPfWW8YzYrgS@E5NbQ2H@", host="github.ginger.com/theirrepo.git/info/refs")
TEST_STDOUTS.append({ 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'] 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 @pytest.mark.django_db
def test_delete_job_in_active_state(job_factory, delete, admin, status): def test_delete_job_in_active_state(job_factory, delete, admin, status):
j = job_factory(initial_state=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) delete(url, None, admin, expect=403)
@pytest.mark.parametrize("status", list(ACTIVE_STATES)) @pytest.mark.parametrize("status", list(TEST_STATES))
@pytest.mark.django_db @pytest.mark.django_db
def test_delete_project_update_in_active_state(project, delete, admin, status): def test_delete_project_update_in_active_state(project, delete, admin, status):
p = ProjectUpdate(project=project, status=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) delete(url, None, admin, expect=403)
@pytest.mark.parametrize("status", list(ACTIVE_STATES)) @pytest.mark.parametrize("status", list(TEST_STATES))
@pytest.mark.django_db @pytest.mark.django_db
def test_delete_inventory_update_in_active_state(inventory_source, delete, admin, status): def test_delete_inventory_update_in_active_state(inventory_source, delete, admin, status):
i = InventoryUpdate.objects.create(inventory_source=inventory_source, status=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) delete(url, None, admin, expect=403)
@pytest.mark.parametrize("status", list(ACTIVE_STATES)) @pytest.mark.parametrize("status", list(TEST_STATES))
@pytest.mark.django_db @pytest.mark.django_db
def test_delete_workflow_job_in_active_state(workflow_job_factory, delete, admin, status): def test_delete_workflow_job_in_active_state(workflow_job_factory, delete, admin, status):
wj = workflow_job_factory(initial_state=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) delete(url, None, admin, expect=403)
@pytest.mark.parametrize("status", list(ACTIVE_STATES)) @pytest.mark.parametrize("status", list(TEST_STATES))
@pytest.mark.django_db @pytest.mark.django_db
def test_delete_system_job_in_active_state(system_job_factory, delete, admin, status): def test_delete_system_job_in_active_state(system_job_factory, delete, admin, status):
sys_j = system_job_factory(initial_state=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) delete(url, None, admin, expect=403)
@pytest.mark.parametrize("status", list(ACTIVE_STATES)) @pytest.mark.parametrize("status", list(TEST_STATES))
@pytest.mark.django_db @pytest.mark.django_db
def test_delete_ad_hoc_command_in_active_state(ad_hoc_command_factory, delete, admin, status): def test_delete_ad_hoc_command_in_active_state(ad_hoc_command_factory, delete, admin, status):
adhoc = ad_hoc_command_factory(initial_state=status) adhoc = ad_hoc_command_factory(initial_state=status)

View File

@@ -171,7 +171,8 @@ def project_factory(organization):
@pytest.fixture @pytest.fixture
def job_factory(job_template, admin): def job_factory(job_template, admin):
def factory(job_template=job_template, initial_state='new', created_by=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 return factory
@@ -528,18 +529,19 @@ def _request(verb):
middleware.process_response(request, response) middleware.process_response(request, response)
if expect: if expect:
if response.status_code != expect: if response.status_code != expect:
data_copy = response.data.copy() if response.data is not None:
try: try:
# Make translated strings printable data_copy = response.data.copy()
for key, value in response.data.items(): # Make translated strings printable
if isinstance(value, list): for key, value in response.data.items():
response.data[key] = [] if isinstance(value, list):
for item in value: response.data[key] = []
response.data[key].append(str(value)) for item in value:
else: response.data[key].append(str(item))
response.data[key] = str(value) else:
except Exception: response.data[key] = str(value)
response.data = data_copy except Exception:
response.data = data_copy
print(response.data) print(response.data)
assert response.status_code == expect assert response.status_code == expect
response.render() response.render()
@@ -665,7 +667,8 @@ def workflow_job_template(organization):
@pytest.fixture @pytest.fixture
def workflow_job_factory(workflow_job_template, admin): def workflow_job_factory(workflow_job_template, admin):
def factory(workflow_job_template=workflow_job_template, initial_state='new', created_by=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 return factory
@@ -679,7 +682,8 @@ def system_job_template():
@pytest.fixture @pytest.fixture
def system_job_factory(system_job_template, admin): def system_job_factory(system_job_template, admin):
def factory(system_job_template=system_job_template, initial_state='new', created_by=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 return factory