Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[1LP][RFR] Add support for cancel and nav_away to Host.update() and test_infrastructure_hosts_crud #10090

Merged
merged 26 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a815c4b
Create draft of rewrite of test_infrastructure_hosts_crud to edit onl…
prichard77 Dec 11, 2019
e56209a
Fix flake8 issues
prichard77 Dec 12, 2019
c095a0d
Reorder imports
prichard77 Dec 12, 2019
21d47e8
Removing outdated BZ lable
prichard77 Dec 12, 2019
cc08ea5
Add from_details kwarg to host.update
prichard77 Apr 23, 2020
402c630
Update host.update nav to support edit from hosts view
prichard77 Apr 23, 2020
8aa24cf
Update Host.update to support edit from hosts view
prichard77 May 1, 2020
8876350
Put view.is_displayed back into Host.update()
prichard77 May 1, 2020
c959976
Add support for cancel and nav_away to Host.update() and test_infrast…
prichard77 May 4, 2020
52545d0
Reorder import
prichard77 May 4, 2020
dbfcddc
Move pytest.fail up into test and add support for nav_away_changes
prichard77 May 5, 2020
66b36c4
Fix missing quote in parameter list
prichard77 May 5, 2020
9ffa5fe
Add explicit kwarg to host.delete and update format of random string
prichard77 May 5, 2020
b820454
Remove delete from update doc block
prichard77 May 5, 2020
024b151
Updated Host.update() and test_infrastructure_hosts_crud to use kwarg…
prichard77 May 7, 2020
287629b
Update nav_away and cancel kwargs in call to Hosts.update()
prichard77 May 7, 2020
f9fe748
Added BZ to exception log msg and added details on crud_actions to do…
prichard77 May 12, 2020
463973a
Remove newline in docblock for test_infrastructure_hosts_compare
prichard77 May 13, 2020
65d4c46
Add comments to and rearrange structure of test_infrastructure_hosts_…
prichard77 May 13, 2020
0f4ae4d
Add more comments and update docblock for clarity
prichard77 May 13, 2020
401ee6a
Update kwargs and associated logic to make from_hosts the one off exc…
prichard77 May 13, 2020
5ecc395
Remove nav_away and changes kwargs from Host.update()
prichard77 May 14, 2020
00ca912
Rewrite test_infrastructure_hosts_crud to not use parameterization of…
prichard77 May 14, 2020
155afde
Set from_details default to True in Host.update() and set it to True …
prichard77 May 14, 2020
16f7747
Update from_details logic and remove cancel kwarg assignements to the…
prichard77 May 15, 2020
de75db5
Combine multi lines into one where applicable
prichard77 May 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cfme/common/host_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class HostEditView(HostFormView):
@property
def is_displayed(self):
return (
self.logged_in_as_current_user and self.navigation.currently_selected == [
self.in_compute_infrastructure_hosts and self.navigation.currently_selected == [
'Compute', 'Infrastructure', 'Hosts'] and self.title.text == 'Info/Settings')


Expand Down
10 changes: 7 additions & 3 deletions cfme/infrastructure/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ def __init__(self, **kwargs):
super(Host.Credential, self).__init__(**kwargs)
self.ipmi = kwargs.get('ipmi')

def update(self, updates, validate_credentials=False, from_details=True):
def update(self, updates, validate_credentials=False, from_details=True, cancel=False):
"""Updates a host in the UI. Better to use utils.update.update context manager than call
this directly.

Args:
updates (dict): fields that are changing.
updates (dict): fields that are changing.
validate_credentials (bool): if True, validate host credentials
from_details (bool): if True, select 'Edit Selected items' from details view
else, select 'Edit Selected items' from hosts view
cancel (bool): click cancel button to cancel the edit if True
"""
if from_details:
view = navigate_to(self, "Edit")
Expand Down Expand Up @@ -137,7 +141,7 @@ def update(self, updates, validate_credentials=False, from_details=True):
view.endpoints.ipmi.validate_button.click()
view.flash.assert_no_error()
changed = any([changed, credentials_changed, ipmi_credentials_changed])
if changed:
if changed and not cancel:
view.save_button.click()
logger.debug("Trying to save update for host with id: %s", str(self.get_db_id))
view = self.create_view(HostDetailsView)
Expand Down
94 changes: 81 additions & 13 deletions cfme/tests/infrastructure/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import fauxfactory
import pytest
from wait_for import TimedOutError
from widgetastic.exceptions import UnexpectedAlertPresentException

from cfme import test_requirements
from cfme.base.credential import Credential
from cfme.common.host_views import HostsEditView
from cfme.common.host_views import HostsView
from cfme.common.provider_views import InfraProviderDetailsView
from cfme.common.provider_views import ProviderNodesView
from cfme.fixtures.provider import setup_or_skip
Expand Down Expand Up @@ -86,7 +88,6 @@ def navigate_and_select_quads(provider):

Returns:
view: the provider nodes view, quadicons already selected"""
# TODO: prichard navigate instead of creating views and consider creaing EditableMixin
hosts_view = navigate_to(provider, 'ProviderNodes')
assert hosts_view.is_displayed
[h.ensure_checked() for h in hosts_view.entities.get_all()]
Expand Down Expand Up @@ -462,6 +463,8 @@ def test_infrastructure_hosts_compare(appliance, setup_provider_min_hosts, provi
casecomponent: Infra
caseimportance: high
initialEstimate: 1/6h
Bugzilla:
1746214
"""

h_coll = locals()[hosts_collection].collections.hosts
Expand All @@ -487,6 +490,7 @@ def test_infrastructure_hosts_navigation_after_download_from_compare(
initialEstimate: 1/3h
Bugzilla:
1747545

"""
h_coll = locals()[hosts_collection].collections.hosts
hosts_view = h_coll.compare_entities(provider, entities_list=h_coll.all()[:num_hosts])
Expand Down Expand Up @@ -526,26 +530,90 @@ def test_add_ipmi_refresh(appliance, setup_provider):


@test_requirements.infra_hosts
@pytest.mark.parametrize("crud_action", ['edit_from_hosts', 'edit_from_details', 'remove'])
def test_infrastructure_hosts_crud(appliance, setup_provider, crud_action):
@pytest.mark.meta(automates=[1634794])
def test_infrastructure_hosts_crud(appliance, setup_provider):
"""
mshriver marked this conversation as resolved.
Show resolved Hide resolved
Polarion:
assignee: prichard
casecomponent: Infra
caseimportance: low
initialEstimate: 1/6h
Bugzilla:
1634794
"""
host = appliance.collections.hosts.all()[0]
mshriver marked this conversation as resolved.
Show resolved Hide resolved
if crud_action != 'remove':
stamp = fauxfactory.gen_alphanumeric()
new_custom_id = f'Edit host data. {stamp}'

with update(host, from_details=(crud_action == 'edit_from_details')):
host.custom_ident = new_custom_id
# Case1 - edit from Hosts
new_custom_id = f'Edit host data. {fauxfactory.gen_alphanumeric()}'
with update(host, from_details=False):
host.custom_ident = new_custom_id
# verify edit
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
"Custom Identifier") == new_custom_id

# Case2 - edit from Details
new_custom_id = f'Edit host data. {fauxfactory.gen_alphanumeric()}'
with update(host, from_details=True):
host.custom_ident = new_custom_id
# verify edit
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
"Custom Identifier") == new_custom_id

# Case3 - canceling the edit
# get the existing value
try:
existing_custom_id = navigate_to(host, 'Details').entities.summary(
"Properties").get_text_of("Custom Identifier")
except NameError:
existing_custom_id = None
# start edit and cancel
new_custom_id = f'Edit host data. {fauxfactory.gen_alphanumeric()}'
with update(host, from_details=True, cancel=True):
host.custom_ident = new_custom_id
# verify edit
# No changes are expected. Comparing to existing value captured above.
try:
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
"Custom Identifier") == existing_custom_id
except NameError:
if existing_custom_id:
raise

assert host.custom_ident == new_custom_id
# Case4 - navigate away from edit view before making any updates in UI.
view = navigate_to(host, "Edit")
# navigate away before any changes have been made in the edit view
try:
view.navigation.select('Compute', 'Infrastructure', 'Hosts', handle_alert=False)
except UnexpectedAlertPresentException as e:
if "Abandon changes" in e.msg:
pytest.fail("Abandon changes alert displayed, but no changes made. BZ1634794")
else:
raise
view = host.create_view(HostsView)
assert view.is_displayed
# No changes are expected. Comparing to existing value captured above.
try:
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
"Custom Identifier") == new_custom_id
else:
host.delete()
host.delete(cancel=False)
"Custom Identifier") == existing_custom_id
except NameError:
if existing_custom_id:
raise

# Case5 -Nav away from edit view after making updates in UI(not saved).
new_custom_id = f'Edit host data. {fauxfactory.gen_alphanumeric()}'
view = navigate_to(host, "Edit")
view.fill({"custom_ident": new_custom_id})
# navigate away here after changes have been made in the edit view(not saved)
view = navigate_to(host.parent, "All")
assert view.is_displayed
# No changes are expected. Comparing to existing value captured above.
try:
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
"Custom Identifier") == existing_custom_id
except NameError:
if existing_custom_id:
raise

# Case6 - lastly do the delete. First try is canceled.
host.delete(cancel=True)
host.delete