mirror of
https://github.com/ansible/awx.git
synced 2026-02-18 19:50:05 -03:30
Further refine error message and update integration tests
Fix test with spaces pep8 failure More test tweaks Even more test fixes
This commit is contained in:
@@ -123,12 +123,12 @@ class TowerAPIModule(TowerModule):
|
|||||||
if name_field in new_data:
|
if name_field in new_data:
|
||||||
self.fail_json(msg="You can't specify the field {0} in your search data if using the name_or_id field".format(name_field))
|
self.fail_json(msg="You can't specify the field {0} in your search data if using the name_or_id field".format(name_field))
|
||||||
|
|
||||||
new_data['or__{0}'.format(name_field)] = name_or_id
|
|
||||||
try:
|
try:
|
||||||
new_data['or__id'] = int(name_or_id)
|
new_data['or__id'] = int(name_or_id)
|
||||||
|
new_data['or__{0}'.format(name_field)] = name_or_id
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# If we get a value error, then we didn't have an integer so we can just pass and fall down to the fail
|
# If we get a value error, then we didn't have an integer so we can just pass and fall down to the fail
|
||||||
pass
|
new_data[name_field] = name_or_id
|
||||||
new_kwargs['data'] = new_data
|
new_kwargs['data'] = new_data
|
||||||
|
|
||||||
response = self.get_endpoint(endpoint, **new_kwargs)
|
response = self.get_endpoint(endpoint, **new_kwargs)
|
||||||
@@ -160,11 +160,13 @@ class TowerAPIModule(TowerModule):
|
|||||||
|
|
||||||
def fail_wanted_one(self, response, endpoint, query_params):
|
def fail_wanted_one(self, response, endpoint, query_params):
|
||||||
sample = response.copy()
|
sample = response.copy()
|
||||||
if len(sample['json']['results']) < 1:
|
if len(sample['json']['results']) > 1:
|
||||||
sample['json']['results'] = sample['json']['results'][:2] + ['...more results snipped...']
|
sample['json']['results'] = sample['json']['results'][:2] + ['...more results snipped...']
|
||||||
|
url = self.build_url(endpoint, query_params)
|
||||||
|
display_endpoint = url.geturl()[len(self.host):] # truncate to not include the base URL
|
||||||
self.fail_json(
|
self.fail_json(
|
||||||
msg="Request to {0} returned {1} items, expected 1".format(
|
msg="Request to {0} returned {1} items, expected 1".format(
|
||||||
self.build_url(endpoint, query_params).geturl(), response['json']['count']
|
display_endpoint, response['json']['count']
|
||||||
),
|
),
|
||||||
query=query_params,
|
query=query_params,
|
||||||
response=sample,
|
response=sample,
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ def test_conflicting_name_and_id(run_module, admin_user):
|
|||||||
)
|
)
|
||||||
assert team.organization.name == 'foo'
|
assert team.organization.name == 'foo'
|
||||||
|
|
||||||
|
|
||||||
def test_multiple_lookup(run_module, admin_user):
|
def test_multiple_lookup(run_module, admin_user):
|
||||||
org1 = Organization.objects.create(name='foo')
|
org1 = Organization.objects.create(name='foo')
|
||||||
org2 = Organization.objects.create(name='bar')
|
org2 = Organization.objects.create(name='bar')
|
||||||
@@ -140,4 +141,3 @@ def test_multiple_lookup(run_module, admin_user):
|
|||||||
assert 'foo' in result['msg']
|
assert 'foo' in result['msg']
|
||||||
assert 'returned 2 items, expected 1' in result['msg']
|
assert 'returned 2 items, expected 1' in result['msg']
|
||||||
assert 'query' in result
|
assert 'query' in result
|
||||||
|
|
||||||
|
|||||||
@@ -288,7 +288,7 @@
|
|||||||
- name: Create an invalid SSH credential (Organization not found)
|
- name: Create an invalid SSH credential (Organization not found)
|
||||||
tower_credential:
|
tower_credential:
|
||||||
name: SSH Credential
|
name: SSH Credential
|
||||||
organization: Missing Organization
|
organization: Missing_Organization
|
||||||
state: present
|
state: present
|
||||||
kind: ssh
|
kind: ssh
|
||||||
username: joe
|
username: joe
|
||||||
@@ -298,7 +298,9 @@
|
|||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result is failed"
|
- "result is failed"
|
||||||
- "'The organizations Missing Organization was not found on the Tower server' in result.msg"
|
- "result is not changed"
|
||||||
|
- "'Missing_Organization' in result.msg"
|
||||||
|
- "result.total_results == 0"
|
||||||
|
|
||||||
- name: Delete an SSH credential
|
- name: Delete an SSH credential
|
||||||
tower_credential:
|
tower_credential:
|
||||||
@@ -750,5 +752,7 @@
|
|||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is failed
|
- "result is failed"
|
||||||
- "result.msg =='The organizations test-non-existing-org was not found on the Tower server'"
|
- "result is not changed"
|
||||||
|
- "'test-non-existing-org' in result.msg"
|
||||||
|
- "result.total_results == 0"
|
||||||
|
|||||||
@@ -51,8 +51,10 @@
|
|||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result.msg =='Failed to update the group, inventory not found: The requested object could not be found.' or
|
- "result is failed"
|
||||||
result.msg =='The inventories test-non-existing-inventory was not found on the Tower server'"
|
- "result is not changed"
|
||||||
|
- "'test-non-existing-inventory' in result.msg"
|
||||||
|
- "result.total_results == 0"
|
||||||
|
|
||||||
- name: add hosts
|
- name: add hosts
|
||||||
tower_host:
|
tower_host:
|
||||||
|
|||||||
@@ -46,5 +46,6 @@
|
|||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result.msg =='The inventories test-non-existing-inventory was not found on the Tower server' or
|
- "result is failed"
|
||||||
result.msg =='Failed to update host, inventory not found: The requested object could not be found.'"
|
- "'test-non-existing-inventory' in result.msg"
|
||||||
|
- "result.total_results == 0"
|
||||||
|
|||||||
@@ -119,9 +119,11 @@
|
|||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
|
- "result is failed"
|
||||||
- "result is not changed"
|
- "result is not changed"
|
||||||
- "result.msg =='Failed to update inventory, organization not found: The requested object could not be found.'
|
- "'test-non-existing-org' in result.msg"
|
||||||
or result.msg =='The organizations test-non-existing-org was not found on the Tower server'"
|
- "result.total_results == 0"
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete Inventories
|
- name: Delete Inventories
|
||||||
tower_inventory:
|
tower_inventory:
|
||||||
|
|||||||
@@ -29,16 +29,16 @@
|
|||||||
|
|
||||||
- name: Check module fails with correct msg
|
- name: Check module fails with correct msg
|
||||||
tower_job_launch:
|
tower_job_launch:
|
||||||
job_template: "Non Existing Job Template"
|
job_template: "Non_Existing_Job_Template"
|
||||||
inventory: "Test Inventory"
|
inventory: "Demo Inventory"
|
||||||
credential: "Test Credential"
|
|
||||||
register: result
|
register: result
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result.msg =='Unable to launch job, job_template/Non Existing Job Template was not found: The requested object could not be found.'
|
- "result is failed"
|
||||||
or result.msg == 'The inventories Test Inventory was not found on the Tower server'"
|
- "result is not changed"
|
||||||
|
- "'Non_Existing_Job_Template' in result.msg"
|
||||||
|
|
||||||
- name: Create a Job Template for testing prompt on launch
|
- name: Create a Job Template for testing prompt on launch
|
||||||
tower_job_template:
|
tower_job_template:
|
||||||
|
|||||||
@@ -12,13 +12,16 @@
|
|||||||
- name: Check module fails with correct msg
|
- name: Check module fails with correct msg
|
||||||
tower_label:
|
tower_label:
|
||||||
name: "Test Label"
|
name: "Test Label"
|
||||||
organization: "Non existing org"
|
organization: "Non_existing_org"
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "'Non existing org was not found on the Tower server' in result.msg"
|
- "result is failed"
|
||||||
|
- "result is not changed"
|
||||||
|
- "'Non_existing_org' in result.msg"
|
||||||
|
- "result.total_results == 0"
|
||||||
|
|
||||||
# TODO: Deleting labels doesn't seem to work currently
|
# TODO: Deleting labels doesn't seem to work currently
|
||||||
|
|||||||
@@ -93,7 +93,7 @@
|
|||||||
- name: Check module fails with correct msg when given non-existing org as param
|
- name: Check module fails with correct msg when given non-existing org as param
|
||||||
tower_project:
|
tower_project:
|
||||||
name: "{{ project_name2 }}"
|
name: "{{ project_name2 }}"
|
||||||
organization: Non Existing Org
|
organization: Non_Existing_Org
|
||||||
scm_type: git
|
scm_type: git
|
||||||
scm_url: https://github.com/ansible/test-playbooks
|
scm_url: https://github.com/ansible/test-playbooks
|
||||||
scm_credential: "{{ cred_name }}"
|
scm_credential: "{{ cred_name }}"
|
||||||
@@ -102,8 +102,10 @@
|
|||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result.msg == 'The organizations Non Existing Org was not found on the Tower server' or
|
- "result is failed"
|
||||||
result.msg == 'Failed to update project, organization not found: Non Existing Org'"
|
- "result is not changed"
|
||||||
|
- "'Non_Existing_Org' in result.msg"
|
||||||
|
- "result.total_results == 0"
|
||||||
|
|
||||||
- name: Check module fails with correct msg when given non-existing credential as param
|
- name: Check module fails with correct msg when given non-existing credential as param
|
||||||
tower_project:
|
tower_project:
|
||||||
@@ -111,14 +113,16 @@
|
|||||||
organization: "{{ org_name }}"
|
organization: "{{ org_name }}"
|
||||||
scm_type: git
|
scm_type: git
|
||||||
scm_url: https://github.com/ansible/test-playbooks
|
scm_url: https://github.com/ansible/test-playbooks
|
||||||
scm_credential: Non Existing Credential
|
scm_credential: Non_Existing_Credential
|
||||||
register: result
|
register: result
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result.msg =='The credentials Non Existing Credential was not found on the Tower server' or
|
- "result is failed"
|
||||||
result.msg =='Failed to update project, credential not found: Non Existing Credential'"
|
- "result is not changed"
|
||||||
|
- "'Non_Existing_Credential' in result.msg"
|
||||||
|
- "result.total_results == 0"
|
||||||
|
|
||||||
- name: Create a git project without credentials without waiting
|
- name: Create a git project without credentials without waiting
|
||||||
tower_project:
|
tower_project:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
- name: Attempt to add a Tower team to a non-existant Organization
|
- name: Attempt to add a Tower team to a non-existant Organization
|
||||||
tower_team:
|
tower_team:
|
||||||
name: Test Team
|
name: Test Team
|
||||||
organization: Missing Organization
|
organization: Missing_Organization
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
@@ -14,9 +14,10 @@
|
|||||||
- name: Assert a meaningful error was provided for the failed Tower team creation
|
- name: Assert a meaningful error was provided for the failed Tower team creation
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is failed
|
- "result is failed"
|
||||||
- "result.msg =='Failed to update team, organization not found: The requested object could not be found.' or
|
- "result is not changed"
|
||||||
result.msg =='The organizations Missing Organization was not found on the Tower server'"
|
- "'Missing_Organization' in result.msg"
|
||||||
|
- "result.total_results == 0"
|
||||||
|
|
||||||
- name: Create a Tower team
|
- name: Create a Tower team
|
||||||
tower_team:
|
tower_team:
|
||||||
@@ -42,12 +43,15 @@
|
|||||||
- name: Check module fails with correct msg
|
- name: Check module fails with correct msg
|
||||||
tower_team:
|
tower_team:
|
||||||
name: "{{ team_name }}"
|
name: "{{ team_name }}"
|
||||||
organization: Non Existing Org
|
organization: Non_Existing_Org
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- assert:
|
- name: Lookup of the related organization should cause a failure
|
||||||
|
assert:
|
||||||
that:
|
that:
|
||||||
- "result.msg =='Failed to update team, organization not found: The requested object could not be found.' or
|
- "result is failed"
|
||||||
result.msg =='The organizations Non Existing Org was not found on the Tower server'"
|
- "result is not changed"
|
||||||
|
- "'Non_Existing_Org' in result.msg"
|
||||||
|
- "result.total_results == 0"
|
||||||
|
|||||||
@@ -207,13 +207,16 @@
|
|||||||
- name: Check module fails with correct msg
|
- name: Check module fails with correct msg
|
||||||
tower_workflow_job_template:
|
tower_workflow_job_template:
|
||||||
name: "{{ wfjt_name }}"
|
name: "{{ wfjt_name }}"
|
||||||
organization: Non Existing Organization
|
organization: Non_Existing_Organization
|
||||||
register: result
|
register: result
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "'The organizations Non Existing Organization was not found' in result.msg"
|
- "result is failed"
|
||||||
|
- "result is not changed"
|
||||||
|
- "'Non_Existing_Organization' in result.msg"
|
||||||
|
- "result.total_results == 0"
|
||||||
|
|
||||||
- name: Delete the Job Template
|
- name: Delete the Job Template
|
||||||
tower_job_template:
|
tower_job_template:
|
||||||
|
|||||||
Reference in New Issue
Block a user