Web UI integration tests: Compute range sizes to avoid overlaps

Heavily inspired by code from xmlrpc tests.

To obtain ranges, this patch also adds method to execute FreeIPA command through Web UI.
It uses Web UI instead of ipalib so it doesn't need to care about authentication on a test-runner machine.

https://fedorahosted.org/freeipa/ticket/3744
This commit is contained in:
Petr Vobornik 2013-07-17 10:47:57 +02:00
parent a3567cef98
commit 8a3d8aeca3
2 changed files with 79 additions and 14 deletions

View File

@ -25,25 +25,65 @@ from ipatests.test_webui.ui_driver import UI_driver
ENTITY = 'idrange'
PKEY = 'itest-range'
DATA = {
'pkey': PKEY,
'add': [
('textbox', 'cn', PKEY),
('textbox', 'ipabaseid', '900000'),
('textbox', 'ipaidrangesize', '99999'),
('textbox', 'ipabaserid', '10000'),
('textbox', 'ipasecondarybaserid', '200000'),
],
'mod': [
('textbox', 'ipaidrangesize', '100000'),
],
}
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
def test_crud(self):
"""
Basic CRUD: range
"""
self.init_app()
self.basic_crud(ENTITY, DATA)
self.get_shifts()
self.basic_crud(ENTITY, self.get_data(PKEY))

View File

@ -489,6 +489,31 @@ class UI_driver(object):
}
return info
def execute_api_from_ui(self, method, args, options, timeout=30):
"""
Executes FreeIPA API command/method from Web UI
"""
script = """
var method = arguments[0];
var args = arguments[1];
var options = arguments[2];
var callback = arguments[arguments.length - 1];
var IPA = require('freeipa/ipa');
var cmd = IPA.command({
method: method,
args: args,
options: options,
on_success: callback,
on_error: callback
});
cmd.execute();
"""
self.driver.set_script_timeout(timeout)
result = self.driver.execute_async_script(script, *[method, args, options])
return result
def click_on_link(self, text, parent=None):
"""
Click on link with given text and parent.