Skip to content

Commit

Permalink
fix: saved_query search on schema and database not working (apache#11286
Browse files Browse the repository at this point in the history
)

* fix: saved_query search on schema and database not working

* add tests
  • Loading branch information
dpgaspar authored and auxten committed Nov 20, 2020
1 parent 6928588 commit 72065e5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion superset/queries/saved_queries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class SavedQueryRestApi(BaseSupersetModelRestApi):
"changed_on_delta_humanized",
]

search_columns = ["id", "label"]
search_columns = ["id", "database", "label", "schema"]
search_filters = {
"id": [SavedQueryFavoriteFilter],
"label": [SavedQueryAllTextFilter],
Expand Down
50 changes: 50 additions & 0 deletions tests/queries/saved_queries/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,56 @@ def test_get_list_filter_saved_query(self):
data = json.loads(rv.data.decode("utf-8"))
assert data["count"] == len(all_queries)

@pytest.mark.usefixtures("create_saved_queries")
def test_get_list_filter_database_saved_query(self):
"""
Saved Query API: Test get list and database saved query
"""
example_db = get_example_database()
admin_user = self.get_user("admin")

all_db_queries = (
db.session.query(SavedQuery)
.filter(SavedQuery.db_id == example_db.id)
.filter(SavedQuery.created_by_fk == admin_user.id)
.all()
)

self.login(username="admin")
query_string = {
"filters": [{"col": "database", "opr": "rel_o_m", "value": example_db.id}],
}
uri = f"api/v1/saved_query/?q={prison.dumps(query_string)}"
rv = self.get_assert_metric(uri, "get_list")
assert rv.status_code == 200
data = json.loads(rv.data.decode("utf-8"))
assert data["count"] == len(all_db_queries)

@pytest.mark.usefixtures("create_saved_queries")
def test_get_list_filter_schema_saved_query(self):
"""
Saved Query API: Test get list and schema saved query
"""
schema_name = "schema1"
admin_user = self.get_user("admin")

all_db_queries = (
db.session.query(SavedQuery)
.filter(SavedQuery.schema == schema_name)
.filter(SavedQuery.created_by_fk == admin_user.id)
.all()
)

self.login(username="admin")
query_string = {
"filters": [{"col": "schema", "opr": "eq", "value": schema_name}],
}
uri = f"api/v1/saved_query/?q={prison.dumps(query_string)}"
rv = self.get_assert_metric(uri, "get_list")
assert rv.status_code == 200
data = json.loads(rv.data.decode("utf-8"))
assert data["count"] == len(all_db_queries)

@pytest.mark.usefixtures("create_saved_queries")
def test_get_list_custom_filter_schema_saved_query(self):
"""
Expand Down

0 comments on commit 72065e5

Please sign in to comment.