Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Dec 24, 2022
1 parent 2f10e2a commit 0b604dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
11 changes: 3 additions & 8 deletions tests/integration_tests/base_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,28 +219,23 @@ def test_get_related_owners(self):
for expected_user in expected_users:
assert expected_user in response_users

def test_get_related_owners_with_query_mutator(self):
def test_get_related_owners_with_extra_filters(self):
"""
API: Test get related owners with query mutator
API: Test get related owners with extra related query filters
"""
self.login(username="admin")

def _base_filter(query):
return query.filter_by(username="alpha")

with patch.dict(
"superset.dashboards.filters.current_app.config",
"superset.views.filters.current_app.config",
{"EXTRA_RELATED_QUERY_FILTERS": {"user": _base_filter}},
):
uri = f"api/v1/{self.resource_name}/related/owners"
rv = self.client.get(uri)
assert rv.status_code == 200
response = json.loads(rv.data.decode("utf-8"))
users = db.session.query(security_manager.user_model).all()
expected_users = [str(user) for user in users]
assert response["count"] == 1
# This needs to be implemented like this, because ordering varies between
# postgres and mysql
response_users = [result["text"] for result in response["result"]]
assert response_users == ["alpha user"]

Expand Down
8 changes: 3 additions & 5 deletions tests/integration_tests/dashboards/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1828,25 +1828,23 @@ def test_get_filter_related_roles(self):
response_roles = [result["text"] for result in response["result"]]
assert "Alpha" in response_roles

def test_get_all_related_roles_with_query_mutator(self):
def test_get_all_related_roles_with_with_extra_filters(self):
"""
API: Test get filter related roles with query mutator
API: Test get filter related roles with extra related query filters
"""
self.login(username="admin")

def _base_filter(query):
return query.filter_by(name="Alpha")

with patch.dict(
"superset.dashboards.filters.current_app.config",
"superset.views.filters.current_app.config",
{"EXTRA_RELATED_QUERY_FILTERS": {"role": _base_filter}},
):
uri = f"api/v1/dashboard/related/roles"
rv = self.client.get(uri)
assert rv.status_code == 200
response = json.loads(rv.data.decode("utf-8"))
assert response["count"] == 1

response_roles = [result["text"] for result in response["result"]]
assert response_roles == ["Alpha"]

Expand Down

0 comments on commit 0b604dd

Please sign in to comment.