Skip to content

Commit f84519d

Browse files
added tests and fastapi typed version
1 parent e9b23c4 commit f84519d

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

packages/create-awesome-python-app/tests/test_catalog_fetch.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import json
6+
import os
67
from pathlib import Path
78
from unittest.mock import patch
89

@@ -18,6 +19,11 @@
1819
FIXTURE_PATH = (
1920
Path(__file__).resolve().parents[3] / "fixtures" / "catalog" / "templates.json"
2021
)
22+
REPO_ROOT = Path(__file__).resolve().parents[3]
23+
_DEFAULT_CPA_TEMPLATES = (REPO_ROOT.parent / "cpa-templates").resolve()
24+
CPA_TEMPLATES_ROOT = Path(
25+
os.environ.get("CPA_TEMPLATES_ROOT", str(_DEFAULT_CPA_TEMPLATES))
26+
).resolve()
2127

2228

2329
@pytest.fixture(autouse=True)
@@ -81,5 +87,14 @@ def test_get_catalog_data_disk_fallback_on_network_error(
8187
assert data["templates"][0]["slug"] == "cached"
8288

8389

90+
def test_local_cpa_templates_catalog_includes_typed_fastapi_template() -> None:
91+
catalog_path = CPA_TEMPLATES_ROOT / "templates.json"
92+
assert catalog_path.is_file()
93+
94+
payload = json.loads(catalog_path.read_text(encoding="utf-8"))
95+
96+
assert any(template["slug"] == "fastapi-typed-starter" for template in payload["templates"])
97+
98+
8499
def test_default_url_points_to_cpa_templates() -> None:
85100
assert DEFAULT_CATALOG_URL.endswith("/cpa-templates/main/templates.json")

packages/create-python-app-core/src/create_python_app_core/paths.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dataclasses import dataclass
88
from pathlib import Path
99
from urllib.parse import parse_qs, unquote, urlparse
10+
from urllib.request import url2pathname
1011

1112
from create_python_app_core.errors import CpaError
1213

@@ -54,10 +55,14 @@ def resolve_source(spec: str, *, cache_dir: Path | None = None) -> ResolvedSourc
5455
if spec.startswith("file://"):
5556
parsed = urlparse(spec)
5657
query = parse_qs(parsed.query)
57-
path = Path(unquote(parsed.path))
58+
raw_path = unquote(parsed.path or "/")
5859
if parsed.netloc and parsed.netloc != "localhost":
5960
# file://host/path — uncommon; treat netloc+path
60-
path = Path(f"/{parsed.netloc}{unquote(parsed.path)}")
61+
raw_path = f"//{parsed.netloc}{raw_path}"
62+
path_text = url2pathname(raw_path)
63+
if os.name == "nt" and re.match(r"^/[A-Za-z]:", path_text):
64+
path_text = path_text[1:]
65+
path = Path(path_text)
6166
subdir = (query.get("subdir") or [None])[0]
6267
return ResolvedSource(
6368
kind="file",

packages/create-python-app-core/tests/test_paths.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from pathlib import Path
23

34
import pytest
@@ -18,6 +19,16 @@ def test_file_url(tmp_path: Path) -> None:
1819
assert src.subdir == "templates/foo"
1920

2021

22+
def test_windows_drive_letter_file_url() -> None:
23+
if os.name != "nt":
24+
pytest.skip("Windows path handling is only relevant on Windows")
25+
26+
src = resolve_source("file:///E:/create-python/cpa-templates?subdir=templates/foo")
27+
assert src.kind == "file"
28+
assert src.subdir == "templates/foo"
29+
assert src.local_path == Path(r"E:\create-python\cpa-templates")
30+
31+
2132
def test_github_url_with_ref() -> None:
2233
src = resolve_source("https://github.com/org/repo?ref=main&subdir=templates/x")
2334
assert src.kind == "github"

0 commit comments

Comments
 (0)