Skip to content

Commit 7227266

Browse files
committed
[TEST] add deleteproject testcase
1 parent ddcdff2 commit 7227266

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/fastapi_fastkit/cli.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ def startproject(
196196
author_email: str,
197197
description: str,
198198
) -> None:
199-
# TODO : add a feature - name project folder name to project_name
200199
"""
201200
Create a new FastAPI project from templates and inject metadata.
202201
@@ -218,12 +217,11 @@ def startproject(
218217
raise CLIExceptions(
219218
f"Error: Template '{template}' does not exist in '{template_dir}'."
220219
)
221-
# TODO : add confirm step : checking template stack & name & metadata, confirm it y/n
222220
click.echo(f"\nProject Name: {project_name}")
223221
click.echo(f"Author: {author}")
224222
click.echo(f"Author Email: {author_email}")
225223
click.echo(f"Description: {description}")
226-
# click.echo("Project Stack: [FastAPI, Uvicorn, SQLAlchemy, Docker (optional)]")
224+
# click.echo("Project Stack: [FastAPI, Uvicorn, SQLAlchemy, Docker (optional)]") # TODO : impl this?
227225

228226
confirm = click.confirm(
229227
"\nDo you want to proceed with project creation?", default=False
@@ -238,7 +236,7 @@ def startproject(
238236

239237
click.echo(f"FastAPI template project will deploy at '{user_local}'")
240238

241-
copy_and_convert_template(target_template, project_dir, project_name)
239+
copy_and_convert_template(target_template, user_local, project_name)
242240

243241
_inject_project_metadata(
244242
project_dir, project_name, author, author_email, description

tests/test_cli_operations/test_cli.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_startproject(self, temp_dir) -> None:
6060
# then
6161
project_path = (
6262
Path(temp_dir) / "test-project"
63-
) # TODO : change this after adding folder naming feature.
63+
)
6464
assert project_path.exists() and project_path.is_dir()
6565
assert (
6666
f"FastAPI project 'test-project' from 'fastapi-default' has been created and saved to {temp_dir}!"
@@ -85,3 +85,39 @@ def test_startproject(self, temp_dir) -> None:
8585
assert "test-project" in setup_py_content
8686
assert "bnbong" in setup_py_content
8787
assert "bbbong9@gmail.com" in setup_py_content
88+
89+
def test_deleteproject(self, temp_dir) -> None:
90+
# given
91+
os.chdir(temp_dir)
92+
project_name = "test-project"
93+
result = self.runner.invoke(
94+
fastkit_cli, # type: ignore
95+
["startproject", "fastapi-default"],
96+
input="\n".join(
97+
[project_name, "bnbong", "bbbong9@gmail.com", "test project", "Y"]
98+
),
99+
)
100+
project_path = (
101+
Path(temp_dir) / project_name
102+
)
103+
assert project_path.exists() and project_path.is_dir()
104+
assert (
105+
f"FastAPI project '{project_name}' from 'fastapi-default' has been created and saved to {temp_dir}!"
106+
in result.output
107+
)
108+
109+
expected_files = ["main.py", "setup.py"]
110+
for file in expected_files:
111+
file_path = project_path / file
112+
assert file_path.exists() and file_path.is_file()
113+
114+
# when
115+
result = self.runner.invoke(
116+
fastkit_cli, # type: ignore
117+
["deleteproject", project_name],
118+
input="Y",
119+
)
120+
121+
# then
122+
assert f"Project '{project_name}' has been successfully deleted" in result.output
123+
assert not project_path.exists()

0 commit comments

Comments
 (0)