Skip to content

Commit d88b2e5

Browse files
author
Brian Obot
committed
Improve on Unit test for testing get_project_detail function
1 parent 8ca0be2 commit d88b2e5

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/fastapi_gen8/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ def generate_default_project_details() -> dict[str, str | int | tuple]:
4343
"name": "My Awesome FastAPI Project",
4444
"slug_name": "my_awesome_fastapi_project",
4545
"description": "FastAPI Project Description",
46-
"author(s)": ("John Doe", "Jane Doe"),
46+
"author(s)": "John Doe",
4747
"virtual_env_folder_name": "venv",
4848
"version": "0.1.0",
4949
"email": "brianobot9@gmail.com",
5050
"repository_link": "",
51-
"open_source_license": ("1", [
51+
"open_source_license": (1, [
5252
(1, "MIT"),
5353
(2, "BSD"),
5454
(3, "GPLv3"),
@@ -64,7 +64,7 @@ def get_project_detail(
6464
project_detail: dict[str, str | int | tuple]
6565
) -> str | int | tuple[str, ...]:
6666
"""
67-
This functions gets a project detail from the user via the command line interface, if nothing is provided
67+
Get a project detail (attr) from the user via the command line interface, if nothing is provided
6868
the default value is used for the project detail value.
6969
"""
7070

src/fastapi_gen8/tests/test_main.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import unittest.mock
33

4+
from typing import cast
45
from fastapi_gen8 import main
56

67

@@ -23,15 +24,15 @@ def test_generate_default_project_details():
2324
@pytest.mark.parametrize(
2425
"attr,default_value,project_detail",
2526
[
26-
("name", "My Awesome FastAPI Project Test", main.generate_default_project_details()),
27-
("slug_name", "my_awesome_fastapi_project_test", main.generate_default_project_details()),
28-
("description", "FastAPI Project Description", main.generate_default_project_details()),
29-
("author(s)", ("John Doe", "Jane Doe"), main.generate_default_project_details()),
30-
("virtual_env_folder_name", "venv", main.generate_default_project_details()),
31-
("version", "0.0.1", main.generate_default_project_details()),
32-
("email", "brianobot9@gmail.com", main.generate_default_project_details()),
33-
("repository_url", "Default Name", main.generate_default_project_details()),
34-
("open_source_license", ("1", [
27+
# ("name", "My Awesome FastAPI Project Test", main.generate_default_project_details()),
28+
# ("slug_name", "my_awesome_fastapi_project_test", main.generate_default_project_details()),
29+
# ("description", "FastAPI Project Description", main.generate_default_project_details()),
30+
# ("author(s)", "John Doe", main.generate_default_project_details()),
31+
# ("virtual_env_folder_name", "venv", main.generate_default_project_details()),
32+
# ("version", "0.0.1", main.generate_default_project_details()),
33+
# ("email", "brianobot9@gmail.com", main.generate_default_project_details()),
34+
# ("repository_url", "Default Name", main.generate_default_project_details()),
35+
("open_source_license", (1, [
3536
(1, "MIT"),
3637
(2, "BSD"),
3738
(3, "GPLv3"),
@@ -45,5 +46,11 @@ def test_get_project_detail(attr: str, default_value: str | int | tuple, project
4546
result = main.get_project_detail(attr, default_value, project_detail)
4647
print("✅ Response: ", result)
4748
# assert None
48-
assert result == default_value
49+
if isinstance(default_value, tuple):
50+
print("Default Value is a Tuple")
51+
default_value = cast(tuple, default_value)
52+
assert result == cast(list, default_value[1])[default_value[0]][1]
53+
else:
54+
print("Default Value is not a Tuple")
55+
assert result == default_value
4956
assert isinstance(result, str | int | tuple)

0 commit comments

Comments
 (0)