From 5e34f6582b3c62ef381f6d7fc364601e0a3b77bd Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Tue, 12 Feb 2019 17:23:47 -0500 Subject: [PATCH] Tests for start permissions for JobTemplate and WorkflowJob when max_hosts is set. --- awx/main/tests/functional/test_rbac_job_start.py | 13 +++++++++++++ awx/main/tests/functional/test_rbac_workflow.py | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/awx/main/tests/functional/test_rbac_job_start.py b/awx/main/tests/functional/test_rbac_job_start.py index 6748b3df5d..d205d992d3 100644 --- a/awx/main/tests/functional/test_rbac_job_start.py +++ b/awx/main/tests/functional/test_rbac_job_start.py @@ -21,6 +21,19 @@ def test_admin_executing_permissions(deploy_jobtemplate, inventory, machine_cred assert admin_user.can_access(Credential, 'use', machine_credential) +@pytest.mark.django_db +@pytest.mark.job_permissions +def test_admin_executing_permissions_with_limits(deploy_jobtemplate, inventory, user): + admin_user = user('admin-user', True) + + inventory.organization.max_hosts = 1 + inventory.organization.save() + inventory.hosts.create(name="Existing host 1") + inventory.hosts.create(name="Existing host 2") + + assert admin_user.can_access(JobTemplate, 'start', deploy_jobtemplate) + + @pytest.mark.django_db @pytest.mark.job_permissions def test_job_template_start_access(deploy_jobtemplate, user): diff --git a/awx/main/tests/functional/test_rbac_workflow.py b/awx/main/tests/functional/test_rbac_workflow.py index 7a2fede786..04926385c0 100644 --- a/awx/main/tests/functional/test_rbac_workflow.py +++ b/awx/main/tests/functional/test_rbac_workflow.py @@ -140,6 +140,16 @@ class TestWorkflowJobAccess: JobLaunchConfig.objects.create(job=workflow_job) assert WorkflowJobAccess(rando).can_start(workflow_job) + def test_can_start_with_limits(self, workflow_job, inventory, admin_user): + inventory.organization.max_hosts = 1 + inventory.organization.save() + inventory.hosts.create(name="Existing host 1") + inventory.hosts.create(name="Existing host 2") + workflow_job.inventory = inventory + workflow_job.save() + + assert WorkflowJobAccess(admin_user).can_start(workflow_job) + def test_cannot_relaunch_friends_job(self, wfjt, rando, alice): workflow_job = wfjt.workflow_jobs.create(name='foo', created_by=alice) JobLaunchConfig.objects.create(