mirror of
https://github.com/apache/superset.git
synced 2026-08-12 11:11:01 +00:00
chore: enforce more ruff rules (#31447)
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
co-authored by
Elizabeth Thompson
parent
9da65d6bfd
commit
e51b95ffa8
@@ -81,7 +81,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
"slug": "slug1_changed",
|
||||
"position_json": '{"b": "B"}',
|
||||
"css": "css_changed",
|
||||
"json_metadata": '{"refresh_frequency": 30, "timed_refresh_immune_slices": [], "expanded_slices": {}, "color_scheme": "", "label_colors": {}, "shared_label_colors": [], "map_label_colors": {}, "color_scheme_domain": [], "cross_filters_enabled": false}',
|
||||
"json_metadata": '{"refresh_frequency": 30, "timed_refresh_immune_slices": [], "expanded_slices": {}, "color_scheme": "", "label_colors": {}, "shared_label_colors": [], "map_label_colors": {}, "color_scheme_domain": [], "cross_filters_enabled": false}', # noqa: E501
|
||||
"published": False,
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
"reordered": [],
|
||||
}
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def create_dashboards(self):
|
||||
with self.create_app().app_context():
|
||||
dashboards = []
|
||||
@@ -136,7 +136,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
db.session.delete(fav_dashboard)
|
||||
db.session.commit()
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def create_created_by_gamma_dashboards(self):
|
||||
with self.create_app().app_context():
|
||||
dashboards = []
|
||||
@@ -157,7 +157,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
db.session.delete(dashboard)
|
||||
db.session.commit()
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def create_dashboard_with_report(self):
|
||||
with self.create_app().app_context():
|
||||
admin = self.get_user("admin")
|
||||
@@ -218,7 +218,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
- ``fourth_dashboard`` is not associated with any tag
|
||||
|
||||
Relies on the ``create_custom_tags`` fixture for the tag creation.
|
||||
"""
|
||||
""" # noqa: E501
|
||||
with self.create_app().app_context():
|
||||
admin_user = self.get_user(ADMIN_USERNAME)
|
||||
|
||||
@@ -832,9 +832,9 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
assert data_by_id["count"] == data_by_name["count"], len(
|
||||
expected_dashboards
|
||||
)
|
||||
assert set(chart["id"] for chart in data_by_id["result"]) == set(
|
||||
assert set(chart["id"] for chart in data_by_id["result"]) == set( # noqa: C401
|
||||
chart["id"] for chart in data_by_name["result"]
|
||||
), set(chart.id for chart in expected_dashboards)
|
||||
), set(chart.id for chart in expected_dashboards) # noqa: C401
|
||||
|
||||
@pytest.mark.usefixtures("create_dashboards")
|
||||
def test_get_current_user_favorite_status(self):
|
||||
@@ -1273,7 +1273,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
"""
|
||||
admin_id = self.get_user("admin").id
|
||||
dashboard_count = 4
|
||||
dashboard_ids = list()
|
||||
dashboard_ids = list() # noqa: C408
|
||||
for dashboard_name_index in range(dashboard_count):
|
||||
dashboard_ids.append(
|
||||
self.insert_dashboard(
|
||||
@@ -1300,7 +1300,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
"""
|
||||
user = self.get_user("admin")
|
||||
dashboard_count = 4
|
||||
dashboard_ids = list()
|
||||
dashboard_ids = list() # noqa: C408
|
||||
for dashboard_name_index in range(dashboard_count):
|
||||
dashboard_ids.append(
|
||||
self.insert_dashboard(
|
||||
@@ -1434,7 +1434,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
"""
|
||||
gamma_id = self.get_user("gamma").id
|
||||
dashboard_count = 4
|
||||
dashboard_ids = list()
|
||||
dashboard_ids = list() # noqa: C408
|
||||
for dashboard_name_index in range(dashboard_count):
|
||||
dashboard_ids.append(
|
||||
self.insert_dashboard(
|
||||
@@ -1474,7 +1474,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
dashboard = self.insert_dashboard(
|
||||
"title", "slug1", [user_alpha1.id], slices=[existing_slice], published=True
|
||||
)
|
||||
self.login(username="alpha2", password="password")
|
||||
self.login(username="alpha2", password="password") # noqa: S106
|
||||
uri = f"api/v1/dashboard/{dashboard.id}"
|
||||
rv = self.client.delete(uri)
|
||||
assert rv.status_code == 403
|
||||
@@ -1499,7 +1499,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
)
|
||||
|
||||
dashboard_count = 4
|
||||
dashboards = list()
|
||||
dashboards = list() # noqa: C408
|
||||
for dashboard_name_index in range(dashboard_count):
|
||||
dashboards.append(
|
||||
self.insert_dashboard(
|
||||
@@ -1519,7 +1519,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
published=True,
|
||||
)
|
||||
|
||||
self.login(username="alpha2", password="password")
|
||||
self.login(username="alpha2", password="password") # noqa: S106
|
||||
|
||||
# verify we can't delete not owned dashboards
|
||||
arguments = [dashboard.id for dashboard in dashboards]
|
||||
@@ -2208,7 +2208,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
dashboard = self.insert_dashboard(
|
||||
"title", "slug1", [user_alpha1.id], slices=[existing_slice], published=True
|
||||
)
|
||||
self.login(username="alpha2", password="password")
|
||||
self.login(username="alpha2", password="password") # noqa: S106
|
||||
dashboard_data = {"dashboard_title": "title1_changed", "slug": "slug1 changed"}
|
||||
uri = f"api/v1/dashboard/{dashboard.id}"
|
||||
rv = self.put_assert_metric(uri, dashboard_data, "put")
|
||||
@@ -2435,27 +2435,30 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing dashboard",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"dashboards/imported_dashboard.yaml": "Dashboard already exists and `overwrite=true` was not passed",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
assert (
|
||||
response
|
||||
== {
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing dashboard",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"dashboards/imported_dashboard.yaml": "Dashboard already exists and `overwrite=true` was not passed", # noqa: E501
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
# import with overwrite flag
|
||||
buf = self.create_dashboard_import()
|
||||
@@ -3021,7 +3024,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
return self.client.post(uri, json=payload)
|
||||
|
||||
def _get_screenshot(self, dashboard_id, cache_key, download_format):
|
||||
uri = f"/api/v1/dashboard/{dashboard_id}/screenshot/{cache_key}/?download_format={download_format}"
|
||||
uri = f"/api/v1/dashboard/{dashboard_id}/screenshot/{cache_key}/?download_format={download_format}" # noqa: E501
|
||||
return self.client.get(uri)
|
||||
|
||||
@pytest.mark.usefixtures("create_dashboard_with_tag")
|
||||
@@ -3240,7 +3243,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
def test_put_dashboard_colors_no_mark_updated(self):
|
||||
"""
|
||||
Dashboard API: Test updating dashboard colors without marking the dashboard as updated
|
||||
"""
|
||||
""" # noqa: E501
|
||||
self.login(ADMIN_USERNAME)
|
||||
dashboard = Dashboard.get("world_health")
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ class TestExportDashboardsCommand(SupersetTestCase):
|
||||
expected_paths = {
|
||||
"metadata.yaml",
|
||||
f"dashboards/COVID_Vaccine_Dashboard_{example_dashboard.id}.yaml",
|
||||
"datasets/examples/covid_vaccines.yaml", # referenced dataset needs to be exported
|
||||
"datasets/examples/covid_vaccines.yaml", # referenced dataset needs to be exported # noqa: E501
|
||||
"databases/examples.yaml",
|
||||
}
|
||||
for chart in example_dashboard.slices:
|
||||
@@ -296,7 +296,7 @@ class TestExportDashboardsCommand(SupersetTestCase):
|
||||
)
|
||||
command = ExportDashboardsCommand([example_dashboard.id])
|
||||
contents = command.run()
|
||||
with self.assertRaises(DashboardNotFoundError):
|
||||
with self.assertRaises(DashboardNotFoundError): # noqa: PT027
|
||||
next(contents)
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
@@ -308,7 +308,7 @@ class TestExportDashboardsCommand(SupersetTestCase):
|
||||
mock_g2.user = security_manager.find_user("admin")
|
||||
command = ExportDashboardsCommand([-1])
|
||||
contents = command.run()
|
||||
with self.assertRaises(DashboardNotFoundError):
|
||||
with self.assertRaises(DashboardNotFoundError): # noqa: PT027
|
||||
next(contents)
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
@@ -766,7 +766,7 @@ class TestCopyDashboardCommand(SupersetTestCase):
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
def test_copy_dashboard_command_no_access(self):
|
||||
"""Test that a non-owner user cannot copy a dashboard if DASHBOARD_RBAC is enabled"""
|
||||
"""Test that a non-owner user cannot copy a dashboard if DASHBOARD_RBAC is enabled""" # noqa: E501
|
||||
with self.client.application.test_request_context():
|
||||
example_dashboard = (
|
||||
db.session.query(Dashboard).filter_by(slug="world_health").one()
|
||||
@@ -779,7 +779,7 @@ class TestCopyDashboardCommand(SupersetTestCase):
|
||||
return_value=True,
|
||||
):
|
||||
command = CopyDashboardCommand(example_dashboard, copy_data)
|
||||
with self.assertRaises(DashboardForbiddenError):
|
||||
with self.assertRaises(DashboardForbiddenError): # noqa: PT027
|
||||
command.run()
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
@@ -793,7 +793,7 @@ class TestCopyDashboardCommand(SupersetTestCase):
|
||||
|
||||
with override_user(security_manager.find_user("admin")):
|
||||
command = CopyDashboardCommand(example_dashboard, invalid_copy_data)
|
||||
with self.assertRaises(DashboardInvalidError):
|
||||
with self.assertRaises(DashboardInvalidError): # noqa: PT027
|
||||
command.run()
|
||||
|
||||
|
||||
@@ -868,16 +868,16 @@ class TestFavoriteDashboardCommand(SupersetTestCase):
|
||||
example_dashboard_id = 1234
|
||||
|
||||
with override_user(security_manager.find_user("admin")):
|
||||
with self.assertRaises(DashboardNotFoundError):
|
||||
with self.assertRaises(DashboardNotFoundError): # noqa: PT027
|
||||
AddFavoriteDashboardCommand(example_dashboard_id).run()
|
||||
|
||||
with self.assertRaises(DashboardNotFoundError):
|
||||
with self.assertRaises(DashboardNotFoundError): # noqa: PT027
|
||||
DelFavoriteDashboardCommand(example_dashboard_id).run()
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
@patch("superset.models.dashboard.Dashboard.get")
|
||||
def test_fave_unfave_dashboard_command_forbidden(self, mock_get):
|
||||
"""Test that faving / unfaving raises an exception for a dashboard the user doesn't own"""
|
||||
"""Test that faving / unfaving raises an exception for a dashboard the user doesn't own""" # noqa: E501
|
||||
with self.client.application.test_request_context():
|
||||
example_dashboard = (
|
||||
db.session.query(Dashboard).filter_by(slug="world_health").one()
|
||||
@@ -889,8 +889,8 @@ class TestFavoriteDashboardCommand(SupersetTestCase):
|
||||
assert example_dashboard is not None
|
||||
|
||||
with override_user(security_manager.find_user("gamma")):
|
||||
with self.assertRaises(DashboardAccessDeniedError):
|
||||
with self.assertRaises(DashboardAccessDeniedError): # noqa: PT027
|
||||
AddFavoriteDashboardCommand(example_dashboard.uuid).run()
|
||||
|
||||
with self.assertRaises(DashboardAccessDeniedError):
|
||||
with self.assertRaises(DashboardAccessDeniedError): # noqa: PT027
|
||||
DelFavoriteDashboardCommand(example_dashboard.uuid).run()
|
||||
|
||||
@@ -98,7 +98,7 @@ def random_slug():
|
||||
|
||||
def get_random_string(length):
|
||||
letters = string.ascii_lowercase
|
||||
result_str = "".join(random.choice(letters) for i in range(length))
|
||||
result_str = "".join(random.choice(letters) for i in range(length)) # noqa: S311
|
||||
print("Random string of length", length, "is:", result_str)
|
||||
return result_str
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class BaseTestDashboardSecurity(DashboardTestCase):
|
||||
self.assert200(response)
|
||||
response_data = response.json
|
||||
assert response_data["count"] == expected_counts
|
||||
response_dashboards_url = set(
|
||||
response_dashboards_url = set( # noqa: C417
|
||||
map(lambda dash: dash["url"], response_data["result"])
|
||||
)
|
||||
expected_dashboards = expected_dashboards or []
|
||||
|
||||
@@ -85,7 +85,7 @@ class TestDashboardDatasetSecurity(DashboardTestCase):
|
||||
}
|
||||
|
||||
# assert
|
||||
for dashboard_url, get_dashboard_response in responses_by_url.items():
|
||||
for dashboard_url, get_dashboard_response in responses_by_url.items(): # noqa: B007
|
||||
self.assert200(get_dashboard_response)
|
||||
|
||||
def test_get_dashboards__users_are_dashboards_owners(self):
|
||||
|
||||
@@ -224,7 +224,7 @@ class TestDashboardRoleBasedSecurity(BaseTestDashboardSecurity):
|
||||
assert response.status_code == 302
|
||||
|
||||
@pytest.mark.usefixtures("public_role_like_gamma")
|
||||
def test_get_dashboard_view__public_user_with_dashboard_permission_can_not_access_draft(
|
||||
def test_get_dashboard_view__public_user_with_dashboard_permission_can_not_access_draft( # noqa: E501
|
||||
self,
|
||||
):
|
||||
# arrange
|
||||
|
||||
Reference in New Issue
Block a user