Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace Guo committed Mar 8, 2018
1 parent bd9ecbe commit 0f350ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
7 changes: 7 additions & 0 deletions superset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 4 additions & 6 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand Down
16 changes: 15 additions & 1 deletion tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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)),
Expand Down

0 comments on commit 0f350ad

Please sign in to comment.