procurement-ingest/tests/conftest.py

42 lines
1.3 KiB
Python
Raw Normal View History

"""Shared test fixtures.
The Lambda handlers create boto3 clients at import time, so a region and
dummy credentials must be in the environment before any handler module is
imported. Setting them here (conftest runs before test collection imports
anything) keeps every test hermetic — no real AWS calls can succeed with
these values.
"""
import importlib.util
import os
import sys
from pathlib import Path
import pytest
os.environ.setdefault("AWS_DEFAULT_REGION", "us-east-1")
os.environ.setdefault("AWS_ACCESS_KEY_ID", "testing")
os.environ.setdefault("AWS_SECRET_ACCESS_KEY", "testing")
os.environ.setdefault("AWS_SESSION_TOKEN", "testing")
REPO_ROOT = Path(__file__).resolve().parents[1]
def load_module(name: str, path: Path):
"""Import a module from an explicit file path under a unique name."""
spec = importlib.util.spec_from_file_location(name, path)
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
spec.loader.exec_module(module)
return module
@pytest.fixture(params=["wo", "po"])
def ses_auth(request):
"""The ses_auth module of each pipeline (duplicated file, kept in sync)."""
pipeline = request.param
return load_module(
f"{pipeline}_ses_auth",
REPO_ROOT / "lambdas" / pipeline / "email_processor" / "ses_auth.py",
)