fix: create permissions on DB import (#29802)

This commit is contained in:
Beto Dealmeida
2024-08-06 12:09:21 -04:00
committed by GitHub
parent 1c3ef01209
commit 61c0970968
18 changed files with 273 additions and 87 deletions

View File

@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
import copy
from unittest.mock import patch
import yaml
from flask import g
@@ -63,8 +64,10 @@ class TestImportAssetsCommand(SupersetTestCase):
self.user = user
setattr(g, "user", user)
def test_import_assets(self):
@patch("superset.commands.database.importers.v1.utils.add_permissions")
def test_import_assets(self, mock_add_permissions):
"""Test that we can import multiple assets"""
contents = {
"metadata.yaml": yaml.safe_dump(metadata_config),
"databases/imported_database.yaml": yaml.safe_dump(database_config),
@@ -144,13 +147,16 @@ class TestImportAssetsCommand(SupersetTestCase):
assert dashboard.owners == [self.user]
mock_add_permissions.assert_called_with(database, None)
db.session.delete(dashboard)
db.session.delete(chart)
db.session.delete(dataset)
db.session.delete(database)
db.session.commit()
def test_import_v1_dashboard_overwrite(self):
@patch("superset.commands.database.importers.v1.utils.add_permissions")
def test_import_v1_dashboard_overwrite(self, mock_add_permissions):
"""Test that assets can be overwritten"""
contents = {
"metadata.yaml": yaml.safe_dump(metadata_config),
@@ -185,6 +191,9 @@ class TestImportAssetsCommand(SupersetTestCase):
chart = dashboard.slices[0]
dataset = chart.table
database = dataset.database
mock_add_permissions.assert_called_with(database, None)
db.session.delete(dashboard)
db.session.delete(chart)
db.session.delete(dataset)