apm-wo-analysis/tests/test_bootstrap_stub.py
Adam Moussa 8dc3f71e6c
Some checks failed
Deploy / Deploy to prod (push) Has been cancelled
fix(lambda): expose interactions.handler on the bootstrap stub (#59)
slack_interactions is configured for interactions.handler. A recreate that
reloads the stub zip must return 503 instead of failing at init.
2026-09-16 20:52:14 +00:00

34 lines
1.2 KiB
Python

"""Stub zip must expose every Lambda handler name in locals.functions."""
from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
STUB_DIR = Path(__file__).resolve().parents[1] / "terraform" / "bootstrap" / "stub"
def _load_file(module_name: str, path: Path):
spec = importlib.util.spec_from_file_location(module_name, path)
assert spec is not None and spec.loader is not None
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def test_stub_handler_modules_return_503() -> None:
handler_mod = _load_file("apm_stub_handler", STUB_DIR / "handler.py")
saved_handler = sys.modules.get("handler")
sys.modules["handler"] = handler_mod
try:
interactions_mod = _load_file("apm_stub_interactions", STUB_DIR / "interactions.py")
for module in (handler_mod, interactions_mod):
result = module.handler({}, None)
assert result["statusCode"] == 503
assert "NOT_DEPLOYED" in result["body"]
finally:
if saved_handler is None:
sys.modules.pop("handler", None)
else:
sys.modules["handler"] = saved_handler