From 5da02690c112d5ec785b5d8034e8ab4e3249775c Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Sat, 26 Jun 2021 01:28:02 -0400 Subject: [PATCH] Fix copy_from warning message - warn() does not take keyword 'msg' - add testing around the copy_from parameter for project creation --- .../plugins/module_utils/controller_api.py | 2 +- awx_collection/test/awx/test_project.py | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/awx_collection/plugins/module_utils/controller_api.py b/awx_collection/plugins/module_utils/controller_api.py index a5a33729eb..e32a6001f3 100644 --- a/awx_collection/plugins/module_utils/controller_api.py +++ b/awx_collection/plugins/module_utils/controller_api.py @@ -421,7 +421,7 @@ class ControllerAPIModule(ControllerModule): def copy_item(self, existing_item, copy_from_name_or_id, new_item_name, endpoint=None, item_type='unknown', copy_lookup_data=None): if existing_item is not None: - self.warn(msg="A {0} with the name {1} already exists.".format(item_type, new_item_name)) + self.warn("A {0} with the name {1} already exists.".format(item_type, new_item_name)) self.json_output['changed'] = False self.json_output['copied'] = False return existing_item diff --git a/awx_collection/test/awx/test_project.py b/awx_collection/test/awx/test_project.py index ed49754800..ec930fde9e 100644 --- a/awx_collection/test/awx/test_project.py +++ b/awx_collection/test/awx/test_project.py @@ -24,3 +24,26 @@ def test_create_project(run_module, admin_user, organization, silence_warning): result.pop('invocation') assert result == {'name': 'foo', 'id': proj.id} + +@pytest.mark.django_db +def test_create_project_copy_from(run_module, admin_user, organization, silence_warning): + ''' Test the copy_from functionality''' + result = run_module( + 'project', + dict(name='foo', organization=organization.name, scm_type='git', scm_url='https://foo.invalid', wait=False, scm_update_cache_timeout=5), + admin_user, + ) + assert result.pop('changed', None), result + proj_name = 'bar' + result = run_module( + 'project', + dict(name=proj_name, copy_from='foo', scm_type='git', wait=False), + admin_user, + ) + assert result.pop('changed', None), result + result = run_module( + 'project', + dict(name=proj_name, copy_from='foo', scm_type='git', wait=False), + admin_user, + ) + silence_warning.assert_called_with(f"A project with the name {proj_name} already exists.")