Web UI integration tests: ID range types

https://fedorahosted.org/freeipa/ticket/3834
This commit is contained in:
Petr Vobornik 2013-08-16 18:18:53 +02:00
parent 0584caf56a
commit 278c87cc62
4 changed files with 281 additions and 72 deletions

View File

@ -0,0 +1,102 @@
# Authors:
# Petr Vobornik <pvoborni@redhat.com>
#
# Copyright (C) 2013 Red Hat
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Range tasks
"""
from ipatests.test_webui.ui_driver import UI_driver
class range_tasks(UI_driver):
def get_shifts(self, idranges=None):
if not idranges:
result = self.execute_api_from_ui('idrange_find', [], {})
idranges = result['result']['result']
id_shift = 0
rid_shift = 0
for idrange in idranges:
size = int(idrange['ipaidrangesize'][0])
base_id = int(idrange['ipabaseid'][0])
id_end = base_id + size
rid_end = 0
if 'ipabaserid' in idrange:
base_rid = int(idrange['ipabaserid'][0])
rid_end = base_rid + size
if 'ipasecondarybaserid' in idrange:
secondary_base_rid = int(idrange['ipasecondarybaserid'][0])
rid_end = max(base_rid, secondary_base_rid) + size
if id_shift < id_end:
id_shift = id_end + 1000000
if rid_shift < rid_end:
rid_shift = rid_end + 1000000
self.id_shift = id_shift
self.rid_shift = rid_shift
self.sec_rid_shift = rid_shift + 1000
self.shift = 0
def get_sid(self):
result = self.execute_api_from_ui('trust_find', [], {})
trusts = result['result']['result']
sid = None
if trusts:
sid = trusts[0]['ipanttrusteddomainsid']
return sid
def get_data(self, pkey, size=50, add_data=None):
if not add_data:
add_data = self.get_add_data(pkey, size=size)
data = {
'pkey': pkey,
'add': add_data,
'mod': [
('textbox', 'ipaidrangesize', str(size + 1)),
],
}
return data
def get_add_data(self, pkey, range_type='ipa-local', size=50, shift=100, sid=None):
self.shift += shift
add = [
('textbox', 'cn', pkey),
('textbox', 'ipabaseid', str(self.id_shift + self.shift)),
('textbox', 'ipaidrangesize', str(size)),
('textbox', 'ipabaserid', str(self.rid_shift + self.shift)),
('radio', 'iparangetype', range_type),
]
if not sid:
add.append(('textbox', 'ipasecondarybaserid', str(self.sec_rid_shift + self.shift)))
if sid:
add.append(('textbox', 'ipanttrusteddomainsid', sid))
return add

View File

@ -18,68 +18,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
User tests
Range tests
"""
from ipatests.test_webui.ui_driver import UI_driver
import ipatests.test_webui.test_trust as trust_mod
from ipatests.test_webui.task_range import range_tasks
ENTITY = 'idrange'
PKEY = 'itest-range'
class test_range(UI_driver):
def get_shifts(self, idranges=None):
if not idranges:
result = self.execute_api_from_ui('idrange_find', [], {})
idranges = result['result']['result']
id_shift = 0
rid_shift = 0
for idrange in idranges:
size = int(idrange['ipaidrangesize'][0])
base_id = int(idrange['ipabaseid'][0])
id_end = base_id + size
rid_end = 0
if 'ipabaserid' in idrange:
base_rid = int(idrange['ipabaserid'][0])
rid_end = base_rid + size
if 'ipasecondarybaserid' in idrange:
secondary_base_rid = int(idrange['ipasecondarybaserid'][0])
rid_end = max(base_rid, secondary_base_rid) + size
if id_shift < id_end:
id_shift = id_end + 1000000
if rid_shift < rid_end:
rid_shift = rid_end + 1000000
self.id_shift = id_shift
self.rid_shift = rid_shift
self.sec_rid_shift = rid_shift + 1000
self.shift = 0
def get_data(self, pkey, size=50, shift=100):
self.shift += shift
data = {
'pkey': pkey,
'add': [
('textbox', 'cn', pkey),
('textbox', 'ipabaseid', str(self.id_shift + self.shift)),
('textbox', 'ipaidrangesize', str(size)),
('textbox', 'ipabaserid', str(self.rid_shift + self.shift)),
('textbox', 'ipasecondarybaserid', str(self.sec_rid_shift + self.shift)),
],
'mod': [
('textbox', 'ipaidrangesize', str(size + 1)),
],
}
return data
class test_range(range_tasks):
def test_crud(self):
"""
@ -88,3 +37,66 @@ class test_range(UI_driver):
self.init_app()
self.get_shifts()
self.basic_crud(ENTITY, self.get_data(PKEY))
def test_types(self):
"""
Test range types
"""
self.init_app()
self.get_shifts()
pkey_local = 'itest-local'
pkey_ad = 'itest-ad'
pkey_posix = 'itest-ad-posix'
pkey_winsync = 'itest-ad-winsync'
pkey_trust = 'itest-ipa-trust'
column = 'iparangetype'
add = self.get_add_data(pkey_local)
data = self.get_data(pkey_local, add_data=add)
self.add_record(ENTITY, data)
self.assert_record_value('local domain range', pkey_local, column)
if self.has_trusts():
trust_tasks = trust_mod.trust_tasks()
trust_data = trust_tasks.get_data()
self.add_record(trust_mod.ENTITY, trust_data)
sid = self.get_sid()
self.navigate_to_entity(ENTITY)
self.facet_button_click('refresh')
self.wait_for_request(n=2)
add = self.get_add_data(pkey_ad, range_type='ipa-ad-trust', sid=sid)
data = self.get_data(pkey_ad, add_data=add)
self.add_record(ENTITY, data, navigate=False)
self.assert_record_value('Active Directory domain range', pkey_ad, column)
add = self.get_add_data(pkey_posix, range_type='ipa-ad-trust-posix', sid=sid)
data = self.get_data(pkey_posix, add_data=add)
self.add_record(ENTITY, data, navigate=False)
self.assert_record_value('Active Directory trust range with POSIX attributes', pkey_posix, column)
self.delete(trust_mod.ENTITY, [trust_data])
self.navigate_to_entity(ENTITY)
self.delete_record(pkey_ad)
self.delete_record(pkey_posix)
self.delete_record(trust_tasks.get_range_name())
add = self.get_add_data(pkey_winsync, range_type='ipa-ad-winsync')
data = self.get_data(pkey_winsync, add_data=add)
self.add_record(ENTITY, data, navigate=False)
self.assert_record_value('Active Directory winsync range', pkey_winsync, column)
add = self.get_add_data(pkey_trust, range_type='ipa-ipa-trust')
data = self.get_data(pkey_trust, add_data=add)
self.add_record(ENTITY, data, navigate=False)
self.assert_record_value('IPA trust range', pkey_trust, column)
self.delete_record(pkey_local)
self.delete_record(pkey_winsync)
self.delete_record(pkey_trust)

View File

@ -22,6 +22,7 @@ Trust tests
"""
from ipatests.test_webui.ui_driver import UI_driver
from ipatests.test_webui.task_range import range_tasks
ENTITY = 'trust'
CONFIG_ENTITY = 'trustconfig'
@ -39,27 +40,18 @@ CONFIG_DATA2 = {
}
class test_trust(UI_driver):
class trust_tasks(UI_driver):
def __init__(self, *args, **kwargs):
super(test_trust, self).__init__(args, kwargs)
if not self.has_trusts():
self.skip('Trusts not configured')
def get_data(self):
def get_data(self, add_data=None):
domain = self.config.get('ad_domain')
admin = self.config.get('ad_admin')
psw = self.config.get('ad_password')
if not add_data:
add_data = self.get_add_data()
data = {
'pkey': domain,
'add': [
('textbox', 'realm_server', domain),
('textbox', 'realm_admin', admin),
('password', 'realm_passwd', psw),
],
'add': add_data,
'mod': [
('multivalued', 'ipantsidblacklistincoming', [
('del', 'S-1-5-18'),
@ -74,6 +66,40 @@ class test_trust(UI_driver):
return data
def get_add_data(self, range_type=None, base_id=None, range_size=None):
domain = self.config.get('ad_domain')
admin = self.config.get('ad_admin')
psw = self.config.get('ad_password')
add = [
('textbox', 'realm_server', domain),
('textbox', 'realm_admin', admin),
('password', 'realm_passwd', psw),
]
if range_type:
add.append(('radio', 'range_type', range_type))
if base_id:
add.append(('textbox', 'base_id', base_id))
if range_size:
add.append(('textbox', 'range_size', range_size))
return add
def get_range_name(self):
domain = self.config.get('ad_domain')
return domain.upper() + '_id_range'
class test_trust(trust_tasks):
def __init__(self, *args, **kwargs):
super(test_trust, self).__init__(args, kwargs)
if not self.has_trusts():
self.skip('Trusts not configured')
def test_crud(self):
"""
Basic basic CRUD: trust
@ -82,9 +108,46 @@ class test_trust(UI_driver):
"""
self.init_app()
data = self.get_data()
self.navigate_to_entity('idrange')
self.delete_record(self.get_range_name())
self.basic_crud(ENTITY, data)
self.navigate_to_entity('idrange')
self.delete_record(self.get_range_name())
def test_range_types(self):
self.init_app()
r_tasks = range_tasks(self.driver, self.config)
r_tasks.get_shifts()
base_id = r_tasks.id_shift + 100
range_size = 50
range_pkey = self.get_range_name()
column = 'iparangetype'
self.navigate_to_entity('idrange')
self.delete_record(range_pkey)
add = self.get_add_data('ipa-ad-trust', base_id, range_size)
data = self.get_data(add_data=add)
self.add_record(ENTITY, data, delete=True)
self.navigate_to_entity('idrange')
self.facet_button_click('refresh')
self.wait_for_request(n=2)
self.assert_record_value('Active Directory domain range', range_pkey, column)
self.delete_record(range_pkey)
add = self.get_add_data('ipa-ad-trust-posix', base_id, range_size)
data = self.get_data(add_data=add)
self.add_record(ENTITY, data, delete=True)
self.navigate_to_entity('idrange')
self.facet_button_click('refresh')
self.wait_for_request(n=2)
self.assert_record_value('Active Directory trust range with POSIX attributes', range_pkey, column)
self.delete_record(range_pkey)
def test_config_mod(self):
self.init_app()
self.navigate_to_entity(CONFIG_ENTITY)

View File

@ -795,7 +795,7 @@ class UI_driver(object):
undos = self.find(s, By.CSS_SELECTOR, parent, strict=True, many=True)
return undos
def get_rows(self, parent=None):
def get_rows(self, parent=None, name=None):
"""
Return all rows of search table.
"""
@ -803,10 +803,23 @@ class UI_driver(object):
parent = self.get_form()
# select table rows
s = 'table.search-table tbody tr'
s = self.get_table_selector(name)
s += ' tbody tr'
rows = self.find(s, By.CSS_SELECTOR, parent, many=True)
return rows
def get_row(self, pkey, parent=None, name=None):
"""
Get row element of search table with given pkey. None if not found.
"""
rows = self.get_rows(parent, name)
s = "input[value='%s']" % pkey
for row in rows:
has = self.find(s, By.CSS_SELECTOR, row)
if has:
return row
return None
def navigate_to_row_record(self, row, pkey_column=None):
"""
Navigate to record by clicking on a link.
@ -842,6 +855,18 @@ class UI_driver(object):
checkbox.click()
self.wait()
def get_record_value(self, pkey, column, parent=None, table_name=None):
"""
Get table column's text value
"""
row = self.get_row(pkey, parent, table_name)
s = "div[name=%s]" % column
val = None
if row:
el = self.find(s, By.CSS_SELECTOR, row)
val = el.text
return val
def has_record(self, pkey, parent=None, table_name=None):
"""
Check if table contains specific record.
@ -1506,6 +1531,13 @@ class UI_driver(object):
key = key.lower()
self.assert_record(key, negative=negative)
def assert_record_value(self, expected, pkey, column, parent=None, table_name=None):
"""
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)
def assert_class(self, element, cls, negative=False):
"""
Assert that element has certain class