Files
mtusi2026lab5/student-tests/test_outbox_payload.py
T
Самохвалов Андрей Ремович b23ecc111f feat: Accept durable queued uploads and publish outbox jobs (U2)
Carry forward the lab4 API and storage baseline, stage verified originals in
MinIO, and atomically commit attachment, job, and outbox records before 202.
Publish identifier-only jobs with broker confirms and reclaimable outbox leases.
Clean abandoned and completed staging objects after database checks.
2026-10-02 14:35:35 +03:00

36 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Keep broker messages within the public job schema and free of file data."""
import json
import sys
import unittest
from datetime import datetime, timezone
from pathlib import Path
from uuid import uuid4
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
sys.path.insert(0, str(ROOT / "tests"))
from client import validate # noqa: E402
from src.pipeline_jobs import job_payload # noqa: E402
class OutboxPayloadTest(unittest.TestCase):
def test_job_message_has_only_contract_fields(self):
schema = json.loads((ROOT / "contracts/jobs.schema.json").read_text(encoding="utf-8"))
row = {
"job_id": uuid4(), "attachment_id": uuid4(), "pipeline_version": 2,
"attempt": 3, "created_at": datetime.now(timezone.utc),
"object_key": "staging/must-not-leak", "bytes": b"must-not-leak",
}
message = job_payload(row)
validate(message, schema)
self.assertEqual(set(message), set(schema["required"]))
self.assertNotIn("staging", json.dumps(message))
self.assertNotIn("bytes", json.dumps(message))
if __name__ == "__main__":
unittest.main()