ipatests: webui: Tests for subordinate ids.

Added web-ui tests to verify where operations
using subordinate ids are working as expected.

Related : https://pagure.io/freeipa/issue/8361

Signed-off-by: Anuja More <amore@redhat.com>
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
This commit is contained in:
Anuja More 2021-12-06 20:50:01 +05:30 committed by Michal Polovka
parent df03dd9bfe
commit c2f2597b6d
No known key found for this signature in database
GPG Key ID: 4934889DC424FE12
2 changed files with 169 additions and 0 deletions

View File

@ -0,0 +1,141 @@
"""
Tests for subordinateid.
"""
from ipatests.test_webui.ui_driver import UI_driver
import ipatests.test_webui.data_config as config_data
import ipatests.test_webui.data_user as user_data
from ipatests.test_webui.ui_driver import screenshot
import re
class test_subid(UI_driver):
def add_user(self, pkey, name, surname):
self.add_record('user', {
'pkey': pkey,
'add': [
('textbox', 'uid', pkey),
('textbox', 'givenname', name),
('textbox', 'sn', surname),
]
})
def set_default_subid(self):
self.navigate_to_entity(config_data.ENTITY)
self.check_option('ipauserdefaultsubordinateid', 'checked')
self.facet_button_click('save')
def get_user_count(self, user_pkey):
self.navigate_to_entity('subid', facet='search')
self.apply_search_filter(user_pkey)
self.wait_for_request()
return self.get_rows()
@screenshot
def test_set_defaultsubid(self):
"""
Test to verify that enable/disable is working for
adding subids to new users.
"""
self.init_app()
self.add_record(user_data.ENTITY, user_data.DATA2)
self.navigate_to_entity(config_data.ENTITY)
# test subid can be enabled/disabled.
self.set_default_subid()
assert self.get_field_checked('ipauserdefaultsubordinateid')
self.set_default_subid()
assert not self.get_field_checked('ipauserdefaultsubordinateid')
@screenshot
def test_user_defaultsubid(self):
"""
Test to verify that subid is generated for new user.
"""
self.init_app()
user_pkey = "some-user"
self.set_default_subid()
assert self.get_field_checked('ipauserdefaultsubordinateid')
before_count = self.get_user_count(user_pkey)
assert len(before_count) == 0
self.add_user(user_pkey, 'Some', 'User')
after_count = self.get_user_count(user_pkey)
assert len(after_count) == 1
@screenshot
def test_user_subid_mod_desc(self):
"""
Test to verify that auto-assigned subid description is modified.
"""
self.init_app()
self.navigate_to_record("some-user")
self.switch_to_facet('memberof_subid')
rows = self.get_rows()
self.navigate_to_row_record(rows[-1])
self.fill_textbox("description", "some-user-subid-desc")
self.facet_button_click('save')
@screenshot
def test_admin_subid(self):
"""
Test to verify that subid range is created with owner admin.
"""
self.init_app()
self.navigate_to_entity('subid', facet='search')
self.facet_button_click('add')
self.select_combobox('ipaowner', 'admin')
self.dialog_button_click('add')
self.wait(0.3)
self.assert_no_error_dialog()
@screenshot
def test_admin_subid_negative(self):
"""
Test to verify that readding the subid fails with error.
"""
self.init_app()
self.navigate_to_entity('subid', facet='search')
self.facet_button_click('add')
self.select_combobox('ipaowner', 'admin')
self.dialog_button_click('add')
self.wait(0.3)
err_dialog = self.get_last_error_dialog(dialog_name='error_dialog')
text = self.get_text('.modal-body div p', err_dialog)
text = text.strip()
pattern = r'Subordinate id with with name .* already exists.'
assert re.search(pattern, text) is not None
self.close_all_dialogs()
@screenshot
def test_user_subid_add(self):
"""
Test to verify that subid range is created for given user.
"""
self.init_app()
self.navigate_to_entity('subid', facet='search')
before_count = self.get_rows()
self.facet_button_click('add')
self.select_combobox('ipaowner', user_data.PKEY2)
self.dialog_button_click('add')
self.wait(0.3)
self.assert_no_error_dialog()
after_count = self.get_rows()
assert len(before_count) < len(after_count)
@screenshot
def test_subid_del(self):
"""
Test to remove subordinate id for given user.
"""
self.init_app()
self.navigate_to_entity('subid', facet='search')
user_uid = self.get_record_pkey("some-user", "ipaowner",
table_name="ipauniqueid")
before_count = self.get_rows()
self.delete_record(user_uid, table_name="ipauniqueid")
after_count = self.get_rows()
assert len(before_count) > len(after_count)

View File

@ -1150,6 +1150,34 @@ class UI_driver:
return row
return None
def get_row_by_column_value(self, key, column_name, parent=None,
table_name=None):
"""
Get the first matched row element of a search table with given key
matched against selected column. None if not found
"""
rows = self.get_rows(parent, table_name)
s = "td div[name='%s']" % column_name
for row in rows:
has = self.find(s, By.CSS_SELECTOR, row)
if has.text == key:
return row
return None
def get_record_pkey(self, key, column, parent=None, table_name=None):
"""
Get record pkey if value of column is known
"""
row = self.get_row_by_column_value(key,
column_name=column,
parent=parent,
table_name=table_name)
val = None
if row:
el = self.find("td input", By.CSS_SELECTOR, row)
val = el.get_attribute("value")
return val
def navigate_to_row_record(self, row, pkey_column=None):
"""
Navigate to record by clicking on a link.