mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
refactor(test): add login_as_admin in global conftest (#20703)
This commit is contained in:
@@ -26,8 +26,6 @@ from superset.explore.exceptions import DatasetAccessDeniedError
|
||||
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,
|
||||
@@ -101,9 +99,8 @@ def assert_slice(result, chart_id, dataset_id):
|
||||
assert slice["form_data"]["viz_type"] == "big_number"
|
||||
|
||||
|
||||
def test_no_params_provided(client):
|
||||
login(client, "admin")
|
||||
resp = client.get(f"api/v1/explore/")
|
||||
def test_no_params_provided(test_client, login_as_admin):
|
||||
resp = test_client.get(f"api/v1/explore/")
|
||||
assert resp.status_code == 200
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
result = data.get("result")
|
||||
@@ -113,9 +110,8 @@ def test_no_params_provided(client):
|
||||
assert result["slice"] == None
|
||||
|
||||
|
||||
def test_get_from_cache(client, dataset):
|
||||
login(client, "admin")
|
||||
resp = client.get(
|
||||
def test_get_from_cache(test_client, login_as_admin, dataset):
|
||||
resp = test_client.get(
|
||||
f"api/v1/explore/?form_data_key={FORM_DATA_KEY}&dataset_id={dataset.id}&dataset_type={dataset.type}"
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
@@ -128,10 +124,11 @@ def test_get_from_cache(client, dataset):
|
||||
assert result["slice"] == None
|
||||
|
||||
|
||||
def test_get_from_cache_unknown_key_chart_id(client, chart_id, dataset):
|
||||
login(client, "admin")
|
||||
def test_get_from_cache_unknown_key_chart_id(
|
||||
test_client, login_as_admin, chart_id, dataset
|
||||
):
|
||||
unknown_key = "unknown_key"
|
||||
resp = client.get(
|
||||
resp = test_client.get(
|
||||
f"api/v1/explore/?form_data_key={unknown_key}&slice_id={chart_id}"
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
@@ -146,10 +143,9 @@ def test_get_from_cache_unknown_key_chart_id(client, chart_id, dataset):
|
||||
)
|
||||
|
||||
|
||||
def test_get_from_cache_unknown_key_dataset(client, dataset):
|
||||
login(client, "admin")
|
||||
def test_get_from_cache_unknown_key_dataset(test_client, login_as_admin, dataset):
|
||||
unknown_key = "unknown_key"
|
||||
resp = client.get(
|
||||
resp = test_client.get(
|
||||
f"api/v1/explore/?form_data_key={unknown_key}&dataset_id={dataset.id}&dataset_type={dataset.type}"
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
@@ -164,10 +160,9 @@ def test_get_from_cache_unknown_key_dataset(client, dataset):
|
||||
assert result["slice"] == None
|
||||
|
||||
|
||||
def test_get_from_cache_unknown_key_no_extra_parameters(client):
|
||||
login(client, "admin")
|
||||
def test_get_from_cache_unknown_key_no_extra_parameters(test_client, login_as_admin):
|
||||
unknown_key = "unknown_key"
|
||||
resp = client.get(f"api/v1/explore/?form_data_key={unknown_key}")
|
||||
resp = test_client.get(f"api/v1/explore/?form_data_key={unknown_key}")
|
||||
assert resp.status_code == 200
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
result = data.get("result")
|
||||
@@ -177,17 +172,16 @@ def test_get_from_cache_unknown_key_no_extra_parameters(client):
|
||||
assert result["slice"] == None
|
||||
|
||||
|
||||
def test_get_from_permalink(client, chart_id, dataset):
|
||||
login(client, "admin")
|
||||
def test_get_from_permalink(test_client, login_as_admin, chart_id, dataset):
|
||||
form_data = {
|
||||
"chart_id": chart_id,
|
||||
"datasource": f"{dataset.id}__{dataset.type}",
|
||||
**FORM_DATA,
|
||||
}
|
||||
resp = client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
permalink_key = data["key"]
|
||||
resp = client.get(f"api/v1/explore/?permalink_key={permalink_key}")
|
||||
resp = test_client.get(f"api/v1/explore/?permalink_key={permalink_key}")
|
||||
assert resp.status_code == 200
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
result = data.get("result")
|
||||
@@ -198,21 +192,21 @@ def test_get_from_permalink(client, chart_id, dataset):
|
||||
assert result["slice"] == None
|
||||
|
||||
|
||||
def test_get_from_permalink_unknown_key(client):
|
||||
login(client, "admin")
|
||||
def test_get_from_permalink_unknown_key(test_client, login_as_admin):
|
||||
unknown_key = "unknown_key"
|
||||
resp = client.get(f"api/v1/explore/?permalink_key={unknown_key}")
|
||||
resp = test_client.get(f"api/v1/explore/?permalink_key={unknown_key}")
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@patch("superset.security.SupersetSecurityManager.can_access_datasource")
|
||||
def test_get_dataset_access_denied(mock_can_access_datasource, client, dataset):
|
||||
def test_get_dataset_access_denied(
|
||||
mock_can_access_datasource, test_client, login_as_admin, dataset
|
||||
):
|
||||
message = "Dataset access denied"
|
||||
mock_can_access_datasource.side_effect = DatasetAccessDeniedError(
|
||||
message=message, dataset_id=dataset.id, dataset_type=dataset.type
|
||||
)
|
||||
login(client, "admin")
|
||||
resp = client.get(
|
||||
resp = test_client.get(
|
||||
f"api/v1/explore/?form_data_key={FORM_DATA_KEY}&dataset_id={dataset.id}&dataset_type={dataset.type}"
|
||||
)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
@@ -223,11 +217,10 @@ def test_get_dataset_access_denied(mock_can_access_datasource, client, dataset):
|
||||
|
||||
|
||||
@patch("superset.datasource.dao.DatasourceDAO.get_datasource")
|
||||
def test_wrong_endpoint(mock_get_datasource, client, dataset):
|
||||
def test_wrong_endpoint(mock_get_datasource, test_client, login_as_admin, dataset):
|
||||
dataset.default_endpoint = "another_endpoint"
|
||||
mock_get_datasource.return_value = dataset
|
||||
login(client, "admin")
|
||||
resp = client.get(
|
||||
resp = test_client.get(
|
||||
f"api/v1/explore/?dataset_id={dataset.id}&dataset_type={dataset.type}"
|
||||
)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
|
||||
@@ -27,8 +27,6 @@ from superset.explore.form_data.commands.state import TemporaryExploreState
|
||||
from superset.extensions import cache_manager
|
||||
from superset.models.slice import Slice
|
||||
from superset.utils.core import DatasourceType
|
||||
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,
|
||||
@@ -80,82 +78,85 @@ def cache(chart_id, admin_id, datasource):
|
||||
cache_manager.explore_form_data_cache.set(KEY, entry)
|
||||
|
||||
|
||||
def test_post(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_post(test_client, login_as_admin, chart_id: int, datasource: SqlaTable):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": INITIAL_FORM_DATA,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data", json=payload)
|
||||
resp = test_client.post("api/v1/explore/form_data", json=payload)
|
||||
assert resp.status_code == 201
|
||||
|
||||
|
||||
def test_post_bad_request_non_string(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_post_bad_request_non_string(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": 1234,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data", json=payload)
|
||||
resp = test_client.post("api/v1/explore/form_data", json=payload)
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_post_bad_request_non_json_string(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_post_bad_request_non_json_string(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "foo",
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data", json=payload)
|
||||
resp = test_client.post("api/v1/explore/form_data", json=payload)
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_post_access_denied(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "gamma")
|
||||
def test_post_access_denied(
|
||||
test_client, login_as, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
login_as("gamma")
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": INITIAL_FORM_DATA,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data", json=payload)
|
||||
resp = test_client.post("api/v1/explore/form_data", json=payload)
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
def test_post_same_key_for_same_context(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_post_same_key_for_same_context(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
resp = test_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")
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
resp = test_client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
second_key = data.get("key")
|
||||
assert first_key == second_key
|
||||
|
||||
|
||||
def test_post_different_key_for_different_context(
|
||||
client, chart_id: int, datasource: SqlaTable
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
login(client, "admin")
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
resp = test_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 = {
|
||||
@@ -163,231 +164,235 @@ def test_post_different_key_for_different_context(
|
||||
"datasource_type": datasource.type,
|
||||
"form_data": json.dumps({"test": "initial value"}),
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
resp = test_client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
second_key = data.get("key")
|
||||
assert first_key != second_key
|
||||
|
||||
|
||||
def test_post_same_key_for_same_tab_id(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_post_same_key_for_same_tab_id(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": json.dumps({"test": "initial value"}),
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
resp = test_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")
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
resp = test_client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
second_key = data.get("key")
|
||||
assert first_key == second_key
|
||||
|
||||
|
||||
def test_post_different_key_for_different_tab_id(
|
||||
client, chart_id: int, datasource: SqlaTable
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
login(client, "admin")
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": json.dumps({"test": "initial value"}),
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload)
|
||||
resp = test_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")
|
||||
resp = client.post("api/v1/explore/form_data?tab_id=2", json=payload)
|
||||
resp = test_client.post("api/v1/explore/form_data?tab_id=2", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
second_key = data.get("key")
|
||||
assert first_key != second_key
|
||||
|
||||
|
||||
def test_post_different_key_for_no_tab_id(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_post_different_key_for_no_tab_id(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": INITIAL_FORM_DATA,
|
||||
}
|
||||
resp = client.post("api/v1/explore/form_data", json=payload)
|
||||
resp = test_client.post("api/v1/explore/form_data", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
first_key = data.get("key")
|
||||
resp = client.post("api/v1/explore/form_data", json=payload)
|
||||
resp = test_client.post("api/v1/explore/form_data", json=payload)
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
second_key = data.get("key")
|
||||
assert first_key != second_key
|
||||
|
||||
|
||||
def test_put(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_put(test_client, login_as_admin, chart_id: int, datasource: SqlaTable):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
resp = test_client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
def test_put_same_key_for_same_tab_id(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_put_same_key_for_same_tab_id(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}?tab_id=1", json=payload)
|
||||
resp = test_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 = test_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
|
||||
|
||||
|
||||
def test_put_different_key_for_different_tab_id(
|
||||
client, chart_id: int, datasource: SqlaTable
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
login(client, "admin")
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}?tab_id=1", json=payload)
|
||||
resp = test_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 = test_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
|
||||
|
||||
|
||||
def test_put_different_key_for_no_tab_id(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_put_different_key_for_no_tab_id(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
resp = test_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 = test_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
|
||||
|
||||
|
||||
def test_put_bad_request(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_put_bad_request(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": 1234,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
resp = test_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, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_put_bad_request_non_string(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": 1234,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
resp = test_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, datasource: SqlaTable):
|
||||
login(client, "admin")
|
||||
def test_put_bad_request_non_json_string(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable
|
||||
):
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": "foo",
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
resp = test_client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_put_access_denied(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "gamma")
|
||||
def test_put_access_denied(test_client, login_as, chart_id: int, datasource: SqlaTable):
|
||||
login_as("gamma")
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
resp = test_client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
def test_put_not_owner(client, chart_id: int, datasource: SqlaTable):
|
||||
login(client, "gamma")
|
||||
def test_put_not_owner(test_client, login_as, chart_id: int, datasource: SqlaTable):
|
||||
login_as("gamma")
|
||||
payload = {
|
||||
"datasource_id": datasource.id,
|
||||
"datasource_type": datasource.type,
|
||||
"chart_id": chart_id,
|
||||
"form_data": UPDATED_FORM_DATA,
|
||||
}
|
||||
resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
resp = test_client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
def test_get_key_not_found(client):
|
||||
login(client, "admin")
|
||||
resp = client.get(f"api/v1/explore/form_data/unknown-key")
|
||||
def test_get_key_not_found(test_client, login_as_admin):
|
||||
resp = test_client.get(f"api/v1/explore/form_data/unknown-key")
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
def test_get(client):
|
||||
login(client, "admin")
|
||||
resp = client.get(f"api/v1/explore/form_data/{KEY}")
|
||||
def test_get(test_client, login_as_admin):
|
||||
resp = test_client.get(f"api/v1/explore/form_data/{KEY}")
|
||||
assert resp.status_code == 200
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
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}")
|
||||
def test_get_access_denied(test_client, login_as):
|
||||
login_as("gamma")
|
||||
resp = test_client.get(f"api/v1/explore/form_data/{KEY}")
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@patch("superset.security.SupersetSecurityManager.can_access_datasource")
|
||||
def test_get_dataset_access_denied(mock_can_access_datasource, client):
|
||||
def test_get_dataset_access_denied(
|
||||
mock_can_access_datasource, test_client, login_as_admin
|
||||
):
|
||||
mock_can_access_datasource.side_effect = DatasetAccessDeniedError()
|
||||
login(client, "admin")
|
||||
resp = client.get(f"api/v1/explore/form_data/{KEY}")
|
||||
resp = test_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}")
|
||||
def test_delete(test_client, login_as_admin):
|
||||
resp = test_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}")
|
||||
def test_delete_access_denied(test_client, login_as):
|
||||
login_as("gamma")
|
||||
resp = test_client.delete(f"api/v1/explore/form_data/{KEY}")
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
def test_delete_not_owner(client, chart_id: int, datasource: SqlaTable, admin_id: int):
|
||||
def test_delete_not_owner(
|
||||
test_client, login_as_admin, chart_id: int, datasource: SqlaTable, admin_id: int
|
||||
):
|
||||
another_key = "another_key"
|
||||
another_owner = admin_id + 1
|
||||
entry: TemporaryExploreState = {
|
||||
@@ -398,6 +403,5 @@ def test_delete_not_owner(client, chart_id: int, datasource: SqlaTable, admin_id
|
||||
"form_data": INITIAL_FORM_DATA,
|
||||
}
|
||||
cache_manager.explore_form_data_cache.set(another_key, entry)
|
||||
login(client, "admin")
|
||||
resp = client.delete(f"api/v1/explore/form_data/{another_key}")
|
||||
resp = test_client.delete(f"api/v1/explore/form_data/{another_key}")
|
||||
assert resp.status_code == 403
|
||||
|
||||
@@ -28,8 +28,6 @@ from superset.key_value.types import KeyValueResource
|
||||
from superset.key_value.utils import decode_permalink_id, encode_permalink_key
|
||||
from superset.models.slice import Slice
|
||||
from superset.utils.core import DatasourceType
|
||||
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,
|
||||
@@ -38,11 +36,10 @@ from tests.integration_tests.test_app import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chart(load_world_bank_dashboard_with_slices) -> Slice:
|
||||
with app.app_context() as ctx:
|
||||
session: Session = ctx.app.appbuilder.get_session
|
||||
chart = session.query(Slice).filter_by(slice_name="World's Population").one()
|
||||
return chart
|
||||
def chart(app_context, load_world_bank_dashboard_with_slices) -> Slice:
|
||||
session: Session = app_context.app.appbuilder.get_session
|
||||
chart = session.query(Slice).filter_by(slice_name="World's Population").one()
|
||||
return chart
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -70,9 +67,10 @@ def permalink_salt() -> Iterator[str]:
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def test_post(client, form_data: Dict[str, Any], permalink_salt: str):
|
||||
login(client, "admin")
|
||||
resp = client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
def test_post(
|
||||
test_client, login_as_admin, form_data: Dict[str, Any], permalink_salt: str
|
||||
):
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
assert resp.status_code == 201
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
key = data["key"]
|
||||
@@ -83,13 +81,15 @@ def test_post(client, form_data: Dict[str, Any], permalink_salt: str):
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def test_post_access_denied(client, form_data):
|
||||
login(client, "gamma")
|
||||
resp = client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
def test_post_access_denied(test_client, login_as, form_data):
|
||||
login_as("gamma")
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
def test_get_missing_chart(client, chart, permalink_salt: str) -> None:
|
||||
def test_get_missing_chart(
|
||||
test_client, login_as_admin, chart, permalink_salt: str
|
||||
) -> None:
|
||||
from superset.key_value.models import KeyValueEntry
|
||||
|
||||
chart_id = 1234
|
||||
@@ -110,25 +110,24 @@ def test_get_missing_chart(client, chart, permalink_salt: str) -> None:
|
||||
db.session.add(entry)
|
||||
db.session.commit()
|
||||
key = encode_permalink_key(entry.id, permalink_salt)
|
||||
login(client, "admin")
|
||||
resp = client.get(f"api/v1/explore/permalink/{key}")
|
||||
resp = test_client.get(f"api/v1/explore/permalink/{key}")
|
||||
assert resp.status_code == 404
|
||||
db.session.delete(entry)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def test_post_invalid_schema(client) -> None:
|
||||
login(client, "admin")
|
||||
resp = client.post(f"api/v1/explore/permalink", json={"abc": 123})
|
||||
def test_post_invalid_schema(test_client, login_as_admin) -> None:
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"abc": 123})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_get(client, form_data: Dict[str, Any], permalink_salt: str) -> None:
|
||||
login(client, "admin")
|
||||
resp = client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
def test_get(
|
||||
test_client, login_as_admin, form_data: Dict[str, Any], permalink_salt: str
|
||||
) -> None:
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
key = data["key"]
|
||||
resp = client.get(f"api/v1/explore/permalink/{key}")
|
||||
resp = test_client.get(f"api/v1/explore/permalink/{key}")
|
||||
assert resp.status_code == 200
|
||||
result = json.loads(resp.data.decode("utf-8"))
|
||||
assert result["state"]["formData"] == form_data
|
||||
|
||||
Reference in New Issue
Block a user