Skip to content

Commit

Permalink
Revert interim test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley committed Jun 27, 2024
1 parent 9653361 commit 2dbe1c6
Show file tree
Hide file tree
Showing 63 changed files with 271 additions and 428 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ basepython = python3.10
ignore_basepython_conflict = true
commands =
superset db upgrade
superset load_test_users
superset init
superset load-test-users
# use -s to be able to use break pointers.
# no args or tests/* can be passed as an argument to run all tests
pytest -s {posargs}
Expand Down
30 changes: 19 additions & 11 deletions scripts/permissions_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,59 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=consider-using-transaction
from collections import defaultdict

from superset import db, security_manager
from superset import security_manager
from superset.utils.decorators import transaction


@transaction()
def cleanup_permissions() -> None:
# 1. Clean up duplicates.
pvms = db.session.query(security_manager.permissionview_model).all()
pvms = security_manager.get_session.query(
security_manager.permissionview_model
).all()
print(f"# of permission view menus is: {len(pvms)}")
pvms_dict = defaultdict(list)
for pvm in pvms:
pvms_dict[(pvm.permission, pvm.view_menu)].append(pvm)
duplicates = [v for v in pvms_dict.values() if len(v) > 1]
len(duplicates)

for pvm_list in duplicates:
first_prm = pvm_list[0]
roles = set(first_prm.role)
for pvm in pvm_list[1:]:
roles = roles.union(pvm.role)
db.session.delete(pvm)
security_manager.get_session.delete(pvm)
first_prm.roles = list(roles)

pvms = db.session.query(security_manager.permissionview_model).all()
pvms = security_manager.get_session.query(
security_manager.permissionview_model
).all()
print(f"Stage 1: # of permission view menus is: {len(pvms)}")

# 2. Clean up None permissions or view menus
pvms = db.session.query(security_manager.permissionview_model).all()
pvms = security_manager.get_session.query(
security_manager.permissionview_model
).all()
for pvm in pvms:
if not (pvm.view_menu and pvm.permission):
db.session.delete(pvm)
security_manager.get_session.delete(pvm)

pvms = db.session.query(security_manager.permissionview_model).all()
pvms = security_manager.get_session.query(
security_manager.permissionview_model
).all()
print(f"Stage 2: # of permission view menus is: {len(pvms)}")

# 3. Delete empty permission view menus from roles
roles = db.session.query(security_manager.role_model).all()
roles = security_manager.get_session.query(security_manager.role_model).all()
for role in roles:
role.permissions = [p for p in role.permissions if p]

# 4. Delete empty roles from permission view menus
pvms = db.session.query(security_manager.permissionview_model).all()
pvms = security_manager.get_session.query(
security_manager.permissionview_model
).all()
for pvm in pvms:
pvm.role = [r for r in pvm.role if r]

Expand Down
3 changes: 2 additions & 1 deletion scripts/python_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export SUPERSET_TESTENV=true
echo "Superset config module: $SUPERSET_CONFIG"

superset db upgrade
superset load_test_users
superset init
superset load-test-users

echo "Running tests"

# pytest --durations-min=2 --maxfail=1 --cov-report= --cov=superset ./tests/integration_tests "$@"
pytest --durations-min=2 --cov-report= --cov=superset ./tests/integration_tests "$@"
8 changes: 0 additions & 8 deletions superset/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,7 @@ def load_test_users() -> None:
Syncs permissions for those users/roles
"""
print(Fore.GREEN + "Loading a set of users for unit tests")
load_test_users_run()


def load_test_users_run() -> None:
"""
Loads admin, alpha, and gamma user for testing purposes
Syncs permissions for those users/roles
"""
if app.config["TESTING"]:
sm = security_manager

Expand Down
2 changes: 1 addition & 1 deletion superset/commands/chart/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def import_chart(
if chart.id is None:
db.session.flush()

if user := get_user():
if (user := get_user()) and user not in chart.owners:
chart.owners.append(user)

return chart
Expand Down
7 changes: 3 additions & 4 deletions superset/commands/chart/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
from superset.daos.dashboard import DashboardDAO
from superset.exceptions import SupersetSecurityException
from superset.models.slice import Slice
from superset.utils.decorators import on_error, transaction
from superset.tags.models import ObjectType
from superset.utils.decorators import on_error, transaction

logger = logging.getLogger(__name__)

Expand All @@ -62,14 +62,13 @@ def run(self) -> Model:
assert self._model

# Update tags
tags = self._properties.pop("tags", None)
if tags is not None:
if (tags := self._properties.pop("tags", None)) is not None:
update_tags(ObjectType.chart, self._model.id, self._model.tags, tags)

if self._properties.get("query_context_generation") is None:
self._properties["last_saved_at"] = datetime.now()
self._properties["last_saved_by"] = g.user

return ChartDAO.update(self._model, self._properties)

def validate(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion superset/commands/dashboard/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def import_dashboard(
if dashboard.id is None:
db.session.flush()

if user := get_user():
if (user := get_user()) and user not in dashboard.owners:
dashboard.owners.append(user)

return dashboard
2 changes: 1 addition & 1 deletion superset/commands/dashboard/permalink/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from sqlalchemy.exc import SQLAlchemyError

from superset import db
from superset.commands.dashboard.permalink.base import BaseDashboardPermalinkCommand
from superset.commands.key_value.upsert import UpsertKeyValueCommand
from superset.daos.dashboard import DashboardDAO
Expand Down Expand Up @@ -78,6 +77,7 @@ def run(self) -> str:
codec=self.codec,
).run()
assert key.id # for type checks
return encode_permalink_key(key=key.id, salt=self.salt)

def validate(self) -> None:
pass
11 changes: 4 additions & 7 deletions superset/commands/dashboard/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,16 @@ def run(self) -> Model:
assert self._model

# Update tags
tags = self._properties.pop("tags", None)
if tags is not None:
update_tags(
ObjectType.dashboard, self._model.id, self._model.tags, tags
)
if (tags := self._properties.pop("tags", None)) is not None:
update_tags(ObjectType.dashboard, self._model.id, self._model.tags, tags)

dashboard = DashboardDAO.update(self._model, self._properties, commit=False)
dashboard = DashboardDAO.update(self._model, self._properties)
if self._properties.get("json_metadata"):
DashboardDAO.set_dash_metadata(
dashboard,
data=json.loads(self._properties.get("json_metadata", "{}")),
)

return dashboard

def validate(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion superset/commands/database/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
)
from superset.commands.database.test_connection import TestConnectionDatabaseCommand
from superset.daos.database import DatabaseDAO
from superset.daos.exceptions import DAOCreateFailedError
from superset.databases.ssh_tunnel.models import SSHTunnel
from superset.exceptions import SupersetErrorsException
from superset.extensions import event_logger, security_manager
from superset.models.core import Database
Expand Down
194 changes: 0 additions & 194 deletions superset/commands/database/csv_import.py

This file was deleted.

Loading

0 comments on commit 2dbe1c6

Please sign in to comment.