mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-09-30 19:33:12 +00:00
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
|
|
"""package_lambdas.py zip layout without a full pip install."""
|
||
|
|
|
||
|
|
import importlib.util
|
||
|
|
import sys
|
||
|
|
import zipfile
|
||
|
|
from pathlib import Path
|
||
|
|
from unittest.mock import patch
|
||
|
|
|
||
|
|
ROOT = Path(__file__).resolve().parents[2]
|
||
|
|
|
||
|
|
|
||
|
|
def _load():
|
||
|
|
spec = importlib.util.spec_from_file_location(
|
||
|
|
"package_lambdas", ROOT / "scripts" / "package_lambdas.py"
|
||
|
|
)
|
||
|
|
mod = importlib.util.module_from_spec(spec)
|
||
|
|
sys.modules["package_lambdas"] = mod
|
||
|
|
spec.loader.exec_module(mod)
|
||
|
|
return mod
|
||
|
|
|
||
|
|
|
||
|
|
pkg = _load()
|
||
|
|
|
||
|
|
|
||
|
|
def test_function_keys_match_terraform_locals():
|
||
|
|
locals_tf = (ROOT / "terraform" / "locals.tf").read_text()
|
||
|
|
for key in pkg.FUNCTIONS:
|
||
|
|
assert f" {key} =" in locals_tf
|
||
|
|
for src in pkg.FUNCTIONS.values():
|
||
|
|
assert src.is_dir()
|
||
|
|
assert (src / "requirements.txt").is_file()
|
||
|
|
|
||
|
|
|
||
|
|
def test_build_function_bundles_shared_and_git_sha(tmp_path, monkeypatch):
|
||
|
|
monkeypatch.setattr(pkg, "_req_lines", lambda path: [])
|
||
|
|
|
||
|
|
def fake_run(cmd, check):
|
||
|
|
raise AssertionError(f"pip should not run when reqs are empty: {cmd}")
|
||
|
|
|
||
|
|
with patch.object(pkg.subprocess, "run", fake_run):
|
||
|
|
zip_path = pkg.build_function(
|
||
|
|
"weekly_post",
|
||
|
|
pkg.FUNCTIONS["weekly_post"],
|
||
|
|
"deadbeef",
|
||
|
|
tmp_path,
|
||
|
|
)
|
||
|
|
assert zip_path.is_file()
|
||
|
|
with zipfile.ZipFile(zip_path) as zf:
|
||
|
|
names = zf.namelist()
|
||
|
|
assert "app.py" in names
|
||
|
|
assert "shared/sentry_init.py" in names
|
||
|
|
assert "shared/build_info.py" in names
|
||
|
|
assert 'GIT_SHA = "deadbeef"' in zf.read("shared/build_info.py").decode()
|
||
|
|
assert "requirements.txt" not in names
|