URL: https://github.com/freeipa/freeipa/pull/1788 Author: tiran Title: #1788: [Backport][ipa-4-6] test_webui: user life-cycles Action: opened
PR body: """ This PR was opened automatically because PR #1740 was pushed to master and backport to ipa-4-6 is required. """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/1788/head:pr1788 git checkout pr1788
From b506b72825713d1a2aa7f7b7cb5322fb861bae36 Mon Sep 17 00:00:00 2001 From: Michal Reznik <mrez...@redhat.com> Date: Mon, 26 Mar 2018 12:32:29 +0200 Subject: [PATCH 1/2] test_webui: add user life-cycles tests Add user life-cycles test cases. https://pagure.io/freeipa/issue/7463 --- ipatests/test_webui/test_user.py | 183 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) diff --git a/ipatests/test_webui/test_user.py b/ipatests/test_webui/test_user.py index bf3d359408..90e74eea1e 100644 --- a/ipatests/test_webui/test_user.py +++ b/ipatests/test_webui/test_user.py @@ -37,6 +37,12 @@ pass +USR_EXIST = 'user with name "{}" already exists' +ENTRY_EXIST = 'This entry already exists' +ACTIVE_ERR = 'active user with name "{}" already exists' +DISABLED = 'This entry is already disabled' + + @pytest.mark.tier1 class user_tasks(UI_driver): def load_file(self, path): @@ -408,3 +414,180 @@ def test_noprivate_gidnumber(self): self.add_record(user.ENTITY, user.DATA4, combobox_input='gidnumber') self.delete(user.ENTITY, [user.DATA4]) + + +@pytest.mark.tier1 +class TestLifeCycles(UI_driver): + + @screenshot + def test_life_cycles(self): + """ + Test user life-cycles + """ + + self.init_app() + + # create "itest-user" and send him to preserved + self.add_record(user.ENTITY, user.DATA) + self.delete_record(user.PKEY, confirm_btn=None) + self.check_option('preserve', value='true') + self.dialog_button_click('ok') + self.assert_notification(assert_text='1 item(s) deleted') + + # try to add the same user again (should fail) + self.add_record(user.ENTITY, user.DATA, negative=True) + self.assert_last_error_dialog(USR_EXIST.format(user.PKEY)) + self.close_all_dialogs() + self.wait() + + # restore "itest-user" user + self.switch_to_facet('search_preserved') + self.select_record(user.PKEY) + self.button_click('undel') + self.dialog_button_click('ok') + self.assert_no_error_dialog() + self.assert_notification(assert_text='1 user(s) restored') + self.wait() + + # add already existing user "itest-user" to stage and try to activate + # the latter (should fail) + self.add_record('stageuser', user.DATA) + self.select_record(user.PKEY) + self.button_click('activate') + self.dialog_button_click('ok') + + err_msg = ACTIVE_ERR.format(user.PKEY) + self.assert_last_error_dialog(err_msg, details=True) + self.dialog_button_click('ok') + + # delete "itest-user" staged user + self.delete_record(user.PKEY) + self.assert_record(user.PKEY, negative=True) + + # add "itest-user2" and send him to staged (through preserved) + self.close_all_dialogs() + self.add_record(user.ENTITY, user.DATA2) + self.delete_record(user.PKEY2, confirm_btn=None) + self.check_option('preserve', value='true') + self.dialog_button_click('ok') + self.switch_to_facet('search_preserved') + self.select_record(user.PKEY2) + self.button_click('batch_stage') + self.dialog_button_click('ok') + self.assert_no_error_dialog() + self.wait(0.7) + # fix assert after https://pagure.io/freeipa/issue/7477 is closed + self.assert_notification(assert_text='1 users(s) staged') + + # add new "itest-user2" - one is already staged (should pass) + self.add_record(user.ENTITY, user.DATA2) + self.assert_record(user.PKEY2) + + # send active "itest-user2" to preserved + self.delete_record(user.PKEY2, confirm_btn=None) + self.check_option('preserve', value='true') + self.dialog_button_click('ok') + + # try to activate staged "itest-user2" while one is already preserved + # (should fail) + self.navigate_to_entity('stageuser') + self.select_record(user.PKEY2) + self.button_click('activate') + self.dialog_button_click('ok') + self.assert_last_error_dialog(ENTRY_EXIST, details=True) + self.dialog_button_click('ok') + + # delete preserved "itest-user2" and activate the staged one + # (should pass) + self.switch_to_facet('search_preserved') + self.delete_record(user.PKEY2) + self.navigate_to_entity('stageuser') + self.select_record(user.PKEY2) + self.button_click('activate') + self.wait() + self.dialog_button_click('ok') + self.assert_notification(assert_text='1 user(s) activated') + + # send multiple records to preserved + self.navigate_to_entity('stageuser') + self.navigate_to_entity('user') + self.delete_record([user.PKEY, user.PKEY2], + confirm_btn=None) + self.check_option('preserve', value='true') + self.dialog_button_click('ok') + self.assert_notification(assert_text='2 item(s) deleted') + + # restore multiple records + self.switch_to_facet('search_preserved') + self.select_multiple_records([user.DATA, user.DATA2]) + self.button_click('undel') + self.dialog_button_click('ok') + self.assert_no_error_dialog() + self.assert_notification(assert_text='2 user(s) restored') + self.wait() + + # send multiple users to staged (through preserved) + self.navigate_to_entity('user') + self.delete_record([user.PKEY, user.PKEY2], + confirm_btn=None) + self.check_option('preserve', value='true') + self.dialog_button_click('ok') + self.switch_to_facet('search_preserved') + self.select_multiple_records([user.DATA, user.DATA2]) + self.button_click('batch_stage') + self.dialog_button_click('ok') + self.assert_no_error_dialog() + self.wait(0.7) + self.assert_notification(assert_text='2 users(s) staged') + + # activate multiple users from stage + self.navigate_to_entity('stageuser') + self.select_multiple_records([user.DATA, user.DATA2]) + self.button_click('activate') + self.dialog_button_click('ok') + self.assert_notification(assert_text='2 user(s) activated') + + # try to disable record from user page + self.navigate_to_entity(user.ENTITY) + self.select_record(user.PKEY) + self.facet_button_click('disable') + self.dialog_button_click('ok') + self.assert_record_value('Disabled', user.PKEY, + 'nsaccountlock') + + # try to disable same record again (should fail) + self.select_record(user.PKEY) + self.facet_button_click('disable') + self.dialog_button_click('ok') + self.assert_last_error_dialog(DISABLED, details=True) + self.dialog_button_click('ok') + + # enable the user again + self.select_record(user.PKEY) + self.facet_button_click('enable') + self.dialog_button_click('ok') + self.assert_record_value('Enabled', user.PKEY, + 'nsaccountlock') + + # same for multiple users (disable, disable again, enable) + self.select_multiple_records([user.DATA, user.DATA2]) + self.facet_button_click('disable') + self.dialog_button_click('ok') + self.assert_record_value('Disabled', [user.PKEY, user.PKEY2], + 'nsaccountlock') + + self.select_multiple_records([user.DATA, user.DATA2]) + self.facet_button_click('disable') + self.dialog_button_click('ok') + self.assert_last_error_dialog(DISABLED, details=True) + self.dialog_button_click('ok') + + self.select_multiple_records([user.DATA, user.DATA2]) + self.facet_button_click('enable') + self.dialog_button_click('ok') + self.assert_record_value('Enabled', [user.PKEY, user.PKEY2], + 'nsaccountlock') + + # cleanup + self.navigate_to_entity('user') + self.delete_record([user.PKEY, user.PKEY2]) From cea1c0e1f1564fc4c6ac865cce450cba2874fb94 Mon Sep 17 00:00:00 2001 From: Michal Reznik <mrez...@redhat.com> Date: Mon, 26 Mar 2018 12:34:25 +0200 Subject: [PATCH 2/2] test_web_ui: extend ui_driver methods Add close_all_dialogs(),change assert_last_dialog_details() method to assert_last_error_dialog() to make it more generic and tweak add_record() method to skip asserts so we can assert later. We are also changing assert_record_value() to accept list of values and adding select_multiple_records(). https://pagure.io/freeipa/issue/7463 --- ipatests/test_webui/ui_driver.py | 69 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py index a9d9385143..c60ef34fab 100644 --- a/ipatests/test_webui/ui_driver.py +++ b/ipatests/test_webui/ui_driver.py @@ -717,6 +717,20 @@ def close_notifications(self): else: break + def close_all_dialogs(self): + """ + Close all currently opened dialogs + """ + self.wait() + while True: + s = ".modal.fade.in .modal-header button.close" + btn = self.find(s, By.CSS_SELECTOR) + if btn: + btn.click() + self.wait(0.5) + else: + break + def get_form(self): """ Get last dialog or visible facet @@ -1024,6 +1038,15 @@ def select_record(self, pkey, parent=None, 'Record was not checked: %s' % input_s self.wait() + def select_multiple_records(self, records): + """ + Select multiple records + """ + + for data in records: + pkey = data['pkey'] + self.select_record(pkey) + def get_record_value(self, pkey, column, parent=None, table_name=None): """ Get table column's text value @@ -1236,10 +1259,13 @@ def find_record(self, entity, data, facet='search', dummy='XXXXXXX'): def add_record(self, entity, data, facet='search', facet_btn='add', dialog_btn='add', delete=False, pre_delete=True, - dialog_name='add', navigate=True, combobox_input=None): + dialog_name='add', navigate=True, combobox_input=None, + negative=False): """ Add records. + When negative=True we are skipping final assertions. + Expected data format: { 'pkey': 'key', @@ -1285,6 +1311,9 @@ def add_record(self, entity, data, facet='search', facet_btn='add', self.dialog_button_click('ok') self.wait_for_request() + if negative: + return + # check for error self.assert_no_error_dialog() self.wait_for_request() @@ -1851,12 +1880,20 @@ def assert_indirect_record(self, pkey, entity, facet, negative=False, switch=Tru key = pkey self.assert_record(key, negative=negative) - def assert_record_value(self, expected, pkey, column, parent=None, table_name=None): + def assert_record_value(self, expected, pkeys, column, parent=None, + table_name=None): """ - Assert that column's value of record defined by pkey equals expected value. + Assert that column's value of record defined by pkey equals expected + value. """ - val = self.get_record_value(pkey, column, parent, table_name) - assert expected == val, "Invalid value: '%s'. Expected: '%s'." % (val, expected) + + if type(pkeys) is not list: + pkeys = [pkeys] + + for pkey in pkeys: + val = self.get_record_value(pkey, column, parent, table_name) + assert expected == val, ("Invalid value: '%s'. Expected: '%s'." + % (val, expected)) def assert_class(self, element, cls, negative=False): """ @@ -1970,3 +2007,25 @@ def assert_notification(self, type='success', assert_text=None): assert is_present, "Notification not present" if assert_text: assert assert_text in is_present.text + + def assert_last_error_dialog(self, expected_err, details=False, + dialog_name='error_dialog'): + """ + Assert error dialog body text or when details=True click on + 'Show details' and assert text there + """ + + err_dialog = self.get_last_error_dialog(dialog_name=dialog_name) + + if details: + # open "Show details" paragraph + s = 'a[title="Show details"]' + details = self.find(s, By.CSS_SELECTOR) + details.click() + + s = 'ul.error-container li p' + self.assert_text(s, expected_err, parent=err_dialog) + + else: + s = '.modal-body div p' + self.assert_text(s, expected_err, parent=err_dialog)
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org