Skip to content

Commit 14232a7

Browse files
committed
Add integration tests.
1 parent a743118 commit 14232a7

File tree

2 files changed

+101
-11
lines changed

2 files changed

+101
-11
lines changed

src/gds_idea_app_kit/init.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,6 @@ def run_init(framework: str, app_name: str, python_version: str) -> None:
310310
project_dir=project_dir,
311311
)
312312

313-
# -- Install gds-idea-app-kit as dev dependency --
314-
click.echo("Installing gds-idea-app-kit as dev dependency...")
315-
_run_command(
316-
[
317-
"uv", "add", "--dev",
318-
"gds-idea-app-kit @ git+https://github.com/co-cddo/gds-idea-app-kit.git",
319-
],
320-
cwd=project_dir,
321-
project_dir=project_dir,
322-
)
323-
324313
# -- Write [tool.webapp] config for AppConfig.from_pyproject() --
325314
click.echo("Writing project configuration...")
326315
_write_webapp_config(project_dir, app_name, framework)

tests/test_integration.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""Integration tests that run real commands (cdk, uv, git).
2+
3+
These tests require:
4+
- cdk installed (npm install -g aws-cdk)
5+
- uv installed
6+
- git installed
7+
- Network access to GitHub (for private deps)
8+
9+
Run with: uv run pytest -m integration
10+
Skip with: uv run pytest -m "not integration"
11+
"""
12+
13+
import os
14+
import subprocess
15+
import tomllib
16+
17+
import pytest
18+
19+
from gds_idea_app_kit.init import run_init
20+
from gds_idea_app_kit.manifest import read_manifest
21+
22+
23+
@pytest.mark.integration
24+
def test_init_streamlit_end_to_end(tmp_path):
25+
"""Full init creates a working streamlit project with all deps resolved."""
26+
os.chdir(tmp_path)
27+
run_init(framework="streamlit", app_name="integ-test", python_version="3.13")
28+
29+
project = tmp_path / "gds-idea-app-integ-test"
30+
31+
# ---- Project structure ----
32+
33+
assert project.is_dir(), "Project directory should be created"
34+
35+
# CDK files
36+
assert (project / "app.py").exists(), "CDK entry point should exist"
37+
assert (project / "cdk.json").exists(), "cdk.json should exist"
38+
39+
# App source
40+
assert (project / "app_src" / "Dockerfile").exists()
41+
assert (project / "app_src" / "streamlit_app.py").exists()
42+
assert (project / "app_src" / "pyproject.toml").exists()
43+
44+
# Dev container
45+
assert (project / ".devcontainer" / "devcontainer.json").exists()
46+
assert (project / ".devcontainer" / "docker-compose.yml").exists()
47+
48+
# Dev mocks
49+
assert (project / "dev_mocks" / "dev_mock_authoriser.json").exists()
50+
assert (project / "dev_mocks" / "dev_mock_user.json").exists()
51+
52+
# ---- Template variables substituted ----
53+
54+
dockerfile = (project / "app_src" / "Dockerfile").read_text()
55+
assert "python:3.13" in dockerfile, "Python version should be substituted in Dockerfile"
56+
assert "{{python_version}}" not in dockerfile, "Template placeholder should not remain"
57+
58+
app_pyproject = (project / "app_src" / "pyproject.toml").read_text()
59+
assert "integ-test" in app_pyproject, "App name should be substituted in pyproject.toml"
60+
assert "{{app_name}}" not in app_pyproject, "Template placeholder should not remain"
61+
62+
# ---- Root pyproject.toml config ----
63+
64+
with open(project / "pyproject.toml", "rb") as f:
65+
root_config = tomllib.load(f)
66+
67+
webapp = root_config.get("tool", {}).get("webapp", {})
68+
assert webapp.get("framework") == "streamlit"
69+
assert webapp.get("app_name") == "integ-test"
70+
71+
# ---- Manifest ----
72+
73+
manifest = read_manifest(project)
74+
assert manifest, "Manifest should be written"
75+
assert manifest["framework"] == "streamlit"
76+
assert manifest["app_name"] == "integ-test"
77+
assert "files" in manifest, "Manifest should contain file hashes"
78+
assert len(manifest["files"]) > 0, "Manifest should track at least one file"
79+
80+
# ---- Dependencies resolved ----
81+
82+
assert (project / "uv.lock").exists(), "uv.lock should be created by uv sync"
83+
assert (project / ".venv").is_dir(), ".venv should be created by uv sync"
84+
85+
# ---- Git history ----
86+
87+
result = subprocess.run(
88+
["git", "log", "--oneline"],
89+
cwd=project,
90+
capture_output=True,
91+
text=True,
92+
check=True,
93+
)
94+
assert "Initial scaffold" in result.stdout, "Initial commit should exist"
95+
assert "streamlit" in result.stdout, "Commit message should mention the framework"
96+
97+
# ---- .gitignore ----
98+
99+
gitignore = (project / ".gitignore").read_text()
100+
assert ".aws-dev" in gitignore, ".aws-dev should be in gitignore"
101+
assert "*.new" in gitignore, "*.new files should be in gitignore"

0 commit comments

Comments
 (0)