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

Commit fe34306

Browse files
authored
Merge pull request #8877 from mshriver/fix-alert-attr
[1LP][RFR] Fix AttributeError in HandleModalsMixin.handle_alert
2 parents a5cafdf + 5fa9f16 commit fe34306

4 files changed

Lines changed: 32 additions & 22 deletions

File tree

cfme/configure/access_control/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ class Role(Updateable, Pretty, BaseEntity):
10081008

10091009
pretty_attrs = ['name', 'product_features']
10101010

1011-
name = attr.ib(default=None)
1011+
name = attr.ib()
10121012
vm_restriction = attr.ib(default=None)
10131013
product_features = attr.ib(default=None)
10141014

@@ -1135,7 +1135,7 @@ def set_role_product_features(view, product_features):
11351135
class RoleCollection(BaseCollection):
11361136
ENTITY = Role
11371137

1138-
def create(self, name=None, vm_restriction=None, product_features=None, cancel=False):
1138+
def create(self, name, vm_restriction=None, product_features=None, cancel=False):
11391139
""" Create role method
11401140
11411141
Args:
@@ -1151,7 +1151,6 @@ def create(self, name=None, vm_restriction=None, product_features=None, cancel=F
11511151
for currently selected role
11521152
"""
11531153
flash_blocked_msg = "Name has already been taken"
1154-
11551154
role = self.instantiate(
11561155
name=name, vm_restriction=vm_restriction, product_features=product_features
11571156
)

cfme/fixtures/tag.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ def category(appliance):
2121
display_name=fauxfactory.gen_alphanumeric(length=32)
2222
)
2323
yield cg
24+
appliance.server.login_admin()
2425
cg.delete_if_exists()
2526

2627

2728
@pytest.fixture(scope="session")
28-
def tag(category):
29+
def tag(category, appliance):
2930
"""
3031
Returns random created tag object
3132
Object can be used in all test run session
@@ -35,6 +36,7 @@ def tag(category):
3536
display_name=fauxfactory.gen_alphanumeric(length=32)
3637
)
3738
yield tag
39+
appliance.server.login_admin()
3840
tag.delete_if_exists()
3941

4042

@@ -47,6 +49,7 @@ def role(appliance):
4749
name='role{}'.format(fauxfactory.gen_alphanumeric()),
4850
vm_restriction='None')
4951
yield role
52+
appliance.server.login_admin()
5053
role.delete_if_exists()
5154

5255

@@ -61,6 +64,7 @@ def group_with_tag(appliance, role, category, tag):
6164
tag=([category.display_name, tag.display_name], True)
6265
)
6366
yield group
67+
appliance.server.login_admin()
6468
group.delete_if_exists()
6569

6670

@@ -78,6 +82,7 @@ def user_restricted(appliance, group_with_tag, new_credential):
7882
cost_center='Workload',
7983
value_assign='Database')
8084
yield user
85+
appliance.server.login_admin()
8186
user.delete_if_exists()
8287

8388

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

9397

9498
@pytest.fixture(scope='function')

cfme/tests/configure/test_access_control.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,13 @@ def test_rolename_required_error_validation(appliance):
760760
# When trying to create a role with no name, the Add button is disabled.
761761
# We are waiting for an Exception saying that there are no success
762762
# or fail messages, because the Add button cannot be clicked.
763-
with pytest.raises(Exception, match=r"Available messages: \[\]"):
764-
appliance.collections.roles.create(
765-
name=None,
766-
vm_restriction='Only User Owned'
767-
)
763+
view = navigate_to(appliance.collections.roles, 'Add')
764+
view.fill({'name_txt': '',
765+
'vm_restriction_select': 'Only User Owned'})
766+
assert view.add_button.disabled
767+
view.fill({'name_txt': 'test-required-name'})
768+
assert not view.add_button.disabled
769+
view.cancel_button.click()
768770

769771

770772
@pytest.mark.tier(3)
@@ -777,13 +779,13 @@ def test_rolename_duplicate_validation(appliance):
777779
tags: rbac
778780
"""
779781
name = 'rol{}'.format(fauxfactory.gen_alphanumeric())
780-
role = new_role(appliance, name=name)
781-
with pytest.raises(RBACOperationBlocked):
782-
new_role(appliance, name=name)
783-
784-
# Navigating away from this page will create an "Abandon Changes" alert
785-
# Since group creation failed we need to reset the state of the page
786-
navigate_to(role.appliance.server, 'Dashboard')
782+
role = appliance.collections.roles.create(name=name)
783+
assert role.exists
784+
view = navigate_to(appliance.collections.roles, 'Add')
785+
view.fill({'name_txt': name})
786+
view.add_button.click()
787+
view.flash.assert_message('Name has already been taken', 'error')
788+
view.cancel_button.click()
787789

788790

789791
@pytest.mark.tier(3)

cfme/utils/appliance/implementations/common.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ def handle_alert(self, cancel=False, wait=30.0, squash=False, prompt=None, check
7171
# throws timeout exception if not found
7272
try:
7373
if wait:
74-
alert = wait_for(self.get_alert, num_sec=wait, fail_condition=None).out
75-
if isinstance(alert, Modal) and BZ(1713399):
74+
popup = wait_for(self.get_alert, num_sec=wait, fail_condition=None).out
75+
if isinstance(popup, Modal) and BZ(1713399).blocks:
7676
# infinispinner if accept button is clicked too quick in modal
7777
sleep(1)
78-
79-
popup = self.get_alert()
78+
else:
79+
popup = self.get_alert()
80+
if popup is None:
81+
raise TimedOutError('Pretending to timeout, no wait') # same logging
8082
self.logger.info('handling alert: %r', popup.text)
8183
if prompt is not None:
8284
self.logger.info(' answering prompt: %r', prompt)
@@ -94,9 +96,12 @@ def handle_alert(self, cancel=False, wait=30.0, squash=False, prompt=None, check
9496
self.dismiss_any_alerts()
9597
return True
9698
except TimedOutError:
99+
# we waited (or didn't), and there was no alert
97100
if check_present:
101+
self.logger.error('handle_alert timed out with wait of %s, raising', wait)
98102
raise
99103
else:
104+
self.logger.info('handle_alert found no alert with wait of %s', wait)
100105
return None
101106
except Exception:
102107
if squash:

0 commit comments

Comments
 (0)