mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -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:
parent
a73323f3d6
commit
2e1f5cebb7
@ -123,12 +123,12 @@ class TowerAPIModule(TowerModule):
|
||||
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))
|
||||
|
||||
new_data['or__{0}'.format(name_field)] = name_or_id
|
||||
try:
|
||||
new_data['or__id'] = int(name_or_id)
|
||||
new_data['or__{0}'.format(name_field)] = name_or_id
|
||||
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
|
||||
pass
|
||||
new_data[name_field] = name_or_id
|
||||
new_kwargs['data'] = new_data
|
||||
|
||||
response = self.get_endpoint(endpoint, **new_kwargs)
|
||||
@ -160,11 +160,13 @@ class TowerAPIModule(TowerModule):
|
||||
|
||||
def fail_wanted_one(self, response, endpoint, query_params):
|
||||
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...']
|
||||
url = self.build_url(endpoint, query_params)
|
||||
display_endpoint = url.geturl()[len(self.host):] # truncate to not include the base URL
|
||||
self.fail_json(
|
||||
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,
|
||||
response=sample,
|
||||
|
||||
@ -126,6 +126,7 @@ def test_conflicting_name_and_id(run_module, admin_user):
|
||||
)
|
||||
assert team.organization.name == 'foo'
|
||||
|
||||
|
||||
def test_multiple_lookup(run_module, admin_user):
|
||||
org1 = Organization.objects.create(name='foo')
|
||||
org2 = Organization.objects.create(name='bar')
|
||||
@ -140,4 +141,3 @@ def test_multiple_lookup(run_module, admin_user):
|
||||
assert 'foo' in result['msg']
|
||||
assert 'returned 2 items, expected 1' in result['msg']
|
||||
assert 'query' in result
|
||||
|
||||
|
||||
@ -288,7 +288,7 @@
|
||||
- name: Create an invalid SSH credential (Organization not found)
|
||||
tower_credential:
|
||||
name: SSH Credential
|
||||
organization: Missing Organization
|
||||
organization: Missing_Organization
|
||||
state: present
|
||||
kind: ssh
|
||||
username: joe
|
||||
@ -298,7 +298,9 @@
|
||||
- assert:
|
||||
that:
|
||||
- "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
|
||||
tower_credential:
|
||||
@ -750,5 +752,7 @@
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
- "result.msg =='The organizations test-non-existing-org was not found on the Tower server'"
|
||||
- "result is failed"
|
||||
- "result is not changed"
|
||||
- "'test-non-existing-org' in result.msg"
|
||||
- "result.total_results == 0"
|
||||
|
||||
@ -51,8 +51,10 @@
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.msg =='Failed to update the group, inventory not found: The requested object could not be found.' or
|
||||
result.msg =='The inventories test-non-existing-inventory was not found on the Tower server'"
|
||||
- "result is failed"
|
||||
- "result is not changed"
|
||||
- "'test-non-existing-inventory' in result.msg"
|
||||
- "result.total_results == 0"
|
||||
|
||||
- name: add hosts
|
||||
tower_host:
|
||||
|
||||
@ -46,5 +46,6 @@
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.msg =='The inventories test-non-existing-inventory was not found on the Tower server' or
|
||||
result.msg =='Failed to update host, inventory not found: The requested object could not be found.'"
|
||||
- "result is failed"
|
||||
- "'test-non-existing-inventory' in result.msg"
|
||||
- "result.total_results == 0"
|
||||
|
||||
@ -119,9 +119,11 @@
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result is failed"
|
||||
- "result is not changed"
|
||||
- "result.msg =='Failed to update inventory, organization not found: The requested object could not be found.'
|
||||
or result.msg =='The organizations test-non-existing-org was not found on the Tower server'"
|
||||
- "'test-non-existing-org' in result.msg"
|
||||
- "result.total_results == 0"
|
||||
|
||||
always:
|
||||
- name: Delete Inventories
|
||||
tower_inventory:
|
||||
|
||||
@ -29,16 +29,16 @@
|
||||
|
||||
- name: Check module fails with correct msg
|
||||
tower_job_launch:
|
||||
job_template: "Non Existing Job Template"
|
||||
inventory: "Test Inventory"
|
||||
credential: "Test Credential"
|
||||
job_template: "Non_Existing_Job_Template"
|
||||
inventory: "Demo Inventory"
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.msg =='Unable to launch job, job_template/Non Existing Job Template was not found: The requested object could not be found.'
|
||||
or result.msg == 'The inventories Test Inventory was not found on the Tower server'"
|
||||
- "result is failed"
|
||||
- "result is not changed"
|
||||
- "'Non_Existing_Job_Template' in result.msg"
|
||||
|
||||
- name: Create a Job Template for testing prompt on launch
|
||||
tower_job_template:
|
||||
|
||||
@ -12,13 +12,16 @@
|
||||
- name: Check module fails with correct msg
|
||||
tower_label:
|
||||
name: "Test Label"
|
||||
organization: "Non existing org"
|
||||
organization: "Non_existing_org"
|
||||
state: present
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- assert:
|
||||
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
|
||||
|
||||
@ -93,7 +93,7 @@
|
||||
- name: Check module fails with correct msg when given non-existing org as param
|
||||
tower_project:
|
||||
name: "{{ project_name2 }}"
|
||||
organization: Non Existing Org
|
||||
organization: Non_Existing_Org
|
||||
scm_type: git
|
||||
scm_url: https://github.com/ansible/test-playbooks
|
||||
scm_credential: "{{ cred_name }}"
|
||||
@ -102,8 +102,10 @@
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.msg == 'The organizations Non Existing Org was not found on the Tower server' or
|
||||
result.msg == 'Failed to update project, organization not found: Non Existing Org'"
|
||||
- "result is failed"
|
||||
- "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
|
||||
tower_project:
|
||||
@ -111,14 +113,16 @@
|
||||
organization: "{{ org_name }}"
|
||||
scm_type: git
|
||||
scm_url: https://github.com/ansible/test-playbooks
|
||||
scm_credential: Non Existing Credential
|
||||
scm_credential: Non_Existing_Credential
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.msg =='The credentials Non Existing Credential was not found on the Tower server' or
|
||||
result.msg =='Failed to update project, credential not found: Non Existing Credential'"
|
||||
- "result is failed"
|
||||
- "result is not changed"
|
||||
- "'Non_Existing_Credential' in result.msg"
|
||||
- "result.total_results == 0"
|
||||
|
||||
- name: Create a git project without credentials without waiting
|
||||
tower_project:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
- name: Attempt to add a Tower team to a non-existant Organization
|
||||
tower_team:
|
||||
name: Test Team
|
||||
organization: Missing Organization
|
||||
organization: Missing_Organization
|
||||
state: present
|
||||
register: result
|
||||
ignore_errors: true
|
||||
@ -14,9 +14,10 @@
|
||||
- name: Assert a meaningful error was provided for the failed Tower team creation
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- "result.msg =='Failed to update team, organization not found: The requested object could not be found.' or
|
||||
result.msg =='The organizations Missing Organization was not found on the Tower server'"
|
||||
- "result is failed"
|
||||
- "result is not changed"
|
||||
- "'Missing_Organization' in result.msg"
|
||||
- "result.total_results == 0"
|
||||
|
||||
- name: Create a Tower team
|
||||
tower_team:
|
||||
@ -42,12 +43,15 @@
|
||||
- name: Check module fails with correct msg
|
||||
tower_team:
|
||||
name: "{{ team_name }}"
|
||||
organization: Non Existing Org
|
||||
organization: Non_Existing_Org
|
||||
state: present
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- assert:
|
||||
- name: Lookup of the related organization should cause a failure
|
||||
assert:
|
||||
that:
|
||||
- "result.msg =='Failed to update team, organization not found: The requested object could not be found.' or
|
||||
result.msg =='The organizations Non Existing Org was not found on the Tower server'"
|
||||
- "result is failed"
|
||||
- "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
|
||||
tower_workflow_job_template:
|
||||
name: "{{ wfjt_name }}"
|
||||
organization: Non Existing Organization
|
||||
organization: Non_Existing_Organization
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- assert:
|
||||
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
|
||||
tower_job_template:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user