Model/applications/sharepoint_renamer/local_handler/invoke_local_lambda.py
Daniel Roth bbb3c9e057 Verify a local rename run the way the queue delivers it 🟪
The local invoke now sends an SQS-shaped payload — a direct invoke is the
one shape that cannot reproduce the dry_run bug class. Test modules route
protected-method calls through typed helpers so both pass pyright strict.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-29 09:19:51 +00:00

39 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Invoke the locally-running Renamer image with a realistic SQS payload.
The event is hand-built SQS-shaped on purpose. A direct invoke (a bare body,
no ``Records``) is the one path where the request is read the same way whether
or not the record body is unwrapped — so it is the one path that would NOT have
caught ``dry_run`` being ignored on queue-triggered runs. Exercise the shape
production actually delivers.
This writes a real task + sub_task row to whatever database ``.env`` points at
(dev), and is the only place the production Postgres driver is exercised — the
tests use a different one. ``dry_run`` is True so nothing is renamed for real.
"""
import json
import requests
HOST = "localhost"
PORT = "9003"
LAMBDA_URL = f"http://{HOST}:{PORT}/2015-03-31/functions/function/invocations"
payload = {
"Records": [
{
"messageId": "local-test-1",
"body": json.dumps(
{"sharepoint_site": "SOCIAL_HOUSING_WAVE_3", "dry_run": True}
),
}
]
}
response = requests.post(LAMBDA_URL, json=payload)
print("Status code:", response.status_code)
print("Response:")
print(response.text)