From e2bf3a02874165c370980a13cd9d82d6bd19bd58 Mon Sep 17 00:00:00 2001 From: sean-m-sullivan Date: Wed, 2 Sep 2020 07:19:11 -0500 Subject: [PATCH] update to use isdigit and updated tests --- .../plugins/modules/tower_project_update.py | 6 +++--- .../targets/tower_project_update/tasks/main.yml | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/awx_collection/plugins/modules/tower_project_update.py b/awx_collection/plugins/modules/tower_project_update.py index fc150cb00d..3586a27340 100644 --- a/awx_collection/plugins/modules/tower_project_update.py +++ b/awx_collection/plugins/modules/tower_project_update.py @@ -103,11 +103,11 @@ def main(): timeout = module.params.get('timeout') # Attempt to look up project based on the provided name or id - if name.isnumeric(): + if name.isdigit(): results = module.get_endpoint('projects', **{'data': {'id': name}}) + if results['json']['count'] == 0: + module.fail_json(msg='Could not find Project with ID: {0}'.format(name)) project = results['json']['results'][0] - if project is None: - module.fail_json(msg="Unable to find project") else: lookup_data = {'name': name} if organization: diff --git a/awx_collection/tests/integration/targets/tower_project_update/tasks/main.yml b/awx_collection/tests/integration/targets/tower_project_update/tasks/main.yml index 1b98e2e74f..08b9852018 100644 --- a/awx_collection/tests/integration/targets/tower_project_update/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_project_update/tasks/main.yml @@ -15,11 +15,11 @@ scm_type: git scm_url: https://github.com/ansible/test-playbooks wait: false - register: result + register: project_create_result - assert: that: - - result is changed + - project_create_result is changed - name: Update a project without waiting tower_project_update: @@ -43,6 +43,17 @@ that: - result is successful +- name: Update a project by ID + tower_project_update: + name: "{{ project_create_result.id }}" + organization: Default + wait: true + register: result + +- assert: + that: + - result is successful + - name: Delete the test project 1 tower_project: name: "{{ project_name1 }}"