-
Notifications
You must be signed in to change notification settings - Fork 165
[WIP] Updating CRUD operations test for automate method #8876
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ | |
from cfme.utils.appliance.implementations.ui import CFMENavigateStep | ||
from cfme.utils.appliance.implementations.ui import navigate_to | ||
from cfme.utils.appliance.implementations.ui import navigator | ||
from cfme.utils.blockers import BZ | ||
from cfme.utils.timeutil import parsetime | ||
from cfme.utils.wait import wait_for | ||
from widgetastic_manageiq import EntryPoint | ||
|
@@ -234,20 +233,23 @@ def read(self): | |
|
||
|
||
class MethodAddView(AutomateExplorerView): | ||
fill_strategy = WaitFillViewStrategy() | ||
fill_strategy = WaitFillViewStrategy("20s") | ||
title = Text('#explorer_title_text') | ||
|
||
location = BootstrapSelect('cls_method_location', can_hide_on_select=True) | ||
|
||
# Inline | ||
inline_name = Input(name='cls_method_name') | ||
inline_display_name = Input(name='cls_method_display_name') | ||
script = ScriptBox() | ||
data = Input(name='cls_method_data') | ||
validate_button = Button('Validate') | ||
inputs = View.nested(Inputs) | ||
|
||
playbook_name = Input(name='name') | ||
playbook_display_name = Input(name='display_name') | ||
# Playbook, Ansible Tower Workflow Template, Ansible Tower Job Template | ||
method_name = Input(name='name') | ||
method_display_name = Input(name='display_name') | ||
|
||
repository = PlaybookBootstrapSelect('provisioning_repository_id') | ||
playbook = PlaybookBootstrapSelect('provisioning_playbook_id') | ||
machine_credential = PlaybookBootstrapSelect('provisioning_machine_credential_id') | ||
|
@@ -263,6 +265,8 @@ class MethodAddView(AutomateExplorerView): | |
embedded_method = EntryPoint(locator='//*[@id="automate-inline-method-select"]//button', | ||
tree_id="treeview-entrypoint_selection") | ||
|
||
ansible_max_ttl = Input(name='provisioning_execution_ttl') | ||
|
||
add_button = Button('Add') | ||
cancel_button = Button('Cancel') | ||
|
||
|
@@ -278,6 +282,7 @@ def is_displayed(self): | |
|
||
|
||
class MethodEditView(AutomateExplorerView): | ||
fill_strategy = WaitFillViewStrategy("20s") | ||
title = Text('#explorer_title_text') | ||
|
||
# inline | ||
|
@@ -288,9 +293,10 @@ class MethodEditView(AutomateExplorerView): | |
validate_button = Button('Validate') | ||
inputs = View.nested(Inputs) | ||
|
||
# playbook | ||
playbook_name = Input(name='name') | ||
playbook_display_name = Input(name='display_name') | ||
# Playbook, Ansible Tower Workflow Template, Ansible Tower Job Template | ||
method_name = Input(name='name') | ||
method_display_name = Input(name='display_name') | ||
|
||
repository = PlaybookBootstrapSelect('provisioning_repository_id') | ||
playbook = PlaybookBootstrapSelect('provisioning_playbook_id') | ||
machine_credential = PlaybookBootstrapSelect('provisioning_machine_credential_id') | ||
|
@@ -306,35 +312,44 @@ class MethodEditView(AutomateExplorerView): | |
embedded_method = EntryPoint(locator='//*[@id="automate-inline-method-select"]//button', | ||
tree_id="treeview-entrypoint_selection") | ||
|
||
ansible_max_ttl = Input(name='provisioning_execution_ttl') | ||
|
||
save_button = Button('Save') | ||
reset_button = Button('Reset') | ||
cancel_button = Button('Cancel') | ||
|
||
def before_fill(self, values): | ||
location = self.context['object'].location.lower() | ||
if 'display_name' in values and location in ['inline', 'playbook']: | ||
values['{}_display_name'.format(location)] = values['display_name'] | ||
if 'display_name' in values: | ||
if location == 'inline': | ||
values[f'{location}_display_name'] = values['display_name'] | ||
else: | ||
values['method_display_name'] = values['display_name'] | ||
del values['display_name'] | ||
elif 'name' in values and location in ['inline', 'playbook']: | ||
values['{}_name'.format(location)] = values['name'] | ||
|
||
elif 'name' in values: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here about |
||
if location == 'inline': | ||
values[f'{location.replace(" ", "_")}_name'] = values['name'] | ||
else: | ||
values['method_name'] = values['name'] | ||
del values['name'] | ||
|
||
@property | ||
def is_displayed(self): | ||
return ( | ||
self.in_explorer | ||
and self.datastore.is_opened | ||
and (f'Editing Automate Method "{self.context["object"].name}"' in self.title.text) | ||
self.in_explorer and | ||
self.datastore.is_opened and | ||
'Editing Automate Method "{}"'.format(self.context['object'].name) in self.title.text | ||
and check_tree_path( | ||
self.datastore.tree.currently_selected, | ||
self.context["object"].tree_path, | ||
partial=True, | ||
) | ||
self.context['object'].tree_path, partial=True) | ||
) | ||
|
||
|
||
class Method(BaseEntity, Copiable): | ||
|
||
LOCATIONS = ['Ansible Tower Job Template', 'Ansible Tower Workflow Template'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts on making it global so that you can import it in test file too ? |
||
|
||
def __init__(self, collection, name=None, display_name=None, location='inline', script=None, | ||
data=None, repository=None, playbook=None, machine_credential=None, hosts=None, | ||
max_ttl=None, logging_output=None, escalate_privilege=None, verbosity=None, | ||
|
@@ -401,11 +416,18 @@ def domain(self): | |
def tree_path(self): | ||
icon_name_map = {'inline': 'fa-ruby', 'playbook': 'vendor-ansible'} | ||
if self.display_name: | ||
return self.parent_obj.tree_path + [ | ||
(icon_name_map[self.location.lower()], '{} ({})'.format(self.display_name, | ||
self.name))] | ||
if self.location in self.LOCATIONS: | ||
return self.parent_obj.tree_path + [f'{self.display_name} ({self.name})'] | ||
else: | ||
return self.parent_obj.tree_path + [ | ||
(icon_name_map[self.location.lower()], f'{self.display_name} ({self.name})')] | ||
else: | ||
return self.parent_obj.tree_path + [(icon_name_map[self.location.lower()], self.name)] | ||
if self.location in self.LOCATIONS: | ||
return self.parent_obj.tree_path + [self.name] | ||
else: | ||
return self.parent_obj.tree_path + [( | ||
icon_name_map[self.location.lower()], self.name | ||
)] | ||
|
||
@property | ||
def tree_path_name_only(self): | ||
|
@@ -452,6 +474,7 @@ def create( | |
playbook_input_parameters=None, inputs=None, embedded_method=None): | ||
|
||
add_page = navigate_to(self, 'Add') | ||
add_page.wait_displayed("25s") | ||
|
||
if self.browser.product_version > '5.11' and location.islower(): | ||
location = location.capitalize() | ||
|
@@ -468,8 +491,8 @@ def create( | |
}) | ||
if location.lower() == 'playbook': | ||
add_page.fill({ | ||
'playbook_name': name, | ||
'playbook_display_name': display_name, | ||
'method_name': name, | ||
'method_display_name': display_name, | ||
'repository': repository | ||
}) | ||
wait_for(lambda: add_page.playbook.is_displayed, delay=0.5, num_sec=2) | ||
|
@@ -484,6 +507,15 @@ def create( | |
'playbook_input_parameters': playbook_input_parameters | ||
}) | ||
validate = False | ||
|
||
if location in ['Ansible Tower Workflow Template', 'Ansible Tower Job Template']: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if location in self.LOCATIONS: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup that was a typo :) |
||
add_page.fill({ | ||
'method_name': name, | ||
'method_display_name': display_name, | ||
'ansible_max_ttl': max_ttl, | ||
}) | ||
validate = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you setting validate=false here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sshveta For method types such as |
||
|
||
if validate: | ||
add_page.validate_button.click() | ||
add_page.wait_displayed() | ||
|
@@ -499,12 +531,6 @@ def create( | |
add_page.add_button.click() | ||
add_page.flash.assert_no_error() | ||
|
||
# TODO(BZ-1704439): Remove the work-around once this BZ got fixed | ||
if BZ(1704439).blocks: | ||
view = self.create_view(ClassDetailsView) | ||
view.flash.assert_message('Automate Method "{}" was added'.format(name)) | ||
self.browser.refresh() | ||
|
||
return self.instantiate( | ||
name=name, | ||
display_name=display_name, | ||
|
@@ -558,10 +584,6 @@ def delete(self, *methods): | |
all_page.flash.assert_message( | ||
'Automate Method "{}": Delete successful'.format(method.name)) | ||
|
||
# TODO(BZ-1704439): Remove the work-around once this BZ got fixed | ||
if BZ(1704439).blocks: | ||
self.browser.refresh() | ||
|
||
|
||
@navigator.register(MethodCollection) | ||
class Add(CFMENavigateStep): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,22 @@ def original_class(domain): | |
|
||
|
||
@pytest.mark.sauce | ||
def test_method_crud(klass): | ||
@pytest.mark.meta(automates=[1704439, 1591797]) | ||
@pytest.mark.parametrize( | ||
"method_type", ["inline", "Ansible Tower Job Template", "Ansible Tower Workflow Template"], | ||
ids=["inline", "job", "workflow"] | ||
) | ||
@pytest.mark.uncollectif( | ||
lambda method_type, appliance: method_type | ||
in ("Ansible Tower Job Template", "Ansible Tower Workflow Template") | ||
and appliance.version < 5.11, reason="These type of methods introduced in 5.11" | ||
) | ||
def test_method_crud(method_type, klass): | ||
""" | ||
Bugzilla: | ||
1704439 | ||
1591797 | ||
|
||
Polarion: | ||
assignee: ghubale | ||
casecomponent: Automate | ||
|
@@ -42,21 +56,30 @@ def test_method_crud(klass): | |
tags: automate | ||
""" | ||
# TODO([email protected]): Update this test case for other types of automate methods like | ||
# builtin, expression, uri, playbook, Ansible Tower Job Template and Ansible Tower Workflow | ||
# Template | ||
method = klass.methods.create( | ||
name=fauxfactory.gen_alphanumeric(), | ||
display_name=fauxfactory.gen_alphanumeric(), | ||
location='inline', | ||
script='$evm.log(:info, ":P")', | ||
) | ||
# builtin, expression, uri, playbook | ||
if method_type in ['Ansible Tower Job Template', 'Ansible Tower Workflow Template']: | ||
method = klass.methods.create( | ||
name=fauxfactory.gen_alphanumeric(), | ||
display_name=fauxfactory.gen_alphanumeric(), | ||
location=method_type, | ||
max_ttl='2' | ||
) | ||
elif method_type == 'inline': | ||
method = klass.methods.create( | ||
name=fauxfactory.gen_alphanumeric(), | ||
display_name=fauxfactory.gen_alphanumeric(), | ||
location=method_type, | ||
script='$evm.log(:info, ":P")', | ||
) | ||
view = method.create_view(ClassDetailsView) | ||
view.flash.assert_message(f'Automate Method "{method.name}" was added') | ||
if method_type in ['Ansible Tower Job Template', 'Ansible Tower Workflow Template']: | ||
view.flash.assert_message(f'Automate Method "{method.name}" was saved') | ||
else: | ||
view.flash.assert_message(f'Automate Method "{method.name}" was added') | ||
assert method.exists | ||
origname = method.name | ||
with update(method): | ||
method.name = fauxfactory.gen_alphanumeric(8) | ||
method.script = "bar" | ||
assert method.exists | ||
with update(method): | ||
method.name = origname | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ganeshhubale What about the
playbook
case? Won't this fail iflocation=='playbook'
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @john-dupuy
Actually I am not getting why this question. So I tested test_automate_ansible_playbook_method_type_crud < this test case with these changes locally. And it works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ganeshhubale I have some test that uses this method that has failed in this section of code before. I remember I had to add in the
location in ['inline', 'playbook']
line to get it to work. Can you please try runningtest_alert_run_ansible_playbook
?My point is that you've removed the code that handles the case where
location == 'playbook'
. I.e. to keep the original code intact, L324 should beDoes that make sense? Or am I missing something here?