apm-wo-analysis/tests/test_bootstrap_stub.py

35 lines
1.2 KiB
Python
Raw Normal View History

"""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