1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

Merge pull request #6909 from AlanCoding/no_manual_source_proj

Disallow manual projects for SCM inventory
This commit is contained in:
Alan Rominger 2017-07-12 12:08:19 -04:00 committed by GitHub
commit 4afb65f447
4 changed files with 24 additions and 5 deletions

View File

@ -1637,6 +1637,11 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
ret['inventory'] = None
return ret
def validate_source_project(self, value):
if value.scm_type == '':
raise serializers.ValidationError(_("Can not use manual project for SCM-based inventory."))
return value
def validate(self, attrs):
def get_field_from_model_or_attrs(fd):
return attrs.get(fd, self.instance and getattr(self.instance, fd) or None)

View File

@ -333,8 +333,8 @@ def test_prefetch_jt_copy_capability(job_template, project, inventory,
@pytest.mark.django_db
def test_manual_projects_no_update(project, get, admin_user):
response = get(reverse('api:project_detail', kwargs={'pk': project.pk}), admin_user, expect=200)
def test_manual_projects_no_update(manual_project, get, admin_user):
response = get(reverse('api:project_detail', kwargs={'pk': manual_project.pk}), admin_user, expect=200)
assert not response.data['summary_fields']['user_capabilities']['start']
assert not response.data['summary_fields']['user_capabilities']['schedule']

View File

@ -133,7 +133,21 @@ def project(instance, organization):
organization=organization,
playbook_files=['helloworld.yml', 'alt-helloworld.yml'],
local_path='_92__test_proj',
scm_revision='1234567890123456789012345678901234567890'
scm_revision='1234567890123456789012345678901234567890',
scm_url='localhost',
scm_type='git'
)
return prj
@pytest.fixture
@mock.patch.object(Project, "update", lambda self, **kwargs: None)
def manual_project(instance, organization):
prj = Project.objects.create(name="test-manual-proj",
description="manual-proj-desc",
organization=organization,
playbook_files=['helloworld.yml', 'alt-helloworld.yml'],
local_path='_92__test_proj'
)
return prj

View File

@ -230,9 +230,9 @@ def test_patch_project_null_organization_xfail(patch, project, org_admin):
@pytest.mark.django_db
def test_cannot_schedule_manual_project(project, admin_user, post):
def test_cannot_schedule_manual_project(manual_project, admin_user, post):
response = post(
reverse('api:project_schedules_list', kwargs={'pk':project.pk,}),
reverse('api:project_schedules_list', kwargs={'pk':manual_project.pk,}),
{
"name": "foo", "description": "", "enabled": True,
"rrule": "DTSTART:20160926T040000Z RRULE:FREQ=HOURLY;INTERVAL=1",