forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a new macro to allow getting filter values easily (apache#5547)
* Adds new macro to get filter values from "filters" and "extra_filters" Adds test for filter_values macro Adds doco for filter_values Changes filter_values return type to be a list rather than string * Makes return value type consistent - filter_values always return a list
- Loading branch information
1 parent
0e93a94
commit 041fe52
Showing
3 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
from flask import json | ||
from tests.base_tests import SupersetTestCase | ||
|
||
from superset import app | ||
from superset import jinja_context | ||
|
||
|
||
class MacroTestCase(SupersetTestCase): | ||
|
||
def test_filter_values_macro(self): | ||
form_data1 = { | ||
'extra_filters': [ | ||
{'col': 'my_special_filter', 'op': 'in', 'val': ['foo']}, | ||
], | ||
'filters': [ | ||
{'col': 'my_special_filter2', 'op': 'in', 'val': ['bar']}, | ||
], | ||
} | ||
|
||
form_data2 = { | ||
'extra_filters': [ | ||
{'col': 'my_special_filter', 'op': 'in', 'val': ['foo', 'bar']}, | ||
], | ||
} | ||
|
||
form_data3 = { | ||
'extra_filters': [ | ||
{'col': 'my_special_filter', 'op': 'in', 'val': ['foo', 'bar']}, | ||
], | ||
'filters': [ | ||
{'col': 'my_special_filter', 'op': 'in', 'val': ['savage']}, | ||
], | ||
} | ||
|
||
data1 = {'form_data': json.dumps(form_data1)} | ||
data2 = {'form_data': json.dumps(form_data2)} | ||
data3 = {'form_data': json.dumps(form_data3)} | ||
|
||
with app.test_request_context(data=data1): | ||
filter_values = jinja_context.filter_values('my_special_filter') | ||
self.assertEqual(filter_values, ['foo']) | ||
|
||
filter_values = jinja_context.filter_values('my_special_filter2') | ||
self.assertEqual(filter_values, ['bar']) | ||
|
||
filter_values = jinja_context.filter_values('') | ||
self.assertEqual(filter_values, []) | ||
|
||
with app.test_request_context(data=data2): | ||
filter_values = jinja_context.filter_values('my_special_filter') | ||
self.assertEqual(filter_values, ['foo', 'bar']) | ||
|
||
with app.test_request_context(data=data3): | ||
filter_values = jinja_context.filter_values('my_special_filter') | ||
self.assertEqual(filter_values, ['savage', 'foo', 'bar']) | ||
|
||
with app.test_request_context(): | ||
filter_values = jinja_context.filter_values('nonexistent_filter', 'foo') | ||
self.assertEqual(filter_values, ['foo']) |