Skip to content

Commit

Permalink
[AIRFLOW-5387] Fix show paused pagination bug (apache#6100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Rojas authored and feluelle committed Oct 8, 2019
1 parent ec8dd34 commit 93bb5e4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
17 changes: 15 additions & 2 deletions airflow/www/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,26 @@ def should_hide_value_for_key(key_name):


def get_params(**kwargs):
hide_paused_dags_by_default = conf.getboolean('webserver',
'hide_paused_dags_by_default')
if 'showPaused' in kwargs:
v = kwargs['showPaused']
if v or v is None:
show_paused_dags_url_param = kwargs['showPaused']
if _should_remove_show_paused_from_url_params(
show_paused_dags_url_param,
hide_paused_dags_by_default
):
kwargs.pop('showPaused')
return urlencode({d: v if v is not None else '' for d, v in kwargs.items()})


def _should_remove_show_paused_from_url_params(show_paused_dags_url_param,
hide_paused_dags_by_default):
return any([
show_paused_dags_url_param != hide_paused_dags_by_default,
show_paused_dags_url_param is None
])


def generate_pages(current_page, num_of_pages,
search=None, showPaused=None, window=7):
"""
Expand Down
42 changes: 34 additions & 8 deletions tests/www/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
from urllib.parse import parse_qs

from bs4 import BeautifulSoup
from parameterized import parameterized

from airflow.www import utils
from tests.test_utils.config import conf_vars


class TestUtils(unittest.TestCase):
Expand Down Expand Up @@ -103,14 +105,38 @@ 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))
@parameterized.expand([
(True, False, ''),
(False, True, ''),
(True, True, 'showPaused=True'),
(False, False, 'showPaused=False'),
(None, True, ''),
(None, False, ''),
])
def test_params_showPaused(self, show_paused, hide_by_default, expected_result):
with conf_vars({('webserver', 'hide_paused_dags_by_default'): str(hide_by_default)}):
self.assertEqual(expected_result,
utils.get_params(showPaused=show_paused))

@parameterized.expand([
(True, False, True),
(False, True, True),
(True, True, False),
(False, False, False),
(None, True, True),
(None, False, True),
])
def test_should_remove_show_paused_from_url_params(self, show_paused,
hide_by_default, expected_result):
with conf_vars({('webserver', 'hide_paused_dags_by_default'): str(hide_by_default)}):

self.assertEqual(
expected_result,
utils._should_remove_show_paused_from_url_params(
show_paused,
hide_by_default
)
)

def test_params_none_and_zero(self):
qs = utils.get_params(a=0, b=None)
Expand Down

0 comments on commit 93bb5e4

Please sign in to comment.