Skip to content

Commit 4e60a8f

Browse files
committed
[FIX] fix testcase
1 parent b204f17 commit 4e60a8f

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

tests/test_cli_operations/test_cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,14 @@ def test_startdemo_cancel_confirmation(self, temp_dir: str) -> None:
136136
fastkit_cli,
137137
["startdemo", "fastapi-default"],
138138
input="\n".join(
139-
["test-project", "bnbong", "[email protected]", "test project", "N"]
139+
[
140+
"test-project",
141+
"bnbong",
142+
143+
"test project",
144+
"uv",
145+
"N",
146+
]
140147
),
141148
)
142149

tests/test_cli_operations/test_cli_extended.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,37 @@ def test_version_command(self) -> None:
4242
# Version command might not exist, but shouldn't crash
4343
assert result.exit_code in [0, 2] # 0 for success, 2 for no such option
4444

45-
@patch("fastapi_fastkit.backend.main.inject_project_metadata")
46-
@patch("fastapi_fastkit.backend.transducer.copy_and_convert_template_file")
47-
@patch("fastapi_fastkit.backend.main.create_venv_with_manager")
48-
@patch("fastapi_fastkit.backend.main.install_dependencies_with_manager")
49-
@patch("fastapi_fastkit.backend.main.generate_dependency_file_with_manager")
45+
@patch("subprocess.run")
5046
@patch("fastapi_fastkit.backend.package_managers.uv_manager.UvManager.is_available")
5147
def test_init_standard_stack(
5248
self,
5349
mock_uv_available: MagicMock,
54-
mock_generate_dependency: MagicMock,
55-
mock_install: MagicMock,
56-
mock_venv: MagicMock,
57-
mock_copy: MagicMock,
58-
mock_inject: MagicMock,
50+
mock_subprocess: MagicMock,
5951
temp_dir: str,
6052
) -> None:
6153
"""Test init command with standard stack."""
6254
# given
6355
os.chdir(temp_dir)
64-
mock_venv.return_value = "/fake/venv"
6556
mock_uv_available.return_value = True
6657

58+
# Mock subprocess.run to simulate venv creation and dependency installation
59+
def mock_subprocess_side_effect(*args, **kwargs) -> MagicMock: # type: ignore
60+
cmd = args[0] if args else kwargs.get("args", [])
61+
if isinstance(cmd, list) and len(cmd) > 0:
62+
# Simulate venv creation by creating the directory
63+
if cmd[0] == "uv" and "venv" in cmd:
64+
venv_path = Path(temp_dir) / "test-standard" / ".venv"
65+
venv_path.mkdir(parents=True, exist_ok=True)
66+
# Create bin directory for Unix-like systems
67+
(venv_path / "bin").mkdir(exist_ok=True)
68+
(venv_path / "Scripts").mkdir(
69+
exist_ok=True
70+
) # For Windows compatibility
71+
72+
return MagicMock(returncode=0, stdout="", stderr="")
73+
74+
mock_subprocess.side_effect = mock_subprocess_side_effect
75+
6776
# when
6877
result = self.runner.invoke(
6978
fastkit_cli,
@@ -86,6 +95,9 @@ def test_init_standard_stack(
8695
assert project_path.exists()
8796
assert "Success" in result.output
8897

98+
# Verify that subprocess.run was called for venv and dependency operations
99+
assert mock_subprocess.call_count >= 2
100+
89101
def test_addroute_command(self, temp_dir: str) -> None:
90102
"""Test addroute command behavior."""
91103
# given

0 commit comments

Comments
 (0)