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

Commit

Permalink
Merge pull request #8877 from mshriver/fix-alert-attr
Browse files Browse the repository at this point in the history
[1LP][RFR] Fix AttributeError in HandleModalsMixin.handle_alert
  • Loading branch information
jawatts authored May 28, 2019
2 parents a5cafdf + 5fa9f16 commit fe34306
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
5 changes: 2 additions & 3 deletions cfme/configure/access_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ class Role(Updateable, Pretty, BaseEntity):

pretty_attrs = ['name', 'product_features']

name = attr.ib(default=None)
name = attr.ib()
vm_restriction = attr.ib(default=None)
product_features = attr.ib(default=None)

Expand Down Expand Up @@ -1135,7 +1135,7 @@ def set_role_product_features(view, product_features):
class RoleCollection(BaseCollection):
ENTITY = Role

def create(self, name=None, vm_restriction=None, product_features=None, cancel=False):
def create(self, name, vm_restriction=None, product_features=None, cancel=False):
""" Create role method
Args:
Expand All @@ -1151,7 +1151,6 @@ def create(self, name=None, vm_restriction=None, product_features=None, cancel=F
for currently selected role
"""
flash_blocked_msg = "Name has already been taken"

role = self.instantiate(
name=name, vm_restriction=vm_restriction, product_features=product_features
)
Expand Down
10 changes: 7 additions & 3 deletions cfme/fixtures/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ def category(appliance):
display_name=fauxfactory.gen_alphanumeric(length=32)
)
yield cg
appliance.server.login_admin()
cg.delete_if_exists()


@pytest.fixture(scope="session")
def tag(category):
def tag(category, appliance):
"""
Returns random created tag object
Object can be used in all test run session
Expand All @@ -35,6 +36,7 @@ def tag(category):
display_name=fauxfactory.gen_alphanumeric(length=32)
)
yield tag
appliance.server.login_admin()
tag.delete_if_exists()


Expand All @@ -47,6 +49,7 @@ def role(appliance):
name='role{}'.format(fauxfactory.gen_alphanumeric()),
vm_restriction='None')
yield role
appliance.server.login_admin()
role.delete_if_exists()


Expand All @@ -61,6 +64,7 @@ def group_with_tag(appliance, role, category, tag):
tag=([category.display_name, tag.display_name], True)
)
yield group
appliance.server.login_admin()
group.delete_if_exists()


Expand All @@ -78,6 +82,7 @@ def user_restricted(appliance, group_with_tag, new_credential):
cost_center='Workload',
value_assign='Database')
yield user
appliance.server.login_admin()
user.delete_if_exists()


Expand All @@ -86,9 +91,8 @@ def new_credential():
"""
Returns credentials object used for new user in test module
"""
# Todo remove .lower() for principal after 1486041 fix
return Credential(
principal='uid{}'.format(fauxfactory.gen_alphanumeric().lower()), secret='redhat')
principal='uid{}'.format(fauxfactory.gen_alphanumeric()), secret='redhat')


@pytest.fixture(scope='function')
Expand Down
26 changes: 14 additions & 12 deletions cfme/tests/configure/test_access_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,11 +760,13 @@ def test_rolename_required_error_validation(appliance):
# When trying to create a role with no name, the Add button is disabled.
# We are waiting for an Exception saying that there are no success
# or fail messages, because the Add button cannot be clicked.
with pytest.raises(Exception, match=r"Available messages: \[\]"):
appliance.collections.roles.create(
name=None,
vm_restriction='Only User Owned'
)
view = navigate_to(appliance.collections.roles, 'Add')
view.fill({'name_txt': '',
'vm_restriction_select': 'Only User Owned'})
assert view.add_button.disabled
view.fill({'name_txt': 'test-required-name'})
assert not view.add_button.disabled
view.cancel_button.click()


@pytest.mark.tier(3)
Expand All @@ -777,13 +779,13 @@ def test_rolename_duplicate_validation(appliance):
tags: rbac
"""
name = 'rol{}'.format(fauxfactory.gen_alphanumeric())
role = new_role(appliance, name=name)
with pytest.raises(RBACOperationBlocked):
new_role(appliance, name=name)

# Navigating away from this page will create an "Abandon Changes" alert
# Since group creation failed we need to reset the state of the page
navigate_to(role.appliance.server, 'Dashboard')
role = appliance.collections.roles.create(name=name)
assert role.exists
view = navigate_to(appliance.collections.roles, 'Add')
view.fill({'name_txt': name})
view.add_button.click()
view.flash.assert_message('Name has already been taken', 'error')
view.cancel_button.click()


@pytest.mark.tier(3)
Expand Down
13 changes: 9 additions & 4 deletions cfme/utils/appliance/implementations/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ def handle_alert(self, cancel=False, wait=30.0, squash=False, prompt=None, check
# throws timeout exception if not found
try:
if wait:
alert = wait_for(self.get_alert, num_sec=wait, fail_condition=None).out
if isinstance(alert, Modal) and BZ(1713399):
popup = wait_for(self.get_alert, num_sec=wait, fail_condition=None).out
if isinstance(popup, Modal) and BZ(1713399).blocks:
# infinispinner if accept button is clicked too quick in modal
sleep(1)

popup = self.get_alert()
else:
popup = self.get_alert()
if popup is None:
raise TimedOutError('Pretending to timeout, no wait') # same logging
self.logger.info('handling alert: %r', popup.text)
if prompt is not None:
self.logger.info(' answering prompt: %r', prompt)
Expand All @@ -94,9 +96,12 @@ def handle_alert(self, cancel=False, wait=30.0, squash=False, prompt=None, check
self.dismiss_any_alerts()
return True
except TimedOutError:
# we waited (or didn't), and there was no alert
if check_present:
self.logger.error('handle_alert timed out with wait of %s, raising', wait)
raise
else:
self.logger.info('handle_alert found no alert with wait of %s', wait)
return None
except Exception:
if squash:
Expand Down

0 comments on commit fe34306

Please sign in to comment.