airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davy...@apache.org
Subject incubator-airflow git commit: [AIRFLOW-1621] Add tests for server side paging
Date Tue, 19 Sep 2017 22:52:55 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master 6e520704f -> 656d045e9


[AIRFLOW-1621] Add tests for server side paging

Adding tests to check logic included in
AIRFLOW-1519.

Closes #2614 from edgarRd/erod-ui-dags-paging-
tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/656d045e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/656d045e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/656d045e

Branch: refs/heads/master
Commit: 656d045e90bf67ca484a3778b2a07a419bfb324a
Parents: 6e52070
Author: Edgar Rodriguez <edgar.rodriguez@airbnb.com>
Authored: Tue Sep 19 15:52:26 2017 -0700
Committer: Dan Davydov <dan.davydov@airbnb.com>
Committed: Tue Sep 19 15:52:30 2017 -0700

----------------------------------------------------------------------
 airflow/www/utils.py    | 26 ++++++++--------
 tests/www/test_utils.py | 73 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/656d045e/airflow/www/utils.py
----------------------------------------------------------------------
diff --git a/airflow/www/utils.py b/airflow/www/utils.py
index 344a4e9..96293a2 100644
--- a/airflow/www/utils.py
+++ b/airflow/www/utils.py
@@ -76,6 +76,20 @@ class DataProfilingMixin(object):
         )
 
 
+def get_params(**kwargs):
+    params = []
+    for k, v in kwargs.items():
+        if k == 'showPaused':
+            # True is default or None
+            if v or v is None:
+                continue
+            params.append('{}={}'.format(k, v))
+        elif v:
+            params.append('{}={}'.format(k, v))
+    params = sorted(params, key=lambda x: x.split('=')[0])
+    return '&'.join(params)
+
+
 def generate_pages(current_page, num_of_pages,
                    search=None, showPaused=None, window=7):
     """
@@ -103,18 +117,6 @@ def generate_pages(current_page, num_of_pages,
         the HTML string of the paging component
     """
 
-    def get_params(**kwargs):
-        params = []
-        for k, v in kwargs.items():
-            if k == 'showPaused':
-                # True is default or None
-                if v or v is None:
-                    continue
-                params.append('{}={}'.format(k, v))
-            elif v:
-                params.append('{}={}'.format(k, v))
-        return '&'.join(params)
-
     void_link = 'javascript:void(0)'
     first_node = """<li class="paginate_button {disabled}" id="dags_first">
     <a href="{href_link}" aria-controls="dags" data-dt-idx="0" tabindex="0">&laquo;</a>

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/656d045e/tests/www/test_utils.py
----------------------------------------------------------------------
diff --git a/tests/www/test_utils.py b/tests/www/test_utils.py
index bb0860f..d13a49d 100644
--- a/tests/www/test_utils.py
+++ b/tests/www/test_utils.py
@@ -13,6 +13,7 @@
 # limitations under the License.
 
 import unittest
+from xml.dom import minidom
 
 from airflow.www import utils
 
@@ -31,6 +32,78 @@ class UtilsTest(unittest.TestCase):
     def test_sensitive_variable_should_be_hidden_ic(self):
         self.assertTrue(utils.should_hide_value_for_key("GOOGLE_API_KEY"))
 
+    def check_generate_pages_html(self, current_page, total_pages,
+                                  window=7, check_middle=False):
+        extra_links = 4  # first, prev, next, last
+        html_str = utils.generate_pages(current_page, total_pages)
+
+        # dom parser has issues with special &laquo; and &raquo;
+        html_str = html_str.replace('&laquo;', '')
+        html_str = html_str.replace('&raquo;', '')
+        dom = minidom.parseString(html_str)
+        self.assertIsNotNone(dom)
+
+        ulist = dom.getElementsByTagName('ul')[0]
+        ulist_items = ulist.getElementsByTagName('li')
+        self.assertEqual(min(window, total_pages) + extra_links, len(ulist_items))
+
+        def get_text(nodelist):
+            rc = []
+            for node in nodelist:
+                if node.nodeType == node.TEXT_NODE:
+                    rc.append(node.data)
+            return ''.join(rc)
+
+        page_items = ulist_items[2:-2]
+        mid = int(len(page_items) / 2)
+        for i, item in enumerate(page_items):
+            a_node = item.getElementsByTagName('a')[0]
+            href_link = a_node.getAttribute('href')
+            node_text = get_text(a_node.childNodes)
+            if node_text == str(current_page + 1):
+                if check_middle:
+                    self.assertEqual(mid, i)
+                self.assertEqual('javascript:void(0)', a_node.getAttribute('href'))
+                self.assertIn('active', item.getAttribute('class'))
+            else:
+                link_str = '?page=' + str(int(node_text) - 1)
+                self.assertEqual(link_str, href_link)
+
+    def test_generate_pager_current_start(self):
+        self.check_generate_pages_html(current_page=0,
+                                       total_pages=6)
+
+    def test_generate_pager_current_middle(self):
+        self.check_generate_pages_html(current_page=10,
+                                       total_pages=20,
+                                       check_middle=True)
+
+    def test_generate_pager_current_end(self):
+        self.check_generate_pages_html(current_page=38,
+                                       total_pages=39)
+
+    def test_params_no_values(self):
+        """Should return an empty string if no params are passed"""
+        self.assertEquals('', utils.get_params())
+
+    def test_params_search(self):
+        self.assertEqual('search=bash_',
+                         utils.get_params(search='bash_'))
+
+    def test_params_showPaused_true(self):
+        """Should detect True as default for showPaused"""
+        self.assertEqual('',
+                         utils.get_params(showPaused=True))
+
+    def test_params_showPaused_false(self):
+        self.assertEqual('showPaused=False',
+                         utils.get_params(showPaused=False))
+
+    def test_params_all(self):
+        """Should return params string ordered by param key"""
+        self.assertEqual('page=3&search=bash_&showPaused=False',
+                         utils.get_params(showPaused=False, page=3, search='bash_'))
+
 
 if __name__ == '__main__':
     unittest.main()


Mime
View raw message