mirror of
https://github.com/Sea-Haven-Industries/apm-wo-analysis.git
synced 2026-09-30 03:03:14 +00:00
Some checks failed
Deploy / Deploy to prod (push) Has been cancelled
slack_interactions is configured for interactions.handler. A recreate that reloads the stub zip must return 503 instead of failing at init.
34 lines
1.2 KiB
Python
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
|