mirror of
https://github.com/apache/superset.git
synced 2026-04-21 00:54:44 +00:00
refactor(test): add login_as_admin in global conftest (#20703)
This commit is contained in:
@@ -29,8 +29,6 @@ from superset.key_value.models import KeyValueEntry
|
||||
from superset.key_value.types import KeyValueResource
|
||||
from superset.key_value.utils import decode_permalink_id
|
||||
from superset.models.dashboard import Dashboard
|
||||
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,
|
||||
@@ -67,9 +65,10 @@ def permalink_salt() -> Iterator[str]:
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def test_post(client, dashboard_id: int, permalink_salt: str) -> None:
|
||||
login(client, "admin")
|
||||
resp = client.post(f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE)
|
||||
def test_post(
|
||||
test_client, login_as_admin, dashboard_id: int, permalink_salt: str
|
||||
) -> None:
|
||||
resp = test_client.post(f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE)
|
||||
assert resp.status_code == 201
|
||||
data = resp.json
|
||||
key = data["key"]
|
||||
@@ -79,7 +78,9 @@ def test_post(client, dashboard_id: int, permalink_salt: str) -> None:
|
||||
|
||||
assert (
|
||||
data
|
||||
== client.post(f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE).json
|
||||
== test_client.post(
|
||||
f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE
|
||||
).json
|
||||
), "Should always return the same permalink key for the same payload"
|
||||
|
||||
db.session.query(KeyValueEntry).filter_by(id=id_).delete()
|
||||
@@ -87,27 +88,26 @@ def test_post(client, dashboard_id: int, permalink_salt: str) -> None:
|
||||
|
||||
|
||||
@patch("superset.security.SupersetSecurityManager.raise_for_dashboard_access")
|
||||
def test_post_access_denied(mock_raise_for_dashboard_access, client, dashboard_id: int):
|
||||
login(client, "admin")
|
||||
def test_post_access_denied(
|
||||
mock_raise_for_dashboard_access, test_client, login_as_admin, dashboard_id: int
|
||||
):
|
||||
mock_raise_for_dashboard_access.side_effect = DashboardAccessDeniedError()
|
||||
resp = client.post(f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE)
|
||||
resp = test_client.post(f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE)
|
||||
assert resp.status_code == 403
|
||||
|
||||
|
||||
def test_post_invalid_schema(client, dashboard_id: int):
|
||||
login(client, "admin")
|
||||
resp = client.post(
|
||||
def test_post_invalid_schema(test_client, login_as_admin, dashboard_id: int):
|
||||
resp = test_client.post(
|
||||
f"api/v1/dashboard/{dashboard_id}/permalink", json={"foo": "bar"}
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_get(client, dashboard_id: int, permalink_salt: str):
|
||||
login(client, "admin")
|
||||
key = client.post(f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE).json[
|
||||
"key"
|
||||
]
|
||||
resp = client.get(f"api/v1/dashboard/permalink/{key}")
|
||||
def test_get(test_client, login_as_admin, dashboard_id: int, permalink_salt: str):
|
||||
key = test_client.post(
|
||||
f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE
|
||||
).json["key"]
|
||||
resp = test_client.get(f"api/v1/dashboard/permalink/{key}")
|
||||
assert resp.status_code == 200
|
||||
result = resp.json
|
||||
assert result["dashboardId"] == str(dashboard_id)
|
||||
|
||||
Reference in New Issue
Block a user