mirror of
https://github.com/apache/superset.git
synced 2026-04-14 05:34:38 +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
@@ -118,7 +118,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
db.session.commit()
|
||||
return database
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def create_database_with_report(self):
|
||||
with self.create_app().app_context():
|
||||
example_db = get_example_database()
|
||||
@@ -142,7 +142,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
db.session.delete(database)
|
||||
db.session.commit()
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def create_database_with_dataset(self):
|
||||
with self.create_app().app_context():
|
||||
example_db = get_example_database()
|
||||
@@ -332,7 +332,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
.filter(SSHTunnel.database_id == response.get("id"))
|
||||
.one()
|
||||
)
|
||||
assert response.get("result")["ssh_tunnel"]["password"] == "XXXXXXXXXX"
|
||||
assert response.get("result")["ssh_tunnel"]["password"] == "XXXXXXXXXX" # noqa: S105
|
||||
assert model_ssh_tunnel.database_id == response.get("id")
|
||||
# Cleanup
|
||||
model = db.session.query(Database).get(response.get("id"))
|
||||
@@ -669,7 +669,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
.one()
|
||||
)
|
||||
assert model_ssh_tunnel.database_id == response_update.get("id")
|
||||
assert response_update.get("result")["ssh_tunnel"]["password"] == "XXXXXXXXXX"
|
||||
assert response_update.get("result")["ssh_tunnel"]["password"] == "XXXXXXXXXX" # noqa: S105
|
||||
assert model_ssh_tunnel.username == "Test"
|
||||
assert model_ssh_tunnel.server_address == "123.132.123.1"
|
||||
assert model_ssh_tunnel.server_port == 8080
|
||||
@@ -1132,7 +1132,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
example_db = get_example_database()
|
||||
if example_db.backend in ("sqlite", "hive", "presto"):
|
||||
return
|
||||
example_db.password = "wrong_password"
|
||||
example_db.password = "wrong_password" # noqa: S105
|
||||
database_data = {
|
||||
"database_name": "test-create-database-wrong-password",
|
||||
"sqlalchemy_uri": example_db.sqlalchemy_uri_decrypted,
|
||||
@@ -1160,7 +1160,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
{
|
||||
"code": 1015,
|
||||
"message": (
|
||||
"Issue 1015 - Issue 1015 - Either the database is spelled incorrectly or does not exist."
|
||||
"Issue 1015 - Issue 1015 - Either the database is spelled incorrectly or does not exist." # noqa: E501
|
||||
),
|
||||
},
|
||||
],
|
||||
@@ -1177,7 +1177,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
{
|
||||
"code": 1013,
|
||||
"message": (
|
||||
"Issue 1013 - The password provided when connecting to a database is not valid."
|
||||
"Issue 1013 - The password provided when connecting to a database is not valid." # noqa: E501
|
||||
),
|
||||
}
|
||||
],
|
||||
@@ -1225,7 +1225,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
test_database = self.insert_database(
|
||||
"test-database1", example_db.sqlalchemy_uri_decrypted
|
||||
)
|
||||
example_db.password = "wrong_password"
|
||||
example_db.password = "wrong_password" # noqa: S105
|
||||
database_data = {
|
||||
"sqlalchemy_uri": example_db.sqlalchemy_uri_decrypted,
|
||||
}
|
||||
@@ -1771,7 +1771,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
db.session.delete(database)
|
||||
db.session.commit()
|
||||
|
||||
def mock_csv_function(d, user):
|
||||
def mock_csv_function(d, user): # noqa: N805
|
||||
return d.get_all_schema_names()
|
||||
|
||||
@mock.patch(
|
||||
@@ -1818,7 +1818,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
db.session.delete(database)
|
||||
db.session.commit()
|
||||
|
||||
def mock_empty_csv_function(d, user):
|
||||
def mock_empty_csv_function(d, user): # noqa: N805
|
||||
return []
|
||||
|
||||
@mock.patch(
|
||||
@@ -1979,7 +1979,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
|
||||
schema_name = self.default_schema_backend_map[database.backend]
|
||||
rv = self.client.get(
|
||||
f"api/v1/database/{database.id}/tables/?q={prison.dumps({'schema_name': schema_name})}"
|
||||
f"api/v1/database/{database.id}/tables/?q={prison.dumps({'schema_name': schema_name})}" # noqa: E501
|
||||
)
|
||||
|
||||
assert rv.status_code == 200
|
||||
@@ -2001,7 +2001,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"""
|
||||
self.login(GAMMA_USERNAME)
|
||||
example_db = get_example_database()
|
||||
uri = f"api/v1/database/{example_db.id}/tables/?q={prison.dumps({'schema_name': 'non_existent'})}"
|
||||
uri = f"api/v1/database/{example_db.id}/tables/?q={prison.dumps({'schema_name': 'non_existent'})}" # noqa: E501
|
||||
rv = self.client.get(uri)
|
||||
assert rv.status_code == 404
|
||||
logger_mock.warning.assert_called_once_with(
|
||||
@@ -2033,7 +2033,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
mock_can_access_database.side_effect = Exception("Test Error")
|
||||
|
||||
rv = self.client.get(
|
||||
f"api/v1/database/{database.id}/tables/?q={prison.dumps({'schema_name': 'main'})}"
|
||||
f"api/v1/database/{database.id}/tables/?q={prison.dumps({'schema_name': 'main'})}" # noqa: E501
|
||||
)
|
||||
assert rv.status_code == 422
|
||||
logger_mock.warning.assert_called_once_with("Test Error", exc_info=True)
|
||||
@@ -2105,7 +2105,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"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
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2134,7 +2134,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"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
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2163,7 +2163,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
expected_response = {
|
||||
"message": {
|
||||
"sqlalchemy_uri": [
|
||||
"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
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -2183,7 +2183,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"""
|
||||
Database API: Test test connection failed due to invalid hostname
|
||||
"""
|
||||
msg = 'psql: error: could not translate host name "localhost_" to address: nodename nor servname provided, or not known'
|
||||
msg = 'psql: error: could not translate host name "localhost_" to address: nodename nor servname provided, or not known' # noqa: E501
|
||||
mock_build_db.return_value.set_sqlalchemy_uri.side_effect = DBAPIError(
|
||||
msg, None, None
|
||||
)
|
||||
@@ -2361,27 +2361,30 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing database",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"databases/imported_database.yaml": "Database 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 database",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"databases/imported_database.yaml": "Database 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_database_import()
|
||||
@@ -2555,7 +2558,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
database.sqlalchemy_uri
|
||||
== "vertica+vertica_python://hackathon:XXXXXXXXXX@host:5433/dbname?ssl=1"
|
||||
)
|
||||
assert database.password == "SECRET"
|
||||
assert database.password == "SECRET" # noqa: S105
|
||||
|
||||
db.session.delete(database)
|
||||
db.session.commit()
|
||||
@@ -2668,7 +2671,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
.filter(SSHTunnel.database_id == database.id)
|
||||
.one()
|
||||
)
|
||||
assert model_ssh_tunnel.password == "TEST"
|
||||
assert model_ssh_tunnel.password == "TEST" # noqa: S105
|
||||
db.session.delete(database)
|
||||
db.session.commit()
|
||||
|
||||
@@ -2709,32 +2712,35 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing database",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"databases/imported_database.yaml": {
|
||||
"_schema": [
|
||||
"Must provide a private key for the ssh tunnel",
|
||||
"Must provide a private key password for the ssh tunnel",
|
||||
]
|
||||
assert (
|
||||
response
|
||||
== {
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing database",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"databases/imported_database.yaml": {
|
||||
"_schema": [
|
||||
"Must provide a private key for the ssh tunnel",
|
||||
"Must provide a private key password for the ssh tunnel", # noqa: E501
|
||||
]
|
||||
},
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
@mock.patch("superset.databases.schemas.is_feature_enabled")
|
||||
@mock.patch("superset.commands.database.importers.v1.utils.add_permissions")
|
||||
@@ -2787,7 +2793,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
.one()
|
||||
)
|
||||
assert model_ssh_tunnel.private_key == "TestPrivateKey"
|
||||
assert model_ssh_tunnel.private_key_password == "TEST"
|
||||
assert model_ssh_tunnel.private_key_password == "TEST" # noqa: S105
|
||||
db.session.delete(database)
|
||||
db.session.commit()
|
||||
|
||||
@@ -3001,32 +3007,35 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing database",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"databases/imported_database.yaml": {
|
||||
"_schema": [
|
||||
"Must provide a private key for the ssh tunnel",
|
||||
"Must provide a private key password for the ssh tunnel",
|
||||
]
|
||||
assert (
|
||||
response
|
||||
== {
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing database",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"databases/imported_database.yaml": {
|
||||
"_schema": [
|
||||
"Must provide a private key for the ssh tunnel",
|
||||
"Must provide a private key password for the ssh tunnel", # noqa: E501
|
||||
]
|
||||
},
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
@mock.patch(
|
||||
"superset.db_engine_specs.base.BaseEngineSpec.get_function_names",
|
||||
@@ -3210,7 +3219,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"type": "string",
|
||||
},
|
||||
"encryption": {
|
||||
"description": "Use an encrypted connection to the database",
|
||||
"description": "Use an encrypted connection to the database", # noqa: E501
|
||||
"type": "boolean",
|
||||
},
|
||||
"host": {
|
||||
@@ -3234,7 +3243,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"type": "object",
|
||||
},
|
||||
"ssh": {
|
||||
"description": "Use an ssh tunnel connection to the database",
|
||||
"description": "Use an ssh tunnel connection to the database", # noqa: E501
|
||||
"type": "boolean",
|
||||
},
|
||||
"username": {
|
||||
@@ -3294,7 +3303,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"type": "string",
|
||||
},
|
||||
"encryption": {
|
||||
"description": "Use an encrypted connection to the database",
|
||||
"description": "Use an encrypted connection to the database", # noqa: E501
|
||||
"type": "boolean",
|
||||
},
|
||||
"host": {
|
||||
@@ -3318,7 +3327,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"type": "object",
|
||||
},
|
||||
"ssh": {
|
||||
"description": "Use an ssh tunnel connection to the database",
|
||||
"description": "Use an ssh tunnel connection to the database", # noqa: E501
|
||||
"type": "boolean",
|
||||
},
|
||||
"username": {
|
||||
@@ -3378,7 +3387,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"type": "string",
|
||||
},
|
||||
"encryption": {
|
||||
"description": "Use an encrypted connection to the database",
|
||||
"description": "Use an encrypted connection to the database", # noqa: E501
|
||||
"type": "boolean",
|
||||
},
|
||||
"host": {
|
||||
@@ -3402,7 +3411,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"type": "object",
|
||||
},
|
||||
"ssh": {
|
||||
"description": "Use an ssh tunnel connection to the database",
|
||||
"description": "Use an ssh tunnel connection to the database", # noqa: E501
|
||||
"type": "boolean",
|
||||
},
|
||||
"username": {
|
||||
@@ -3507,7 +3516,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1019,
|
||||
"message": "Issue 1019 - The submitted payload has the incorrect format.",
|
||||
"message": "Issue 1019 - The submitted payload has the incorrect format.", # noqa: E501
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -3606,7 +3615,10 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
@mock.patch("superset.db_engine_specs.base.is_port_open")
|
||||
@mock.patch("superset.databases.api.ValidateDatabaseParametersCommand")
|
||||
def test_validate_parameters_valid_payload(
|
||||
self, ValidateDatabaseParametersCommand, is_port_open, is_hostname_valid
|
||||
self,
|
||||
ValidateDatabaseParametersCommand, # noqa: N803
|
||||
is_port_open,
|
||||
is_hostname_valid, # noqa: N803
|
||||
):
|
||||
is_hostname_valid.return_value = True
|
||||
is_port_open.return_value = True
|
||||
@@ -3786,13 +3798,13 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1018,
|
||||
"message": "Issue 1018 - One or more parameters needed to configure a database are missing.",
|
||||
"message": "Issue 1018 - One or more parameters needed to configure a database are missing.", # noqa: E501
|
||||
}
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"message": "The port must be an integer between 0 and 65535 (inclusive).",
|
||||
"message": "The port must be an integer between 0 and 65535 (inclusive).", # noqa: E501
|
||||
"error_type": "CONNECTION_INVALID_PORT_ERROR",
|
||||
"level": "error",
|
||||
"extra": {
|
||||
|
||||
Reference in New Issue
Block a user