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

Commit c63b987

Browse files
authored
[1LP][RFR] Add support for create and nav_away to Host.update() and test_infrastructure_hosts_crud (#10090)
* Create draft of rewrite of test_infrastructure_hosts_crud to edit only single hosts * Fix flake8 issues * Reorder imports * Removing outdated BZ lable * Add from_details kwarg to host.update * Update host.update nav to support edit from hosts view * Update Host.update to support edit from hosts view * Put view.is_displayed back into Host.update() * Add support for cancel and nav_away to Host.update() and test_infrastructure_hosts_crud * Reorder import * Move pytest.fail up into test and add support for nav_away_changes * Fix missing quote in parameter list * Add explicit kwarg to host.delete and update format of random string * Remove delete from update doc block * Updated Host.update() and test_infrastructure_hosts_crud to use kwargs instead of action strings * Update nav_away and cancel kwargs in call to Hosts.update() * Added BZ to exception log msg and added details on crud_actions to docblock * Remove newline in docblock for test_infrastructure_hosts_compare * Add comments to and rearrange structure of test_infrastructure_hosts_crud for clarity and easier understanding * Add more comments and update docblock for clarity * Update kwargs and associated logic to make from_hosts the one off exception and default to from_details * Remove nav_away and changes kwargs from Host.update() * Rewrite test_infrastructure_hosts_crud to not use parameterization of actions * Set from_details default to True in Host.update() and set it to True in cancel calls in test_infrastructure_hosts_crud * Update from_details logic and remove cancel kwarg assignements to the default value * Combine multi lines into one where applicable
1 parent c1c8e30 commit c63b987

File tree

3 files changed

+89
-17
lines changed

3 files changed

+89
-17
lines changed

cfme/common/host_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class HostEditView(HostFormView):
307307
@property
308308
def is_displayed(self):
309309
return (
310-
self.logged_in_as_current_user and self.navigation.currently_selected == [
310+
self.in_compute_infrastructure_hosts and self.navigation.currently_selected == [
311311
'Compute', 'Infrastructure', 'Hosts'] and self.title.text == 'Info/Settings')
312312

313313

cfme/infrastructure/host.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,16 @@ def __init__(self, **kwargs):
9494
super(Host.Credential, self).__init__(**kwargs)
9595
self.ipmi = kwargs.get('ipmi')
9696

97-
def update(self, updates, validate_credentials=False, from_details=True):
97+
def update(self, updates, validate_credentials=False, from_details=True, cancel=False):
9898
"""Updates a host in the UI. Better to use utils.update.update context manager than call
9999
this directly.
100100
101101
Args:
102-
updates (dict): fields that are changing.
102+
updates (dict): fields that are changing.
103+
validate_credentials (bool): if True, validate host credentials
104+
from_details (bool): if True, select 'Edit Selected items' from details view
105+
else, select 'Edit Selected items' from hosts view
106+
cancel (bool): click cancel button to cancel the edit if True
103107
"""
104108
if from_details:
105109
view = navigate_to(self, "Edit")
@@ -137,7 +141,7 @@ def update(self, updates, validate_credentials=False, from_details=True):
137141
view.endpoints.ipmi.validate_button.click()
138142
view.flash.assert_no_error()
139143
changed = any([changed, credentials_changed, ipmi_credentials_changed])
140-
if changed:
144+
if changed and not cancel:
141145
view.save_button.click()
142146
logger.debug("Trying to save update for host with id: %s", str(self.get_db_id))
143147
view = self.create_view(HostDetailsView)

cfme/tests/infrastructure/test_host.py

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import fauxfactory
55
import pytest
66
from wait_for import TimedOutError
7+
from widgetastic.exceptions import UnexpectedAlertPresentException
78

89
from cfme import test_requirements
910
from cfme.base.credential import Credential
1011
from cfme.common.host_views import HostsEditView
12+
from cfme.common.host_views import HostsView
1113
from cfme.common.provider_views import InfraProviderDetailsView
1214
from cfme.common.provider_views import ProviderNodesView
1315
from cfme.fixtures.provider import setup_or_skip
@@ -86,7 +88,6 @@ def navigate_and_select_quads(provider):
8688
8789
Returns:
8890
view: the provider nodes view, quadicons already selected"""
89-
# TODO: prichard navigate instead of creating views and consider creaing EditableMixin
9091
hosts_view = navigate_to(provider, 'ProviderNodes')
9192
assert hosts_view.is_displayed
9293
[h.ensure_checked() for h in hosts_view.entities.get_all()]
@@ -462,6 +463,8 @@ def test_infrastructure_hosts_compare(appliance, setup_provider_min_hosts, provi
462463
casecomponent: Infra
463464
caseimportance: high
464465
initialEstimate: 1/6h
466+
Bugzilla:
467+
1746214
465468
"""
466469

467470
h_coll = locals()[hosts_collection].collections.hosts
@@ -487,6 +490,7 @@ def test_infrastructure_hosts_navigation_after_download_from_compare(
487490
initialEstimate: 1/3h
488491
Bugzilla:
489492
1747545
493+
490494
"""
491495
h_coll = locals()[hosts_collection].collections.hosts
492496
hosts_view = h_coll.compare_entities(entities_list=h_coll.all()[:num_hosts])
@@ -526,26 +530,90 @@ def test_add_ipmi_refresh(appliance, setup_provider):
526530

527531

528532
@test_requirements.infra_hosts
529-
@pytest.mark.parametrize("crud_action", ['edit_from_hosts', 'edit_from_details', 'remove'])
530-
def test_infrastructure_hosts_crud(appliance, setup_provider, crud_action):
533+
@pytest.mark.meta(automates=[1634794])
534+
def test_infrastructure_hosts_crud(appliance, setup_provider):
531535
"""
532536
Polarion:
533537
assignee: prichard
534538
casecomponent: Infra
535539
caseimportance: low
536540
initialEstimate: 1/6h
541+
Bugzilla:
542+
1634794
537543
"""
538544
host = appliance.collections.hosts.all()[0]
539-
if crud_action != 'remove':
540-
stamp = fauxfactory.gen_alphanumeric()
541-
new_custom_id = f'Edit host data. {stamp}'
542545

543-
with update(host, from_details=(crud_action == 'edit_from_details')):
544-
host.custom_ident = new_custom_id
546+
# Case1 - edit from Hosts
547+
new_custom_id = f'Edit host data. {fauxfactory.gen_alphanumeric()}'
548+
with update(host, from_details=False):
549+
host.custom_ident = new_custom_id
550+
# verify edit
551+
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
552+
"Custom Identifier") == new_custom_id
553+
554+
# Case2 - edit from Details
555+
new_custom_id = f'Edit host data. {fauxfactory.gen_alphanumeric()}'
556+
with update(host, from_details=True):
557+
host.custom_ident = new_custom_id
558+
# verify edit
559+
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
560+
"Custom Identifier") == new_custom_id
561+
562+
# Case3 - canceling the edit
563+
# get the existing value
564+
try:
565+
existing_custom_id = navigate_to(host, 'Details').entities.summary(
566+
"Properties").get_text_of("Custom Identifier")
567+
except NameError:
568+
existing_custom_id = None
569+
# start edit and cancel
570+
new_custom_id = f'Edit host data. {fauxfactory.gen_alphanumeric()}'
571+
with update(host, from_details=True, cancel=True):
572+
host.custom_ident = new_custom_id
573+
# verify edit
574+
# No changes are expected. Comparing to existing value captured above.
575+
try:
576+
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
577+
"Custom Identifier") == existing_custom_id
578+
except NameError:
579+
if existing_custom_id:
580+
raise
545581

546-
assert host.custom_ident == new_custom_id
582+
# Case4 - navigate away from edit view before making any updates in UI.
583+
view = navigate_to(host, "Edit")
584+
# navigate away before any changes have been made in the edit view
585+
try:
586+
view.navigation.select('Compute', 'Infrastructure', 'Hosts', handle_alert=False)
587+
except UnexpectedAlertPresentException as e:
588+
if "Abandon changes" in e.msg:
589+
pytest.fail("Abandon changes alert displayed, but no changes made. BZ1634794")
590+
else:
591+
raise
592+
view = host.create_view(HostsView)
593+
assert view.is_displayed
594+
# No changes are expected. Comparing to existing value captured above.
595+
try:
547596
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
548-
"Custom Identifier") == new_custom_id
549-
else:
550-
host.delete()
551-
host.delete(cancel=False)
597+
"Custom Identifier") == existing_custom_id
598+
except NameError:
599+
if existing_custom_id:
600+
raise
601+
602+
# Case5 -Nav away from edit view after making updates in UI(not saved).
603+
new_custom_id = f'Edit host data. {fauxfactory.gen_alphanumeric()}'
604+
view = navigate_to(host, "Edit")
605+
view.fill({"custom_ident": new_custom_id})
606+
# navigate away here after changes have been made in the edit view(not saved)
607+
view = navigate_to(host.parent, "All")
608+
assert view.is_displayed
609+
# No changes are expected. Comparing to existing value captured above.
610+
try:
611+
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
612+
"Custom Identifier") == existing_custom_id
613+
except NameError:
614+
if existing_custom_id:
615+
raise
616+
617+
# Case6 - lastly do the delete. First try is canceled.
618+
host.delete(cancel=True)
619+
host.delete

0 commit comments

Comments
 (0)