mirror of
https://github.com/apache/superset.git
synced 2026-04-20 08:34:37 +00:00
chore: set up ruff as a new linter/formatter (#28158)
This commit is contained in:
committed by
GitHub
parent
e8a678b75a
commit
2d63722150
@@ -19,7 +19,7 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from flask_appbuilder.security.sqla.models import User
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.orm import Session # noqa: F401
|
||||
|
||||
from superset import db
|
||||
from superset.commands.explore.form_data.state import TemporaryExploreState
|
||||
@@ -28,8 +28,8 @@ from superset.explore.exceptions import DatasetAccessDeniedError
|
||||
from superset.extensions import cache_manager
|
||||
from superset.models.slice import Slice
|
||||
from tests.integration_tests.fixtures.world_bank_dashboard import (
|
||||
load_world_bank_dashboard_with_slices,
|
||||
load_world_bank_data,
|
||||
load_world_bank_dashboard_with_slices, # noqa: F401
|
||||
load_world_bank_data, # noqa: F401
|
||||
)
|
||||
from tests.integration_tests.test_app import app
|
||||
|
||||
@@ -38,22 +38,22 @@ FORM_DATA = {"test": "test value"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chart_id(load_world_bank_dashboard_with_slices) -> int:
|
||||
with app.app_context() as ctx:
|
||||
def chart_id(load_world_bank_dashboard_with_slices) -> int: # noqa: F811
|
||||
with app.app_context(): # noqa: F841
|
||||
chart = db.session.query(Slice).filter_by(slice_name="World's Population").one()
|
||||
return chart.id
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_id() -> int:
|
||||
with app.app_context() as ctx:
|
||||
with app.app_context(): # noqa: F841
|
||||
admin = db.session.query(User).filter_by(username="admin").one()
|
||||
return admin.id
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dataset() -> int:
|
||||
with app.app_context() as ctx:
|
||||
with app.app_context(): # noqa: F841
|
||||
dataset = (
|
||||
db.session.query(SqlaTable)
|
||||
.filter_by(table_name="wb_health_population")
|
||||
@@ -79,9 +79,9 @@ def assert_dataset(result, dataset_id):
|
||||
dataset = result["dataset"]
|
||||
assert dataset["id"] == dataset_id
|
||||
assert dataset["datasource_name"] == "wb_health_population"
|
||||
assert dataset["is_sqllab_view"] == False
|
||||
assert dataset["is_sqllab_view"] is False # noqa: E712
|
||||
assert dataset["main_dttm_col"] == "year"
|
||||
assert dataset["sql"] == None
|
||||
assert dataset["sql"] is None # noqa: E711
|
||||
assert dataset["type"] == "table"
|
||||
assert dataset["uid"] == f"{dataset_id}__table"
|
||||
|
||||
@@ -90,7 +90,7 @@ def assert_dataset(result, dataset_id):
|
||||
def assert_slice(result, chart_id, dataset_id):
|
||||
slice = result["slice"]
|
||||
assert slice["edit_url"] == f"/chart/edit/{chart_id}"
|
||||
assert slice["is_managed_externally"] == False
|
||||
assert slice["is_managed_externally"] is False # noqa: E712
|
||||
assert slice["slice_id"] == chart_id
|
||||
assert slice["slice_name"] == "World's Population"
|
||||
assert slice["form_data"]["datasource"] == f"{dataset_id}__table"
|
||||
@@ -98,14 +98,14 @@ def assert_slice(result, chart_id, dataset_id):
|
||||
|
||||
|
||||
def test_no_params_provided(test_client, login_as_admin):
|
||||
resp = test_client.get(f"api/v1/explore/")
|
||||
resp = test_client.get("api/v1/explore/") # noqa: F541
|
||||
assert resp.status_code == 200
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
result = data.get("result")
|
||||
assert result["dataset"]["name"] == "[Missing Dataset]"
|
||||
assert result["form_data"]["datasource"] == "None__table"
|
||||
assert result["message"] == None
|
||||
assert result["slice"] == None
|
||||
assert result["message"] is None # noqa: E711
|
||||
assert result["slice"] is None # noqa: E711
|
||||
|
||||
|
||||
def test_get_from_cache(test_client, login_as_admin, dataset):
|
||||
@@ -118,8 +118,8 @@ def test_get_from_cache(test_client, login_as_admin, dataset):
|
||||
assert_dataset(result, dataset.id)
|
||||
assert result["form_data"]["datasource"] == f"{dataset.id}__table"
|
||||
assert result["form_data"]["test"] == "test value"
|
||||
assert result["message"] == None
|
||||
assert result["slice"] == None
|
||||
assert result["message"] is None # noqa: E711
|
||||
assert result["slice"] is None # noqa: E711
|
||||
|
||||
|
||||
def test_get_from_cache_unknown_key_chart_id(
|
||||
@@ -155,7 +155,7 @@ def test_get_from_cache_unknown_key_dataset(test_client, login_as_admin, dataset
|
||||
result["message"]
|
||||
== "Form data not found in cache, reverting to dataset metadata."
|
||||
)
|
||||
assert result["slice"] == None
|
||||
assert result["slice"] is None # noqa: E711
|
||||
|
||||
|
||||
def test_get_from_cache_unknown_key_no_extra_parameters(test_client, login_as_admin):
|
||||
@@ -166,8 +166,8 @@ def test_get_from_cache_unknown_key_no_extra_parameters(test_client, login_as_ad
|
||||
result = data.get("result")
|
||||
assert result["dataset"]["name"] == "[Missing Dataset]"
|
||||
assert result["form_data"]["datasource"] == "None__table"
|
||||
assert result["message"] == None
|
||||
assert result["slice"] == None
|
||||
assert result["message"] is None # noqa: E711
|
||||
assert result["slice"] is None # noqa: E711
|
||||
|
||||
|
||||
def test_get_from_permalink(test_client, login_as_admin, chart_id, dataset):
|
||||
@@ -176,7 +176,7 @@ def test_get_from_permalink(test_client, login_as_admin, chart_id, dataset):
|
||||
"datasource": f"{dataset.id}__{dataset.type}",
|
||||
**FORM_DATA,
|
||||
}
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
resp = test_client.post("api/v1/explore/permalink", json={"formData": form_data}) # noqa: F541
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
permalink_key = data["key"]
|
||||
resp = test_client.get(f"api/v1/explore/?permalink_key={permalink_key}")
|
||||
@@ -186,8 +186,8 @@ def test_get_from_permalink(test_client, login_as_admin, chart_id, dataset):
|
||||
assert_dataset(result, dataset.id)
|
||||
assert result["form_data"]["datasource"] == f"{dataset.id}__table"
|
||||
assert result["form_data"]["test"] == "test value"
|
||||
assert result["message"] == None
|
||||
assert result["slice"] == None
|
||||
assert result["message"] is None # noqa: E711
|
||||
assert result["slice"] is None # noqa: E711
|
||||
|
||||
|
||||
def test_get_from_permalink_unknown_key(test_client, login_as_admin):
|
||||
|
||||
@@ -19,7 +19,7 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from flask_appbuilder.security.sqla.models import User
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.orm import Session # noqa: F401
|
||||
|
||||
from superset import db
|
||||
from superset.commands.dataset.exceptions import DatasetAccessDeniedError
|
||||
@@ -29,8 +29,8 @@ from superset.extensions import cache_manager
|
||||
from superset.models.slice import Slice
|
||||
from superset.utils.core import DatasourceType
|
||||
from tests.integration_tests.fixtures.world_bank_dashboard import (
|
||||
load_world_bank_dashboard_with_slices,
|
||||
load_world_bank_data,
|
||||
load_world_bank_dashboard_with_slices, # noqa: F401
|
||||
load_world_bank_data, # noqa: F401
|
||||
)
|
||||
from tests.integration_tests.test_app import app
|
||||
|
||||
@@ -40,22 +40,22 @@ UPDATED_FORM_DATA = json.dumps({"test": "updated value"})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chart_id(load_world_bank_dashboard_with_slices) -> int:
|
||||
with app.app_context() as ctx:
|
||||
def chart_id(load_world_bank_dashboard_with_slices) -> int: # noqa: F811
|
||||
with app.app_context() as ctx: # noqa: F841
|
||||
chart = db.session.query(Slice).filter_by(slice_name="World's Population").one()
|
||||
return chart.id
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_id() -> int:
|
||||
with app.app_context() as ctx:
|
||||
with app.app_context() as ctx: # noqa: F841
|
||||
admin = db.session.query(User).filter_by(username="admin").one()
|
||||
return admin.id
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def datasource() -> int:
|
||||
with app.app_context() as ctx:
|
||||
with app.app_context() as ctx: # noqa: F841
|
||||
dataset = (
|
||||
db.session.query(SqlaTable)
|
||||
.filter_by(table_name="wb_health_population")
|
||||
@@ -351,7 +351,7 @@ def test_put_not_owner(test_client, login_as, chart_id: int, datasource: SqlaTab
|
||||
|
||||
|
||||
def test_get_key_not_found(test_client, login_as_admin):
|
||||
resp = test_client.get(f"api/v1/explore/form_data/unknown-key")
|
||||
resp = test_client.get(f"api/v1/explore/form_data/unknown-key") # noqa: F541
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from superset import app, db, security, security_manager
|
||||
from superset import app, db, security_manager
|
||||
from superset.commands.exceptions import DatasourceTypeInvalidError
|
||||
from superset.commands.explore.form_data.create import CreateFormDataCommand
|
||||
from superset.commands.explore.form_data.delete import DeleteFormDataCommand
|
||||
@@ -326,7 +326,7 @@ class TestCreateFormDataCommand(SupersetTestCase):
|
||||
delete_command = DeleteFormDataCommand(delete_args)
|
||||
response = delete_command.run()
|
||||
|
||||
assert response == True
|
||||
assert response is True # noqa: E712
|
||||
|
||||
@patch("superset.security.manager.g")
|
||||
@pytest.mark.usefixtures("create_dataset", "create_slice", "create_query")
|
||||
@@ -343,4 +343,4 @@ class TestCreateFormDataCommand(SupersetTestCase):
|
||||
delete_command = DeleteFormDataCommand(delete_args)
|
||||
response = delete_command.run()
|
||||
|
||||
assert response == False
|
||||
assert response is False # noqa: E712
|
||||
|
||||
@@ -20,7 +20,7 @@ from typing import Any
|
||||
from uuid import uuid3
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.orm import Session # noqa: F401
|
||||
|
||||
from superset import db
|
||||
from superset.explore.permalink.schemas import ExplorePermalinkSchema
|
||||
@@ -30,14 +30,14 @@ from superset.key_value.utils import decode_permalink_id, encode_permalink_key
|
||||
from superset.models.slice import Slice
|
||||
from superset.utils.core import DatasourceType
|
||||
from tests.integration_tests.fixtures.world_bank_dashboard import (
|
||||
load_world_bank_dashboard_with_slices,
|
||||
load_world_bank_data,
|
||||
load_world_bank_dashboard_with_slices, # noqa: F401
|
||||
load_world_bank_data, # noqa: F401
|
||||
)
|
||||
from tests.integration_tests.test_app import app
|
||||
from tests.integration_tests.test_app import app # noqa: F401
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chart(app_context, load_world_bank_dashboard_with_slices) -> Slice:
|
||||
def chart(app_context, load_world_bank_dashboard_with_slices) -> Slice: # noqa: F811
|
||||
chart = db.session.query(Slice).filter_by(slice_name="World's Population").one()
|
||||
return chart
|
||||
|
||||
@@ -70,7 +70,7 @@ def permalink_salt() -> Iterator[str]:
|
||||
def test_post(
|
||||
form_data: dict[str, Any], permalink_salt: str, test_client, login_as_admin
|
||||
):
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data}) # noqa: F541
|
||||
assert resp.status_code == 201
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
key = data["key"]
|
||||
@@ -83,7 +83,7 @@ def test_post(
|
||||
|
||||
def test_post_access_denied(form_data, test_client, login_as):
|
||||
login_as("gamma")
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data}) # noqa: F541
|
||||
assert resp.status_code == 403
|
||||
|
||||
|
||||
@@ -120,14 +120,14 @@ def test_get_missing_chart(
|
||||
|
||||
|
||||
def test_post_invalid_schema(test_client, login_as_admin) -> None:
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"abc": 123})
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"abc": 123}) # noqa: F541
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_get(
|
||||
form_data: dict[str, Any], permalink_salt: str, test_client, login_as_admin
|
||||
) -> None:
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data})
|
||||
resp = test_client.post(f"api/v1/explore/permalink", json={"formData": form_data}) # noqa: F541
|
||||
data = json.loads(resp.data.decode("utf-8"))
|
||||
key = data["key"]
|
||||
resp = test_client.get(f"api/v1/explore/permalink/{key}")
|
||||
|
||||
@@ -19,13 +19,10 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from superset import app, db, security, security_manager
|
||||
from superset.commands.exceptions import DatasourceTypeInvalidError
|
||||
from superset.commands.explore.form_data.parameters import CommandParameters
|
||||
from superset import app, db, security_manager
|
||||
from superset.commands.explore.permalink.create import CreateExplorePermalinkCommand
|
||||
from superset.commands.explore.permalink.get import GetExplorePermalinkCommand
|
||||
from superset.connectors.sqla.models import SqlaTable
|
||||
from superset.key_value.utils import decode_permalink_id
|
||||
from superset.models.slice import Slice
|
||||
from superset.models.sql_lab import Query
|
||||
from superset.utils.core import DatasourceType, get_example_default_schema
|
||||
|
||||
Reference in New Issue
Block a user