Skip to content

Commit 7d6f968

Browse files
ulises-jeremiasulises-jeremias
andauthored
test(cli): integration tests scaffolding from cpa-templates (#143)
Closes #139 Co-authored-by: ulises-jeremias <ulises.jeremias@users.noreply.github.com>
1 parent 42c7f7a commit 7d6f968

3 files changed

Lines changed: 115 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13+
- name: Checkout cpa-templates
14+
uses: actions/checkout@v4
15+
with:
16+
repository: Create-Python-App/cpa-templates
17+
path: cpa-templates
1318
- uses: astral-sh/setup-uv@v6
1419
with:
1520
enable-cache: true
1621
- uses: actions/setup-python@v5
1722
with:
1823
python-version-file: .python-version
1924
- run: uv sync --group dev
20-
- run: uv run pytest --cov --cov-report=term-missing
25+
- name: Run tests
26+
env:
27+
CPA_TEMPLATES_ROOT: ${{ github.workspace }}/cpa-templates
28+
run: uv run pytest --cov --cov-report=term-missing

CONTRIBUTING.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ make typecheck
2424

2525
## Templates
2626

27-
Template bank work will live in `cpa-templates` (tracked in #44). Until then use `fixtures/`.
27+
Template and extension authoring lives in [`cpa-templates`](https://github.com/Create-Python-App/cpa-templates).
28+
29+
To test scaffolding against a local `cpa-templates` checkout:
30+
31+
```bash
32+
export CPA_TEMPLATES_ROOT=/path/to/cpa-templates
33+
uv run pytest packages/create-awesome-python-app/tests/test_cpa_templates_integration.py -v
34+
```
35+
36+
The catalog is fetched from `cpa-templates` `templates.json` (override with `CPA_CATALOG_URL`).
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""Integration tests against the cpa-templates bank."""
2+
3+
from __future__ import annotations
4+
5+
import os
6+
import subprocess
7+
from pathlib import Path
8+
9+
import pytest
10+
11+
_REPO_ROOT = Path(__file__).resolve().parents[4]
12+
_DEFAULT_CPA_TEMPLATES = (_REPO_ROOT.parent / "cpa-templates").resolve()
13+
CPA_TEMPLATES_ROOT = Path(
14+
os.environ.get("CPA_TEMPLATES_ROOT", str(_DEFAULT_CPA_TEMPLATES))
15+
).resolve()
16+
FASTAPI_TEMPLATE = CPA_TEMPLATES_ROOT / "templates" / "fastapi-starter"
17+
GITHUB_SETUP = CPA_TEMPLATES_ROOT / "extensions" / "github-setup"
18+
19+
20+
def _cpa_templates_available() -> bool:
21+
return (FASTAPI_TEMPLATE / "pyproject.toml").is_file()
22+
23+
24+
@pytest.mark.skipif(
25+
not _cpa_templates_available(),
26+
reason="cpa-templates checkout not available (set CPA_TEMPLATES_ROOT)",
27+
)
28+
def test_scaffold_fastapi_starter_from_cpa_templates(
29+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
30+
) -> None:
31+
monkeypatch.setenv("CI", "1")
32+
monkeypatch.setenv("CPA_SKIP_GIT", "1")
33+
dest = tmp_path / "api"
34+
template_url = f"file://{CPA_TEMPLATES_ROOT}?subdir=templates/fastapi-starter"
35+
36+
result = subprocess.run(
37+
[
38+
"uv",
39+
"run",
40+
"create-awesome-python-app",
41+
"--template",
42+
template_url,
43+
"--no-interactive",
44+
"--no-install",
45+
str(dest),
46+
],
47+
cwd=_REPO_ROOT,
48+
capture_output=True,
49+
text=True,
50+
check=False,
51+
)
52+
assert result.returncode == 0, result.stdout + result.stderr
53+
assert (dest / "app" / "main.py").is_file()
54+
assert (dest / "pyproject.toml").is_file()
55+
56+
sync = subprocess.run(["uv", "sync"], cwd=dest, capture_output=True, text=True)
57+
assert sync.returncode == 0, sync.stderr
58+
59+
lint = subprocess.run(["uv", "run", "ruff", "check", "."], cwd=dest, capture_output=True, text=True)
60+
assert lint.returncode == 0, lint.stderr
61+
62+
tests = subprocess.run(["uv", "run", "pytest", "-q"], cwd=dest, capture_output=True, text=True)
63+
assert tests.returncode == 0, tests.stdout + tests.stderr
64+
65+
66+
@pytest.mark.skipif(
67+
not (_cpa_templates_available() and GITHUB_SETUP.is_dir()),
68+
reason="cpa-templates extensions not available",
69+
)
70+
def test_scaffold_fastapi_with_github_setup_extension(
71+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
72+
) -> None:
73+
monkeypatch.setenv("CI", "1")
74+
monkeypatch.setenv("CPA_SKIP_GIT", "1")
75+
dest = tmp_path / "api-ext"
76+
repo = CPA_TEMPLATES_ROOT
77+
result = subprocess.run(
78+
[
79+
"uv",
80+
"run",
81+
"create-awesome-python-app",
82+
"--template",
83+
f"file://{repo}?subdir=templates/fastapi-starter",
84+
"--addons",
85+
f"file://{repo}?subdir=extensions/github-setup",
86+
"--no-interactive",
87+
"--no-install",
88+
str(dest),
89+
],
90+
cwd=_REPO_ROOT,
91+
capture_output=True,
92+
text=True,
93+
check=False,
94+
)
95+
assert result.returncode == 0, result.stdout + result.stderr
96+
assert (dest / ".github" / "workflows" / "ci.yml").is_file()

0 commit comments

Comments
 (0)