mirror of
https://github.com/apache/superset.git
synced 2026-05-11 19:05:24 +00:00
feat: add permalink to dashboard and explore (#19078)
* rename key_value to temporary_cache
* add migration
* create new key_value package
* add commands
* lots of new stuff
* fix schema reference
* remove redundant filter state from bootstrap data
* add missing license headers
* fix pylint
* fix dashboard permalink access
* use valid json mocks for filter state tests
* fix temporary cache tests
* add anchors to dashboard state
* lint
* fix util test
* fix url shortlink button tests
* remove legacy shortner
* remove unused imports
* fix js tests
* fix test
* add native filter state to anchor link
* add UPDATING.md section
* address comments
* address comments
* lint
* fix test
* add utils tests + other test stubs
* add key_value integration tests
* add filter box state to permalink state
* fully support persisting url parameters
* lint, add redirects and a few integration tests
* fix test + clean up trailing comma
* fix anchor bug
* change value to LargeBinary to support persisting binary values
* fix urlParams type and simplify urlencode
* lint
* add optional entry expiration
* fix incorrect chart id + add test
(cherry picked from commit b7a0559aaf)
This commit is contained in:
committed by
Ville Brofeldt
parent
90f4d77422
commit
8c102174b8
@@ -27,21 +27,16 @@ from superset.explore.form_data.commands.state import TemporaryExploreState
|
||||
from superset.extensions import cache_manager
|
||||
from superset.models.slice import Slice
|
||||
from tests.integration_tests.base_tests import login
|
||||
from tests.integration_tests.fixtures.client import client
|
||||
from tests.integration_tests.fixtures.world_bank_dashboard import (
|
||||
load_world_bank_dashboard_with_slices,
|
||||
load_world_bank_data,
|
||||
)
|
||||
from tests.integration_tests.test_app import app
|
||||
|
||||
key = "test-key"
|
||||
form_data = "test"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with app.test_client() as client:
|
||||
with app.app_context():
|
||||
yield client
|
||||
KEY = "test-key"
|
||||
INITIAL_FORM_DATA = json.dumps({"test": "initial value"})
|
||||
UPDATED_FORM_DATA = json.dumps({"test": "updated value"})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -78,9 +73,9 @@ def cache(chart_id, admin_id, dataset_id):
|
||||
"owner": admin_id,
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": form_data,
|
||||
"form_data": INITIAL_FORM_DATA,
|
||||
}
|
||||
cache_manager.explore_form_data_cache.set(key, entry)
|
||||
cache_manager.explore_form_data_cache.set(KEY, entry)
|
||||
|
||||
|
||||
def test_post(client, chart_id: int, dataset_id: int):
|
||||
@@ -88,13 +83,13 @@ def test_post(client, chart_id: int, dataset_id: int):
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": form_data,
|
||||
"form_data": INITIAL_FORM_DATA,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data", json=payload)
|
||||
assert resp.status_code == 201
|
||||
|
||||
|
||||
def test_post_bad_request(client, chart_id: int, dataset_id: int):
|
||||
def test_post_bad_request_non_string(client, chart_id: int, dataset_id: int):
|
||||
login(client, "admin")
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
@@ -105,12 +100,23 @@ def test_post_bad_request(client, chart_id: int, dataset_id: int):
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_post_bad_request_non_json_string(client, chart_id: int, dataset_id: int):
|
||||
login(client, "admin")
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "foo",
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data", json=payload)
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_post_access_denied(client, chart_id: int, dataset_id: int):
|
||||
login(client, "gamma")
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": form_data,
|
||||
"form_data": INITIAL_FORM_DATA,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data", json=payload)
|
||||
assert resp.status_code == 404
|
||||
@@ -121,7 +127,7 @@ def test_post_same_key_for_same_context(client, chart_id: int, dataset_id: int):
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
@@ -139,14 +145,14 @@ def test_post_different_key_for_different_context(
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
first_key = data.get("key")
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": json.dumps({"test": "initial value"}),
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
@@ -159,7 +165,7 @@ def test_post_same_key_for_same_tab_id(client, chart_id: int, dataset_id: int):
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": json.dumps({"test": "initial value"}),
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
@@ -177,7 +183,7 @@ def test_post_different_key_for_different_tab_id(
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": json.dumps({"test": "initial value"}),
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
@@ -193,7 +199,7 @@ def test_post_different_key_for_no_tab_id(client, chart_id: int, dataset_id: int
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": INITIAL_FORM_DATA,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
@@ -209,9 +215,9 @@ def test_put(client, chart_id: int, dataset_id: int):
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{key}", json=payload)
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
@@ -220,12 +226,12 @@ def test_put_same_key_for_same_tab_id(client, chart_id: int, dataset_id: int):
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{key}?tab_id=1", json=payload)
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
first_key = data.get("key")
|
||||
resp = client.put(f"api/v1/explore/form_data/{key}?tab_id=1", json=payload)
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
second_key = data.get("key")
|
||||
assert first_key == second_key
|
||||
@@ -236,12 +242,12 @@ def test_put_different_key_for_different_tab_id(client, chart_id: int, dataset_i
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{key}?tab_id=1", json=payload)
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
first_key = data.get("key")
|
||||
resp = client.put(f"api/v1/explore/form_data/{key}?tab_id=2", json=payload)
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}?tab_id=2", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
second_key = data.get("key")
|
||||
assert first_key != second_key
|
||||
@@ -252,12 +258,12 @@ def test_put_different_key_for_no_tab_id(client, chart_id: int, dataset_id: int)
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{key}", json=payload)
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
first_key = data.get("key")
|
||||
resp = client.put(f"api/v1/explore/form_data/{key}", json=payload)
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
second_key = data.get("key")
|
||||
assert first_key != second_key
|
||||
@@ -270,7 +276,29 @@ def test_put_bad_request(client, chart_id: int, dataset_id: int):
|
||||
"chart_id": chart_id,
|
||||
"form_data": 1234,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{key}", json=payload)
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_put_bad_request_non_string(client, chart_id: int, dataset_id: int):
|
||||
login(client, "admin")
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": 1234,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_put_bad_request_non_json_string(client, chart_id: int, dataset_id: int):
|
||||
login(client, "admin")
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "foo",
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@@ -279,9 +307,9 @@ def test_put_access_denied(client, chart_id: int, dataset_id: int):
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{key}", json=payload)
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@@ -290,9 +318,9 @@ def test_put_not_owner(client, chart_id: int, dataset_id: int):
|
||||
payload = {
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "new form_data",
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{key}", json=payload)
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@@ -304,15 +332,15 @@ def test_get_key_not_found(client):
|
||||
|
||||
def test_get(client):
|
||||
login(client, "admin")
|
||||
resp = client.get(f"api/v1/explore/form_data/{key}")
|
||||
resp = client.get(f"api/v1/explore/form_data/{KEY}")
|
||||
assert resp.status_code == 200
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
assert form_data == data.get("form_data")
|
||||
assert INITIAL_FORM_DATA == data.get("form_data")
|
||||
|
||||
|
||||
def test_get_access_denied(client):
|
||||
login(client, "gamma")
|
||||
resp = client.get(f"api/v1/explore/form_data/{key}")
|
||||
resp = client.get(f"api/v1/explore/form_data/{KEY}")
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@@ -320,19 +348,19 @@ def test_get_access_denied(client):
|
||||
def test_get_dataset_access_denied(mock_can_access_datasource, client):
|
||||
mock_can_access_datasource.side_effect = DatasetAccessDeniedError()
|
||||
login(client, "admin")
|
||||
resp = client.get(f"api/v1/explore/form_data/{key}")
|
||||
resp = client.get(f"api/v1/explore/form_data/{KEY}")
|
||||
assert resp.status_code == 403
|
||||
|
||||
|
||||
def test_delete(client):
|
||||
login(client, "admin")
|
||||
resp = client.delete(f"api/v1/explore/form_data/{key}")
|
||||
resp = client.delete(f"api/v1/explore/form_data/{KEY}")
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
def test_delete_access_denied(client):
|
||||
login(client, "gamma")
|
||||
resp = client.delete(f"api/v1/explore/form_data/{key}")
|
||||
resp = client.delete(f"api/v1/explore/form_data/{KEY}")
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@@ -343,7 +371,7 @@ def test_delete_not_owner(client, chart_id: int, dataset_id: int, admin_id: int)
|
||||
"owner": another_owner,
|
||||
"dataset_id": dataset_id,
|
||||
"chart_id": chart_id,
|
||||
"form_data": form_data,
|
||||
"form_data": INITIAL_FORM_DATA,
|
||||
}
|
||||
cache_manager.explore_form_data_cache.set(another_key, entry)
|
||||
login(client, "admin")
|
||||
|
||||
Reference in New Issue
Block a user