From 0f350adaf461111d5ef0883ff95c3a9fed76a63f Mon Sep 17 00:00:00 2001 From: Grace Guo Date: Fri, 2 Mar 2018 13:48:55 -0800 Subject: [PATCH] add unit test --- superset/utils.py | 7 +++++++ superset/views/core.py | 10 ++++------ tests/utils_tests.py | 16 +++++++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/superset/utils.py b/superset/utils.py index c60f128d0e603..639045970d796 100644 --- a/superset/utils.py +++ b/superset/utils.py @@ -835,6 +835,13 @@ def get_filter_key(f): del form_data['extra_filters'] +def merge_request_params(form_data, params): + for key, value in params.items(): + if key == 'form_data': + continue + form_data[key] = value + + def get_update_perms_flag(): val = os.environ.get('SUPERSET_UPDATE_PERMS') return val.lower() not in ('0', 'false', 'no') if val else True diff --git a/superset/views/core.py b/superset/views/core.py index 9e0aa358b574a..4330e7d7eea41 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -43,7 +43,9 @@ import superset.models.core as models from superset.models.sql_lab import Query from superset.sql_parse import SupersetQuery -from superset.utils import has_access, merge_extra_filters, QueryStatus +from superset.utils import ( + has_access, merge_extra_filters, merge_request_params, QueryStatus, +) from .base import ( api, BaseSupersetView, CsvResponse, DeleteMixin, generate_download_headers, get_error_msg, get_user_roles, @@ -1257,11 +1259,7 @@ def explore(self, datasource_type=None, datasource_id=None): # merge request url params if request.method == 'GET': - url_params = request.args - for key, value in url_params.items(): - if key == 'form_data': - continue - form_data[key] = value + merge_request_params(form_data, request.args) # handle save or overwrite action = request.args.get('action') diff --git a/tests/utils_tests.py b/tests/utils_tests.py index 172818964f684..000079491a512 100644 --- a/tests/utils_tests.py +++ b/tests/utils_tests.py @@ -14,7 +14,8 @@ from superset.utils import ( base_json_conv, datetime_f, json_int_dttm_ser, json_iso_dttm_ser, - JSONEncodedDict, memoized, merge_extra_filters, parse_human_timedelta, + JSONEncodedDict, memoized, merge_extra_filters, merge_request_params, + parse_human_timedelta, SupersetException, validate_json, zlib_compress, zlib_decompress_to_string, ) @@ -216,6 +217,19 @@ def test_merge_extra_filters_adds_unequal_lists(self): merge_extra_filters(form_data) self.assertEquals(form_data, expected) + def test_merge_request_params(self): + form_data = { + 'since': '2000', + 'until': 'now', + } + url_params = { + 'form_data': form_data, + 'dashboard_ids': '(1,2,3,4,5)', + } + merge_request_params(form_data, url_params) + self.assertIn('dashboard_ids', form_data.keys()) + self.assertNotIn('form_data', form_data.keys()) + def test_datetime_f(self): self.assertEquals( datetime_f(datetime(1990, 9, 21, 19, 11, 19, 626096)),