Skip to content

Commit 51fdac5

Browse files
committed
Run quickstart examples in CI
1 parent dc77820 commit 51fdac5

4 files changed

Lines changed: 55 additions & 5 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ jobs:
127127
exit 1
128128
fi
129129
130-
- name: Run E2E tests
130+
- name: Run E2E tests and examples
131131
env:
132132
TEST_NODE_PARITY: 0
133133
run: |
134-
poetry run pytest tests/test_e2e_upload.py -q --maxfail=1 --no-cov
134+
poetry run pytest tests/test_e2e_upload.py tests/test_examples.py -q --maxfail=1 --no-cov

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ This script will:
8484
- install Poetry, Node.js 24, and the Transloadit CLI
8585
- pass credentials from `.env` (if present) so end-to-end tests can run against real Transloadit accounts
8686

87-
Signature parity tests use `npx transloadit smart_sig` under the hood, matching the reference implementation used by our other SDKs. Our GitHub Actions workflow also runs the E2E upload against Python 3.14 on every push/PR using a dedicated Transloadit test account (wired through the `TRANSLOADIT_KEY` and `TRANSLOADIT_SECRET` secrets).
87+
Signature parity tests use `npx transloadit smart_sig` under the hood, matching the reference implementation used by our other SDKs. Our GitHub Actions workflow also runs the E2E upload and quickstart examples against Python 3.14 on every push/PR using a dedicated Transloadit test account (wired through the `TRANSLOADIT_KEY` and `TRANSLOADIT_SECRET` secrets).
8888

8989
Pass `--python 3.14` (or set `PYTHON_VERSIONS`) to restrict the matrix, or append a custom command after `--`, for example `scripts/test-in-docker.sh -- pytest -k smartcdn`.
9090

9191
To exercise the optional end-to-end upload against a real Transloadit account, provide `TRANSLOADIT_KEY` and `TRANSLOADIT_SECRET` (via environment variables or `.env`) and set `PYTHON_SDK_E2E=1`:
9292

9393
```bash
94-
PYTHON_SDK_E2E=1 scripts/test-in-docker.sh --python 3.14 -- pytest tests/test_e2e_upload.py
94+
PYTHON_SDK_E2E=1 scripts/test-in-docker.sh --python 3.14 -- pytest tests/test_e2e_upload.py tests/test_examples.py
9595
```
9696

97-
The test uploads `chameleon.jpg`, resizes it, and asserts on the live assembly results.
97+
The tests upload `chameleon.jpg`, run the copy/paste quickstart examples, and assert on the live assembly results.
9898

9999
If you have a global installation of `poetry`, you can run the tests with:
100100

‎examples/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ poetry run python examples/smart_cdn_url.py
2222
`smart_cdn_url.py` only signs a URL locally. The other quickstart examples contact
2323
Transloadit and may create temporary Assemblies or Templates in your account.
2424

25+
These quickstart examples run in CI against a dedicated Transloadit test account, so they
26+
are kept in sync with the SDK and API.
27+
2528
## Advanced Examples
2629

2730
These examples require pre-created Templates and, depending on your Template, third-party

‎tests/test_examples.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,28 @@
44
import sys
55
from pathlib import Path
66

7+
import pytest
8+
79

810
REPO_ROOT = Path(__file__).resolve().parents[1]
911
EXAMPLES_ROOT = REPO_ROOT / "examples"
12+
QUICKSTART_EXAMPLES = [
13+
"image_resize.py",
14+
"async_image_resize.py",
15+
"resumable_upload.py",
16+
"assembly_with_template.py",
17+
"template_lifecycle.py",
18+
"smart_cdn_url.py",
19+
]
20+
21+
22+
def _is_e2e_enabled():
23+
flag = os.getenv("PYTHON_SDK_E2E", "")
24+
return flag.lower() in {"1", "true", "yes", "on"}
25+
26+
27+
def _has_credentials():
28+
return bool(os.getenv("TRANSLOADIT_KEY") and os.getenv("TRANSLOADIT_SECRET"))
1029

1130

1231
def test_examples_import_without_side_effects():
@@ -37,3 +56,31 @@ def test_smart_cdn_example_runs_without_network():
3756

3857
assert result.stdout.startswith("https://workspace.tlcdn.com/template/image.jpg?")
3958
assert "sig=sha256%3A" in result.stdout
59+
60+
61+
@pytest.mark.e2e
62+
@pytest.mark.skipif(not _is_e2e_enabled(), reason="Set PYTHON_SDK_E2E=1 to run live examples")
63+
@pytest.mark.skipif(
64+
not _has_credentials(),
65+
reason="TRANSLOADIT_KEY and TRANSLOADIT_SECRET must be set to run live examples",
66+
)
67+
@pytest.mark.parametrize("example_name", QUICKSTART_EXAMPLES)
68+
def test_quickstart_example_runs_against_transloadit(example_name):
69+
env = {
70+
**os.environ,
71+
"PYTHONPATH": str(REPO_ROOT),
72+
}
73+
result = subprocess.run(
74+
[sys.executable, f"examples/{example_name}"],
75+
cwd=REPO_ROOT,
76+
env=env,
77+
text=True,
78+
capture_output=True,
79+
)
80+
81+
assert result.returncode == 0, (
82+
f"{example_name} failed with exit code {result.returncode}\n"
83+
f"STDOUT:\n{result.stdout}\n"
84+
f"STDERR:\n{result.stderr}"
85+
)
86+
assert result.stdout.strip(), f"{example_name} completed without printing output"

0 commit comments

Comments
 (0)