From bb3c4c78f88a88d353a1c00ab763b8927214a5c1 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Thu, 6 Jul 2017 15:06:46 -0400 Subject: [PATCH] do not allow inv src source_project of manual type --- awx/api/serializers.py | 5 +++++ .../tests/functional/api/test_rbac_displays.py | 4 ++-- awx/main/tests/functional/conftest.py | 16 +++++++++++++++- awx/main/tests/functional/test_projects.py | 4 ++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 54959f4f1a..f29adb3d4c 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1635,6 +1635,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) diff --git a/awx/main/tests/functional/api/test_rbac_displays.py b/awx/main/tests/functional/api/test_rbac_displays.py index ca83d6df4a..523e057465 100644 --- a/awx/main/tests/functional/api/test_rbac_displays.py +++ b/awx/main/tests/functional/api/test_rbac_displays.py @@ -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'] diff --git a/awx/main/tests/functional/conftest.py b/awx/main/tests/functional/conftest.py index e2d34a06cd..879e6ab3fd 100644 --- a/awx/main/tests/functional/conftest.py +++ b/awx/main/tests/functional/conftest.py @@ -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 diff --git a/awx/main/tests/functional/test_projects.py b/awx/main/tests/functional/test_projects.py index 69c5fdcf65..31792683d9 100644 --- a/awx/main/tests/functional/test_projects.py +++ b/awx/main/tests/functional/test_projects.py @@ -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",