mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
chore: enforce more ruff rules (#31447)
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
committed by
GitHub
parent
9da65d6bfd
commit
e51b95ffa8
@@ -148,7 +148,7 @@ def test_password_mask(
|
||||
"project_id": "black-sanctum-314419",
|
||||
"private_key_id": "259b0d419a8f840056158763ff54d8b08f7b8173",
|
||||
"private_key": "SECRET",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com", # noqa: E501
|
||||
"client_id": "114567578578109757129",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
@@ -204,7 +204,7 @@ def test_database_connection(
|
||||
"project_id": "black-sanctum-314419",
|
||||
"private_key_id": "259b0d419a8f840056158763ff54d8b08f7b8173",
|
||||
"private_key": "SECRET",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com", # noqa: E501
|
||||
"client_id": "114567578578109757129",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
@@ -242,7 +242,7 @@ def test_database_connection(
|
||||
"supports_oauth2": True,
|
||||
},
|
||||
"expose_in_sqllab": True,
|
||||
"extra": '{\n "metadata_params": {},\n "engine_params": {},\n "metadata_cache_timeout": {},\n "schemas_allowed_for_file_upload": []\n}\n',
|
||||
"extra": '{\n "metadata_params": {},\n "engine_params": {},\n "metadata_cache_timeout": {},\n "schemas_allowed_for_file_upload": []\n}\n', # noqa: E501
|
||||
"force_ctas_schema": None,
|
||||
"id": 1,
|
||||
"impersonate_user": False,
|
||||
@@ -254,7 +254,7 @@ def test_database_connection(
|
||||
"project_id": "black-sanctum-314419",
|
||||
"private_key_id": "259b0d419a8f840056158763ff54d8b08f7b8173",
|
||||
"private_key": "XXXXXXXXXX",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com", # noqa: E501
|
||||
"client_id": "114567578578109757129",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
@@ -267,7 +267,7 @@ def test_database_connection(
|
||||
"service_account_info": {
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com", # noqa: E501
|
||||
"client_id": "114567578578109757129",
|
||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/google-spreadsheets-demo-servi%40black-sanctum-314419.iam.gserviceaccount.com",
|
||||
"private_key": "XXXXXXXXXX",
|
||||
@@ -373,7 +373,7 @@ def test_update_with_password_mask(
|
||||
database = db.session.query(Database).one()
|
||||
assert (
|
||||
database.encrypted_extra
|
||||
== '{"service_account_info": {"project_id": "yellow-unicorn-314419", "private_key": "SECRET"}}'
|
||||
== '{"service_account_info": {"project_id": "yellow-unicorn-314419", "private_key": "SECRET"}}' # noqa: E501
|
||||
)
|
||||
|
||||
|
||||
@@ -401,7 +401,7 @@ def test_non_zip_import(client: Any, full_api_access: None) -> None:
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": "Issue 1010 - Superset encountered an error while running a command.",
|
||||
"message": "Issue 1010 - Superset encountered an error while running a command.", # noqa: E501
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -442,7 +442,7 @@ def test_delete_ssh_tunnel(
|
||||
"project_id": "black-sanctum-314419",
|
||||
"private_key_id": "259b0d419a8f840056158763ff54d8b08f7b8173",
|
||||
"private_key": "SECRET",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com", # noqa: E501
|
||||
"client_id": "SSH_TUNNEL_CREDENTIALS_CLIENT",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
@@ -520,7 +520,7 @@ def test_delete_ssh_tunnel_not_found(
|
||||
"project_id": "black-sanctum-314419",
|
||||
"private_key_id": "259b0d419a8f840056158763ff54d8b08f7b8173",
|
||||
"private_key": "SECRET",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com",
|
||||
"client_email": "google-spreadsheets-demo-servi@black-sanctum-314419.iam.gserviceaccount.com", # noqa: E501
|
||||
"client_id": "SSH_TUNNEL_CREDENTIALS_CLIENT",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
@@ -723,9 +723,9 @@ def test_oauth2_happy_path(
|
||||
token = db.session.query(DatabaseUserOAuth2Tokens).one()
|
||||
assert token.user_id == 1
|
||||
assert token.database_id == 1
|
||||
assert token.access_token == "YYY"
|
||||
assert token.access_token == "YYY" # noqa: S105
|
||||
assert token.access_token_expiration == datetime(2024, 1, 1, 1, 0)
|
||||
assert token.refresh_token == "ZZZ"
|
||||
assert token.refresh_token == "ZZZ" # noqa: S105
|
||||
|
||||
|
||||
def test_oauth2_multiple_tokens(
|
||||
@@ -804,8 +804,8 @@ def test_oauth2_multiple_tokens(
|
||||
tokens = db.session.query(DatabaseUserOAuth2Tokens).all()
|
||||
assert len(tokens) == 1
|
||||
token = tokens[0]
|
||||
assert token.access_token == "YYY2"
|
||||
assert token.refresh_token == "ZZZ2"
|
||||
assert token.access_token == "YYY2" # noqa: S105
|
||||
assert token.refresh_token == "ZZZ2" # noqa: S105
|
||||
|
||||
|
||||
def test_oauth2_error(
|
||||
@@ -1811,7 +1811,7 @@ def test_table_metadata_no_table(
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1020,
|
||||
"message": "Issue 1020 - The submitted payload has the incorrect schema.",
|
||||
"message": "Issue 1020 - The submitted payload has the incorrect schema.", # noqa: E501
|
||||
}
|
||||
],
|
||||
},
|
||||
@@ -1862,7 +1862,7 @@ def test_table_metadata_invalid_database(
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1011,
|
||||
"message": "Issue 1011 - Superset encountered an unexpected error.",
|
||||
"message": "Issue 1011 - Superset encountered an unexpected error.", # noqa: E501
|
||||
},
|
||||
{
|
||||
"code": 1036,
|
||||
@@ -1975,7 +1975,7 @@ def test_table_extra_metadata_no_table(
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1020,
|
||||
"message": "Issue 1020 - The submitted payload has the incorrect schema.",
|
||||
"message": "Issue 1020 - The submitted payload has the incorrect schema.", # noqa: E501
|
||||
}
|
||||
],
|
||||
},
|
||||
@@ -2026,7 +2026,7 @@ def test_table_extra_metadata_invalid_database(
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1011,
|
||||
"message": "Issue 1011 - Superset encountered an unexpected error.",
|
||||
"message": "Issue 1011 - Superset encountered an unexpected error.", # noqa: E501
|
||||
},
|
||||
{
|
||||
"code": 1036,
|
||||
@@ -2084,7 +2084,7 @@ def test_catalogs(
|
||||
"""
|
||||
database = mocker.MagicMock()
|
||||
database.get_all_catalog_names.return_value = {"db1", "db2"}
|
||||
DatabaseDAO = mocker.patch("superset.databases.api.DatabaseDAO")
|
||||
DatabaseDAO = mocker.patch("superset.databases.api.DatabaseDAO") # noqa: N806
|
||||
DatabaseDAO.find_by_id.return_value = database
|
||||
|
||||
security_manager = mocker.patch(
|
||||
@@ -2128,7 +2128,7 @@ def test_catalogs_with_oauth2(
|
||||
"tab_id",
|
||||
"redirect_uri",
|
||||
)
|
||||
DatabaseDAO = mocker.patch("superset.databases.api.DatabaseDAO")
|
||||
DatabaseDAO = mocker.patch("superset.databases.api.DatabaseDAO") # noqa: N806
|
||||
DatabaseDAO.find_by_id.return_value = database
|
||||
|
||||
security_manager = mocker.patch(
|
||||
|
||||
@@ -112,7 +112,7 @@ def test_import_database_sqlite_invalid(
|
||||
_ = import_database(config)
|
||||
assert (
|
||||
str(excinfo.value)
|
||||
== "SQLiteDialect_pysqlite cannot be used as a data source for security reasons."
|
||||
== "SQLiteDialect_pysqlite cannot be used as a data source for security reasons." # noqa: E501
|
||||
)
|
||||
# restore app config
|
||||
app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] = True
|
||||
|
||||
@@ -65,7 +65,7 @@ def test_database_filter_full_db_access(mocker: MockerFixture) -> None:
|
||||
mocker.patch.object(security_manager, "can_access_all_databases", return_value=True)
|
||||
|
||||
engine = create_engine("sqlite://")
|
||||
Session = sessionmaker(bind=engine)
|
||||
Session = sessionmaker(bind=engine) # noqa: N806
|
||||
session = Session()
|
||||
query = session.query(Database)
|
||||
|
||||
@@ -108,7 +108,7 @@ def test_database_filter(mocker: MockerFixture) -> None:
|
||||
)
|
||||
|
||||
engine = create_engine("sqlite://")
|
||||
Session = sessionmaker(bind=engine)
|
||||
Session = sessionmaker(bind=engine) # noqa: N806
|
||||
session = Session()
|
||||
query = session.query(Database)
|
||||
|
||||
@@ -124,5 +124,5 @@ def test_database_filter(mocker: MockerFixture) -> None:
|
||||
str(compiled_query)
|
||||
== f"""SELECT dbs.uuid, dbs.created_on, dbs.changed_on, dbs.id, dbs.verbose_name, dbs.database_name, dbs.sqlalchemy_uri, dbs.password, dbs.cache_timeout, dbs.select_as_create_table_as, dbs.expose_in_sqllab, dbs.configuration_method, dbs.allow_run_async, dbs.allow_file_upload, dbs.allow_ctas, dbs.allow_cvas, dbs.allow_dml, dbs.force_ctas_schema, dbs.extra, dbs.encrypted_extra, dbs.impersonate_user, dbs.server_cert, dbs.is_managed_externally, dbs.external_url, dbs.created_by_fk, dbs.changed_by_fk{space}
|
||||
FROM dbs{space}
|
||||
WHERE '[' || dbs.database_name || '].(id:' || CAST(dbs.id AS VARCHAR) || ')' IN ('[my_db].(id:42)', '[my_other_db].(id:43)') OR dbs.database_name IN ('my_db', 'my_other_db', 'third_db')"""
|
||||
WHERE '[' || dbs.database_name || '].(id:' || CAST(dbs.id AS VARCHAR) || ')' IN ('[my_db].(id:42)', '[my_other_db].(id:43)') OR dbs.database_name IN ('my_db', 'my_other_db', 'third_db')""" # noqa: S608, E501
|
||||
)
|
||||
|
||||
@@ -103,14 +103,17 @@ def test_database_parameters_schema_mixin_no_engine(
|
||||
try:
|
||||
dummy_schema.load(payload)
|
||||
except ValidationError as err:
|
||||
assert err.messages == {
|
||||
"_schema": [
|
||||
(
|
||||
"An engine must be specified when passing individual parameters to "
|
||||
"a database."
|
||||
),
|
||||
]
|
||||
}
|
||||
assert ( # noqa: PT017
|
||||
err.messages
|
||||
== { # noqa: PT017
|
||||
"_schema": [
|
||||
(
|
||||
"An engine must be specified when passing individual parameters to " # noqa: E501
|
||||
"a database."
|
||||
),
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_database_parameters_schema_mixin_invalid_engine(
|
||||
@@ -133,7 +136,7 @@ def test_database_parameters_schema_mixin_invalid_engine(
|
||||
try:
|
||||
dummy_schema.load(payload)
|
||||
except ValidationError as err:
|
||||
assert err.messages == {
|
||||
assert err.messages == { # noqa: PT017
|
||||
"_schema": ['Engine "dummy_engine" is not a valid engine.']
|
||||
}
|
||||
|
||||
@@ -158,14 +161,17 @@ def test_database_parameters_schema_no_mixin(
|
||||
try:
|
||||
dummy_schema.load(payload)
|
||||
except ValidationError as err:
|
||||
assert err.messages == {
|
||||
"_schema": [
|
||||
(
|
||||
'Engine spec "InvalidEngine" does not support '
|
||||
"being configured via individual parameters."
|
||||
)
|
||||
]
|
||||
}
|
||||
assert ( # noqa: PT017
|
||||
err.messages
|
||||
== { # noqa: PT017
|
||||
"_schema": [
|
||||
(
|
||||
'Engine spec "InvalidEngine" does not support '
|
||||
"being configured via individual parameters."
|
||||
)
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_database_parameters_schema_mixin_invalid_type(
|
||||
@@ -188,7 +194,7 @@ def test_database_parameters_schema_mixin_invalid_type(
|
||||
try:
|
||||
dummy_schema.load(payload)
|
||||
except ValidationError as err:
|
||||
assert err.messages == {"port": ["Not a valid integer."]}
|
||||
assert err.messages == {"port": ["Not a valid integer."]} # noqa: PT017
|
||||
|
||||
|
||||
def test_rename_encrypted_extra() -> None:
|
||||
|
||||
Reference in New Issue
Block a user