mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore: Adds non-interactive mode to superset-extensions init command (#36308)
This commit is contained in:
committed by
GitHub
parent
b12f5f8394
commit
db995ad5bf
@@ -360,3 +360,139 @@ def test_full_init_workflow_integration(cli_runner, isolated_filesystem):
|
||||
|
||||
pyproject_content = (extension_path / "backend" / "pyproject.toml").read_text()
|
||||
assert "awesome_charts" in pyproject_content
|
||||
|
||||
|
||||
# Non-interactive mode tests
|
||||
@pytest.mark.cli
|
||||
def test_init_non_interactive_with_all_options(cli_runner, isolated_filesystem):
|
||||
"""Test that init works in non-interactive mode with all CLI options."""
|
||||
result = cli_runner.invoke(
|
||||
app,
|
||||
[
|
||||
"init",
|
||||
"--id",
|
||||
"my_ext",
|
||||
"--name",
|
||||
"My Extension",
|
||||
"--version",
|
||||
"1.0.0",
|
||||
"--license",
|
||||
"MIT",
|
||||
"--frontend",
|
||||
"--backend",
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0, f"Command failed with output: {result.output}"
|
||||
assert "🎉 Extension My Extension (ID: my_ext) initialized" in result.output
|
||||
|
||||
extension_path = isolated_filesystem / "my_ext"
|
||||
assert_directory_exists(extension_path)
|
||||
assert_directory_exists(extension_path / "frontend")
|
||||
assert_directory_exists(extension_path / "backend")
|
||||
|
||||
extension_json = load_json_file(extension_path / "extension.json")
|
||||
assert extension_json["id"] == "my_ext"
|
||||
assert extension_json["name"] == "My Extension"
|
||||
assert extension_json["version"] == "1.0.0"
|
||||
assert extension_json["license"] == "MIT"
|
||||
|
||||
|
||||
@pytest.mark.cli
|
||||
def test_init_frontend_only_with_cli_options(cli_runner, isolated_filesystem):
|
||||
"""Test init with frontend only using CLI options."""
|
||||
result = cli_runner.invoke(
|
||||
app,
|
||||
[
|
||||
"init",
|
||||
"--id",
|
||||
"frontend_ext",
|
||||
"--name",
|
||||
"Frontend Extension",
|
||||
"--version",
|
||||
"1.0.0",
|
||||
"--license",
|
||||
"MIT",
|
||||
"--frontend",
|
||||
"--no-backend",
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0, f"Command failed with output: {result.output}"
|
||||
|
||||
extension_path = isolated_filesystem / "frontend_ext"
|
||||
assert_directory_exists(extension_path / "frontend")
|
||||
assert not (extension_path / "backend").exists()
|
||||
|
||||
|
||||
@pytest.mark.cli
|
||||
def test_init_backend_only_with_cli_options(cli_runner, isolated_filesystem):
|
||||
"""Test init with backend only using CLI options."""
|
||||
result = cli_runner.invoke(
|
||||
app,
|
||||
[
|
||||
"init",
|
||||
"--id",
|
||||
"backend_ext",
|
||||
"--name",
|
||||
"Backend Extension",
|
||||
"--version",
|
||||
"1.0.0",
|
||||
"--license",
|
||||
"MIT",
|
||||
"--no-frontend",
|
||||
"--backend",
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0, f"Command failed with output: {result.output}"
|
||||
|
||||
extension_path = isolated_filesystem / "backend_ext"
|
||||
assert not (extension_path / "frontend").exists()
|
||||
assert_directory_exists(extension_path / "backend")
|
||||
|
||||
|
||||
@pytest.mark.cli
|
||||
def test_init_prompts_for_missing_options(cli_runner, isolated_filesystem):
|
||||
"""Test that init prompts for options not provided via CLI and uses defaults."""
|
||||
# Provide id and name via CLI, but version/license will be prompted (accept defaults)
|
||||
result = cli_runner.invoke(
|
||||
app,
|
||||
[
|
||||
"init",
|
||||
"--id",
|
||||
"default_ext",
|
||||
"--name",
|
||||
"Default Extension",
|
||||
"--frontend",
|
||||
"--backend",
|
||||
],
|
||||
input="\n\n", # Accept defaults for version and license prompts
|
||||
)
|
||||
|
||||
assert result.exit_code == 0, f"Command failed with output: {result.output}"
|
||||
|
||||
extension_path = isolated_filesystem / "default_ext"
|
||||
extension_json = load_json_file(extension_path / "extension.json")
|
||||
assert extension_json["version"] == "0.1.0"
|
||||
assert extension_json["license"] == "Apache-2.0"
|
||||
|
||||
|
||||
@pytest.mark.cli
|
||||
def test_init_non_interactive_validates_id(cli_runner, isolated_filesystem):
|
||||
"""Test that non-interactive mode validates extension ID."""
|
||||
result = cli_runner.invoke(
|
||||
app,
|
||||
[
|
||||
"init",
|
||||
"--id",
|
||||
"invalid-id",
|
||||
"--name",
|
||||
"Invalid Extension",
|
||||
"--frontend",
|
||||
"--backend",
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 1
|
||||
assert "must be alphanumeric" in result.output
|
||||
|
||||
Reference in New Issue
Block a user