diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2013-07-17 10:47:57 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2013-07-26 13:35:12 +0200 |
commit | 8a3d8aeca3bec741f8c23652848075c298bea5f1 (patch) | |
tree | 080ff69c532231a0162615472e9562993c78a974 /ipatests/test_webui | |
parent | a3567cef981c0cd6883debcd000651a8b12dd247 (diff) | |
download | freeipa.git-8a3d8aeca3bec741f8c23652848075c298bea5f1.tar.gz freeipa.git-8a3d8aeca3bec741f8c23652848075c298bea5f1.tar.xz freeipa.git-8a3d8aeca3bec741f8c23652848075c298bea5f1.zip |
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
Diffstat (limited to 'ipatests/test_webui')
-rw-r--r-- | ipatests/test_webui/test_range.py | 68 | ||||
-rw-r--r-- | ipatests/test_webui/ui_driver.py | 25 |
2 files changed, 79 insertions, 14 deletions
diff --git a/ipatests/test_webui/test_range.py b/ipatests/test_webui/test_range.py index baa53cba..93e3e789 100644 --- a/ipatests/test_webui/test_range.py +++ b/ipatests/test_webui/test_range.py @@ -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)) diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py index ef97a11f..508418b6 100644 --- a/ipatests/test_webui/ui_driver.py +++ b/ipatests/test_webui/ui_driver.py @@ -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. |