Skip to content

Commit

Permalink
add unit tests for merge_extra_form_data
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Feb 13, 2021
1 parent 23592ea commit a71d35b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,8 @@ def merge_extra_form_data(form_data: Dict[str, Any]) -> None:
"druid_time_origin": "__time_origin",
"granularity": "__granularity",
}
applied_time_extras = form_data["applied_time_extras"]
applied_time_extras = form_data.get("applied_time_extras", {})
form_data["applied_time_extras"] = applied_time_extras
extra_form_data = form_data.pop("extra_form_data", {})
append_form_data = extra_form_data.pop("append_form_data", {})
append_filters = append_form_data.get("filters", None)
Expand Down
30 changes: 30 additions & 0 deletions tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
JSONEncodedDict,
memoized,
merge_extra_filters,
merge_extra_form_data,
merge_request_params,
parse_ssl_cert,
parse_js_uri_path_item,
Expand Down Expand Up @@ -902,6 +903,35 @@ def test_build_extra_filters(self):
layout, filter_scopes, default_filters, box_plot.id
) == [{"col": "region", "op": "==", "val": "North America"}]

def test_merge_extra_filters_with_no_extras(self):
form_data = {
"time_range": "Last 10 days",
}
merge_extra_form_data(form_data)
self.assertEqual(
form_data,
{
"time_range": "Last 10 days",
"applied_time_extras": {},
"adhoc_filters": [],
},
)

def test_merge_extra_filters_with_extras(self):
form_data = {
"time_range": "Last 10 days",
"extra_form_data": {
"append_form_data": {
"filters": [{"col": "foo", "op": "IN", "val": "bar"}]
},
"override_form_data": {"time_range": "Last 100 years",},
},
}
merge_extra_form_data(form_data)
assert form_data["applied_time_extras"] == {"__time_range": "Last 100 years"}
assert form_data["time_range"] == "Last 100 years"
assert len(form_data["adhoc_filters"]) == 1

def test_ssl_certificate_parse(self):
parsed_certificate = parse_ssl_cert(ssl_certificate)
self.assertEqual(parsed_certificate.serial_number, 12355228710836649848)
Expand Down

0 comments on commit a71d35b

Please sign in to comment.