|
4 | 4 | import sys |
5 | 5 | from pathlib import Path |
6 | 6 |
|
| 7 | +import pytest |
| 8 | + |
7 | 9 |
|
8 | 10 | REPO_ROOT = Path(__file__).resolve().parents[1] |
9 | 11 | 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")) |
10 | 29 |
|
11 | 30 |
|
12 | 31 | def test_examples_import_without_side_effects(): |
@@ -37,3 +56,31 @@ def test_smart_cdn_example_runs_without_network(): |
37 | 56 |
|
38 | 57 | assert result.stdout.startswith("https://workspace.tlcdn.com/template/image.jpg?") |
39 | 58 | 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