meal-order-manager/tests/conftest.py
Adam Moussa 44b21f4033
Some checks failed
Deploy / deploy (push) Has been cancelled
fix(test): fix aggregated notifier tests + enable CI test suite (INFRA-72) (#39)
* fix(test): mock get_settings/get_roster in aggregated tests + enable CI tests (INFRA-72)

handle_orders_aggregated now delivers the summary via admin DMs (PR #15),
adding get_settings/get_roster calls the aggregated tests never mocked, so
they hit live DynamoDB. Mock both and assert the message content on the
send_dm path. Set run-tests: true so the suite actually runs in CI.

* fix(test): default AWS region in conftest so CI collection doesn't hit NoRegionError (INFRA-72)

Handlers build boto3 clients at module load; CI runners have no AWS config,
so test collection raised NoRegionError once the suite actually ran. Set a
region default before imports (offline client construction; calls are mocked).

* fix(test): add repo root to sys.path so CI's bare pytest collects functions.* (INFRA-72)

test_aggregate_orders imports functions.aggregate_orders.handler, which needs
the repo root on sys.path. python -m pytest injects CWD automatically but CI
runs pytest directly, so these 11 tests errored at collection in CI only.
2026-07-08 16:33:42 -04:00

23 lines
1.2 KiB
Python

"""Pytest configuration — add shared layer source to sys.path so handler imports resolve."""
import os
import sys
# Several Lambda handlers construct boto3.client(...) at module load. On a CI
# runner with no AWS config this raises NoRegionError during test collection
# (a real region is read from ~/.aws/config locally, masking it). Set a default
# region before any import. Client construction is offline; real calls are mocked.
os.environ.setdefault("AWS_DEFAULT_REGION", "us-east-1")
os.environ.setdefault("AWS_REGION", "us-east-1")
# Add the repo root so `import functions.<name>.handler` resolves under a bare
# `pytest` invocation. `python -m pytest` injects the CWD automatically, but CI
# runs `pytest` directly, which does not — hence tests passed locally yet failed
# to collect in CI.
_repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
sys.path.insert(0, _repo_root)
# Add the shared layer source directory so `from shared.db import ...` works
# without requiring a real Lambda layer or .aws-sam build.
_shared_layer_dir = os.path.join(os.path.dirname(__file__), os.pardir, "src", "shared")
sys.path.insert(0, os.path.abspath(_shared_layer_dir))