mirror of
https://github.com/ansible/awx.git
synced 2026-09-04 19:08:30 -02:30
Add scm_revision to project updates and cleanup
Add validation around prompted scm_branch requiring project allow_override field to be true Updated related process isolation docs Fix invalid comarision in serializer from PR review, clarify pre-check logging, minor docs additions
This commit is contained in:
@@ -516,6 +516,25 @@ def test_job_launch_JT_with_credentials(machine_credential, credential, net_cred
|
||||
assert machine_credential in creds
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_job_branch_rejected_and_accepted(deploy_jobtemplate):
|
||||
deploy_jobtemplate.ask_scm_branch_on_launch = True
|
||||
deploy_jobtemplate.save()
|
||||
prompted_fields, ignored_fields, errors = deploy_jobtemplate._accept_or_ignore_job_kwargs(
|
||||
scm_branch='foobar'
|
||||
)
|
||||
assert 'scm_branch' in ignored_fields
|
||||
assert 'does not allow override of branch' in errors['scm_branch']
|
||||
|
||||
deploy_jobtemplate.project.allow_override = True
|
||||
deploy_jobtemplate.project.save()
|
||||
prompted_fields, ignored_fields, errors = deploy_jobtemplate._accept_or_ignore_job_kwargs(
|
||||
scm_branch='foobar'
|
||||
)
|
||||
assert not ignored_fields
|
||||
assert prompted_fields['scm_branch'] == 'foobar'
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.job_runtime_vars
|
||||
def test_job_launch_unprompted_vars_with_survey(mocker, survey_spec_factory, job_template_prompts, post, admin_user):
|
||||
|
||||
@@ -505,3 +505,37 @@ def test_callback_disallowed_null_inventory(project):
|
||||
with pytest.raises(ValidationError) as exc:
|
||||
serializer.validate({'host_config_key': 'asdfbasecfeee'})
|
||||
assert 'Cannot enable provisioning callback without an inventory set' in str(exc)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_job_template_branch_error(project, inventory, post, admin_user):
|
||||
r = post(
|
||||
url=reverse('api:job_template_list'),
|
||||
data={
|
||||
"name": "fooo",
|
||||
"inventory": inventory.pk,
|
||||
"project": project.pk,
|
||||
"playbook": "helloworld.yml",
|
||||
"scm_branch": "foobar"
|
||||
},
|
||||
user=admin_user,
|
||||
expect=400
|
||||
)
|
||||
assert 'Project does not allow overriding branch' in str(r.data['scm_branch'])
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_job_template_branch_prompt_error(project, inventory, post, admin_user):
|
||||
r = post(
|
||||
url=reverse('api:job_template_list'),
|
||||
data={
|
||||
"name": "fooo",
|
||||
"inventory": inventory.pk,
|
||||
"project": project.pk,
|
||||
"playbook": "helloworld.yml",
|
||||
"ask_scm_branch_on_launch": True
|
||||
},
|
||||
user=admin_user,
|
||||
expect=400
|
||||
)
|
||||
assert 'Project does not allow overriding branch' in str(r.data['ask_scm_branch_on_launch'])
|
||||
|
||||
@@ -10,12 +10,12 @@ from awx.api.versioning import reverse
|
||||
@pytest.mark.django_db
|
||||
class TestInsightsCredential:
|
||||
def test_insights_credential(self, patch, insights_project, admin_user, insights_credential):
|
||||
patch(insights_project.get_absolute_url(),
|
||||
patch(insights_project.get_absolute_url(),
|
||||
{'credential': insights_credential.id}, admin_user,
|
||||
expect=200)
|
||||
|
||||
def test_non_insights_credential(self, patch, insights_project, admin_user, scm_credential):
|
||||
patch(insights_project.get_absolute_url(),
|
||||
patch(insights_project.get_absolute_url(),
|
||||
{'credential': scm_credential.id}, admin_user,
|
||||
expect=400)
|
||||
|
||||
@@ -44,3 +44,24 @@ def test_project_unset_custom_virtualenv(get, patch, project, admin, value):
|
||||
url = reverse('api:project_detail', kwargs={'pk': project.id})
|
||||
resp = patch(url, {'custom_virtualenv': value}, user=admin, expect=200)
|
||||
assert resp.data['custom_virtualenv'] is None
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_no_changing_overwrite_behavior(post, patch, organization, admin_user):
|
||||
r1 = post(
|
||||
url=reverse('api:project_list'),
|
||||
data={
|
||||
'name': 'fooo',
|
||||
'organization': organization.id,
|
||||
'allow_override': True
|
||||
},
|
||||
user=admin_user,
|
||||
expect=201
|
||||
)
|
||||
r2 = patch(
|
||||
url=reverse('api:project_detail', kwargs={'pk': r1.data['id']}),
|
||||
data={'allow_override': False},
|
||||
user=admin_user,
|
||||
expect=400
|
||||
)
|
||||
assert 'cannot be changed' in str(r2.data['allow_override'])
|
||||
|
||||
@@ -256,7 +256,7 @@ class TestExtraVarSanitation(TestJobExecution):
|
||||
|
||||
def test_vars_unsafe_by_default(self, job, private_data_dir):
|
||||
job.created_by = User(pk=123, username='angry-spud')
|
||||
job.inventory = Inventory(pk=123, name='example-inv')
|
||||
job.inventory = Inventory(pk=123, name='example-inv')
|
||||
|
||||
task = tasks.RunJob()
|
||||
task.build_extra_vars_file(job, private_data_dir)
|
||||
@@ -367,10 +367,10 @@ class TestGenericRun():
|
||||
task = tasks.RunJob()
|
||||
task.update_model = mock.Mock(return_value=job)
|
||||
task.build_private_data_files = mock.Mock(side_effect=OSError())
|
||||
task.copy_folders = mock.Mock()
|
||||
|
||||
with pytest.raises(Exception):
|
||||
task.run(1)
|
||||
with mock.patch('awx.main.tasks.copy_tree'):
|
||||
with pytest.raises(Exception):
|
||||
task.run(1)
|
||||
|
||||
update_model_call = task.update_model.call_args[1]
|
||||
assert 'OSError' in update_model_call['result_traceback']
|
||||
@@ -386,10 +386,10 @@ class TestGenericRun():
|
||||
task = tasks.RunJob()
|
||||
task.update_model = mock.Mock(wraps=update_model_wrapper)
|
||||
task.build_private_data_files = mock.Mock()
|
||||
task.copy_folders = mock.Mock()
|
||||
|
||||
with pytest.raises(Exception):
|
||||
task.run(1)
|
||||
with mock.patch('awx.main.tasks.copy_tree'):
|
||||
with pytest.raises(Exception):
|
||||
task.run(1)
|
||||
|
||||
for c in [
|
||||
mock.call(1, status='running', start_args=''),
|
||||
@@ -1722,8 +1722,6 @@ class TestProjectUpdateCredentials(TestJobExecution):
|
||||
call_args, _ = task._write_extra_vars_file.call_args_list[0]
|
||||
_, extra_vars = call_args
|
||||
|
||||
assert extra_vars["scm_revision_output"] == 'foobar'
|
||||
|
||||
def test_username_and_password_auth(self, project_update, scm_type):
|
||||
task = tasks.RunProjectUpdate()
|
||||
ssh = CredentialType.defaults['ssh']()
|
||||
|
||||
Reference in New Issue
Block a user