On 08/19/2013 05:33 PM, Petr Vobornik wrote:
https://fedorahosted.org/freeipa/ticket/3834


New version. Fixes usage of secondary rid for non-trust installation.

--
Petr Vobornik
From 4f8358e9aa8a4ec2e28d47acd351b556cd10c272 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Fri, 16 Aug 2013 18:18:53 +0200
Subject: [PATCH] Web UI integration tests: ID range types

https://fedorahosted.org/freeipa/ticket/3834
---
 .../test_webui/{test_range.py => task_range.py}    |  54 +++++----
 ipatests/test_webui/test_range.py                  | 122 +++++++++++----------
 ipatests/test_webui/test_trust.py                  |  93 +++++++++++++---
 ipatests/test_webui/ui_driver.py                   |  36 +++++-
 4 files changed, 212 insertions(+), 93 deletions(-)
 copy ipatests/test_webui/{test_range.py => task_range.py} (66%)

diff --git a/ipatests/test_webui/test_range.py b/ipatests/test_webui/task_range.py
similarity index 66%
copy from ipatests/test_webui/test_range.py
copy to ipatests/test_webui/task_range.py
index 0a7da7e4f3a804c1b4469cac225488b29dcd3138..4775078e7388078ccf4d6a59288388c3dd363ff5 100644
--- a/ipatests/test_webui/test_range.py
+++ b/ipatests/test_webui/task_range.py
@@ -18,16 +18,13 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 """
-User tests
+Range tasks
 """
 
 from ipatests.test_webui.ui_driver import UI_driver
 
-ENTITY = 'idrange'
-PKEY = 'itest-range'
 
-
-class test_range(UI_driver):
+class range_tasks(UI_driver):
 
     def get_shifts(self, idranges=None):
 
@@ -64,27 +61,42 @@ class test_range(UI_driver):
         self.sec_rid_shift = rid_shift + 1000
         self.shift = 0
 
-    def get_data(self, pkey, size=50, shift=100):
-        self.shift += shift
+    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': [
-                ('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)),
-            ],
+            'add': add_data,
             'mod': [
                 ('textbox', 'ipaidrangesize', str(size + 1)),
             ],
         }
         return data
 
-    def test_crud(self):
-        """
-        Basic CRUD: range
-        """
-        self.init_app()
-        self.get_shifts()
-        self.basic_crud(ENTITY, self.get_data(PKEY))
+    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
diff --git a/ipatests/test_webui/test_range.py b/ipatests/test_webui/test_range.py
index 0a7da7e4f3a804c1b4469cac225488b29dcd3138..98c4098a6dba51d9b5d17c36727e3609f5c7ba36 100644
--- a/ipatests/test_webui/test_range.py
+++ b/ipatests/test_webui/test_range.py
@@ -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)
diff --git a/ipatests/test_webui/test_trust.py b/ipatests/test_webui/test_trust.py
index e308844d976950439434b67122581b4af849babf..713bcfa640f3767bd1d1b987c4b795d32349cf02 100644
--- a/ipatests/test_webui/test_trust.py
+++ b/ipatests/test_webui/test_trust.py
@@ -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)
 
diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py
index 9653b613261305bac2a0044d25bf272e2a73e42a..fab846b480056f37aeb29b857dfb206fec214529 100644
--- a/ipatests/test_webui/ui_driver.py
+++ b/ipatests/test_webui/ui_driver.py
@@ -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
-- 
1.8.3.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to