mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
fix: Refactor ownership checks and ensure consistency (#20499)
Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
@@ -23,6 +23,7 @@ from flask.ctx import AppContext
|
||||
from flask_appbuilder.security.sqla.models import User
|
||||
|
||||
from superset.extensions import db
|
||||
from superset.utils.core import override_user
|
||||
from tests.integration_tests.key_value.commands.fixtures import (
|
||||
admin,
|
||||
ID_KEY,
|
||||
@@ -36,19 +37,23 @@ def test_create_id_entry(app_context: AppContext, admin: User) -> None:
|
||||
from superset.key_value.commands.create import CreateKeyValueCommand
|
||||
from superset.key_value.models import KeyValueEntry
|
||||
|
||||
key = CreateKeyValueCommand(actor=admin, resource=RESOURCE, value=VALUE).run()
|
||||
entry = db.session.query(KeyValueEntry).filter_by(id=key.id).autoflush(False).one()
|
||||
assert pickle.loads(entry.value) == VALUE
|
||||
assert entry.created_by_fk == admin.id
|
||||
db.session.delete(entry)
|
||||
db.session.commit()
|
||||
with override_user(admin):
|
||||
key = CreateKeyValueCommand(resource=RESOURCE, value=VALUE).run()
|
||||
entry = (
|
||||
db.session.query(KeyValueEntry).filter_by(id=key.id).autoflush(False).one()
|
||||
)
|
||||
assert pickle.loads(entry.value) == VALUE
|
||||
assert entry.created_by_fk == admin.id
|
||||
db.session.delete(entry)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def test_create_uuid_entry(app_context: AppContext, admin: User) -> None:
|
||||
from superset.key_value.commands.create import CreateKeyValueCommand
|
||||
from superset.key_value.models import KeyValueEntry
|
||||
|
||||
key = CreateKeyValueCommand(actor=admin, resource=RESOURCE, value=VALUE).run()
|
||||
with override_user(admin):
|
||||
key = CreateKeyValueCommand(resource=RESOURCE, value=VALUE).run()
|
||||
entry = (
|
||||
db.session.query(KeyValueEntry).filter_by(uuid=key.uuid).autoflush(False).one()
|
||||
)
|
||||
|
||||
@@ -24,6 +24,7 @@ from flask.ctx import AppContext
|
||||
from flask_appbuilder.security.sqla.models import User
|
||||
|
||||
from superset.extensions import db
|
||||
from superset.utils.core import override_user
|
||||
from tests.integration_tests.key_value.commands.fixtures import (
|
||||
admin,
|
||||
ID_KEY,
|
||||
@@ -47,12 +48,12 @@ def test_update_id_entry(
|
||||
from superset.key_value.commands.update import UpdateKeyValueCommand
|
||||
from superset.key_value.models import KeyValueEntry
|
||||
|
||||
key = UpdateKeyValueCommand(
|
||||
actor=admin,
|
||||
resource=RESOURCE,
|
||||
key=ID_KEY,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
with override_user(admin):
|
||||
key = UpdateKeyValueCommand(
|
||||
resource=RESOURCE,
|
||||
key=ID_KEY,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
assert key is not None
|
||||
assert key.id == ID_KEY
|
||||
entry = db.session.query(KeyValueEntry).filter_by(id=ID_KEY).autoflush(False).one()
|
||||
@@ -68,12 +69,12 @@ def test_update_uuid_entry(
|
||||
from superset.key_value.commands.update import UpdateKeyValueCommand
|
||||
from superset.key_value.models import KeyValueEntry
|
||||
|
||||
key = UpdateKeyValueCommand(
|
||||
actor=admin,
|
||||
resource=RESOURCE,
|
||||
key=UUID_KEY,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
with override_user(admin):
|
||||
key = UpdateKeyValueCommand(
|
||||
resource=RESOURCE,
|
||||
key=UUID_KEY,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
assert key is not None
|
||||
assert key.uuid == UUID_KEY
|
||||
entry = (
|
||||
@@ -86,10 +87,10 @@ def test_update_uuid_entry(
|
||||
def test_update_missing_entry(app_context: AppContext, admin: User) -> None:
|
||||
from superset.key_value.commands.update import UpdateKeyValueCommand
|
||||
|
||||
key = UpdateKeyValueCommand(
|
||||
actor=admin,
|
||||
resource=RESOURCE,
|
||||
key=456,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
with override_user(admin):
|
||||
key = UpdateKeyValueCommand(
|
||||
resource=RESOURCE,
|
||||
key=456,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
assert key is None
|
||||
|
||||
@@ -24,6 +24,7 @@ from flask.ctx import AppContext
|
||||
from flask_appbuilder.security.sqla.models import User
|
||||
|
||||
from superset.extensions import db
|
||||
from superset.utils.core import override_user
|
||||
from tests.integration_tests.key_value.commands.fixtures import (
|
||||
admin,
|
||||
ID_KEY,
|
||||
@@ -47,12 +48,12 @@ def test_upsert_id_entry(
|
||||
from superset.key_value.commands.upsert import UpsertKeyValueCommand
|
||||
from superset.key_value.models import KeyValueEntry
|
||||
|
||||
key = UpsertKeyValueCommand(
|
||||
actor=admin,
|
||||
resource=RESOURCE,
|
||||
key=ID_KEY,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
with override_user(admin):
|
||||
key = UpsertKeyValueCommand(
|
||||
resource=RESOURCE,
|
||||
key=ID_KEY,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
assert key is not None
|
||||
assert key.id == ID_KEY
|
||||
entry = (
|
||||
@@ -70,12 +71,12 @@ def test_upsert_uuid_entry(
|
||||
from superset.key_value.commands.upsert import UpsertKeyValueCommand
|
||||
from superset.key_value.models import KeyValueEntry
|
||||
|
||||
key = UpsertKeyValueCommand(
|
||||
actor=admin,
|
||||
resource=RESOURCE,
|
||||
key=UUID_KEY,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
with override_user(admin):
|
||||
key = UpsertKeyValueCommand(
|
||||
resource=RESOURCE,
|
||||
key=UUID_KEY,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
assert key is not None
|
||||
assert key.uuid == UUID_KEY
|
||||
entry = (
|
||||
@@ -89,12 +90,12 @@ def test_upsert_missing_entry(app_context: AppContext, admin: User) -> None:
|
||||
from superset.key_value.commands.upsert import UpsertKeyValueCommand
|
||||
from superset.key_value.models import KeyValueEntry
|
||||
|
||||
key = UpsertKeyValueCommand(
|
||||
actor=admin,
|
||||
resource=RESOURCE,
|
||||
key=456,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
with override_user(admin):
|
||||
key = UpsertKeyValueCommand(
|
||||
resource=RESOURCE,
|
||||
key=456,
|
||||
value=NEW_VALUE,
|
||||
).run()
|
||||
assert key is not None
|
||||
assert key.id == 456
|
||||
db.session.query(KeyValueEntry).filter_by(id=456).delete()
|
||||
|
||||
Reference in New Issue
Block a user