---
id: T02
parent: S02
milestone: M001
provides: []
requires: []
affects: []
key_files: ["backend/tests/conftest.py", "backend/tests/test_ingest.py", "backend/tests/fixtures/sample_transcript.json", "backend/pytest.ini", "backend/requirements.txt", "backend/models.py"]
key_decisions: ["Used NullPool for test engine to avoid asyncpg connection contention between ASGI test client and verification queries", "Fixed _now() helper in models.py to return naive UTC datetimes for asyncpg TIMESTAMP WITHOUT TIME ZONE compatibility"]
patterns_established: []
drill_down_paths: []
observability_surfaces: []
duration: ""
verification_result: "All 6 tests pass: cd backend && python3 -m pytest tests/test_ingest.py -v (6 passed in 2.92s). All 4 slice-level verification checks pass: router.routes outputs ['/ingest'], TranscriptIngestResponse fields correct, python-multipart in requirements.txt, ingest in main.py. Docker compose config validation passes."
completed_at: 2026-03-29T22:16:12.806Z
blocker_discovered: false
---

# T02: Added 6 integration tests proving ingestion, creator auto-detection, and idempotent re-upload against real PostgreSQL

> Added 6 integration tests proving ingestion, creator auto-detection, and idempotent re-upload against real PostgreSQL

## What Happened
---
id: T02
parent: S02
milestone: M001
key_files:
  - backend/tests/conftest.py
  - backend/tests/test_ingest.py
  - backend/tests/fixtures/sample_transcript.json
  - backend/pytest.ini
  - backend/requirements.txt
  - backend/models.py
key_decisions:
  - Used NullPool for test engine to avoid asyncpg connection contention between ASGI test client and verification queries
  - Fixed _now() helper in models.py to return naive UTC datetimes for asyncpg TIMESTAMP WITHOUT TIME ZONE compatibility
duration: ""
verification_result: passed
completed_at: 2026-03-29T22:16:12.806Z
blocker_discovered: false
---

# T02: Added 6 integration tests proving ingestion, creator auto-detection, and idempotent re-upload against real PostgreSQL

**Added 6 integration tests proving ingestion, creator auto-detection, and idempotent re-upload against real PostgreSQL**

## What Happened

Set up complete pytest + pytest-asyncio test infrastructure with async fixtures: function-scoped db_engine using NullPool for isolation, ASGI transport test client with dependency overrides, and sample transcript fixture. Created 6 integration tests covering happy path (creator+video+segments creation), creator reuse, idempotent re-upload, JSON-to-disk persistence, invalid JSON rejection, and missing fields rejection. Fixed a bug in models.py where _now() returned timezone-aware datetimes incompatible with TIMESTAMP WITHOUT TIME ZONE columns in asyncpg.

## Verification

All 6 tests pass: cd backend && python3 -m pytest tests/test_ingest.py -v (6 passed in 2.92s). All 4 slice-level verification checks pass: router.routes outputs ['/ingest'], TranscriptIngestResponse fields correct, python-multipart in requirements.txt, ingest in main.py. Docker compose config validation passes.

## Verification Evidence

| # | Command | Exit Code | Verdict | Duration |
|---|---------|-----------|---------|----------|
| 1 | `cd backend && python3 -m pytest tests/test_ingest.py -v` | 0 | ✅ pass | 2920ms |
| 2 | `cd backend && python3 -c "from routers.ingest import router; print([r.path for r in router.routes])"` | 0 | ✅ pass | 500ms |
| 3 | `cd backend && python3 -c "from schemas import TranscriptIngestResponse; print(TranscriptIngestResponse.model_fields.keys())"` | 0 | ✅ pass | 500ms |
| 4 | `grep -q 'python-multipart' backend/requirements.txt` | 0 | ✅ pass | 10ms |
| 5 | `grep -q 'ingest' backend/main.py` | 0 | ✅ pass | 10ms |
| 6 | `docker compose config > /dev/null 2>&1` | 0 | ✅ pass | 500ms |


## Deviations

Fixed bug in backend/models.py _now() function — changed from datetime.now(timezone.utc) to datetime.now(timezone.utc).replace(tzinfo=None) to match TIMESTAMP WITHOUT TIME ZONE column types. This was necessary for asyncpg compatibility and was not in the original task plan.

## Known Issues

None.

## Files Created/Modified

- `backend/tests/conftest.py`
- `backend/tests/test_ingest.py`
- `backend/tests/fixtures/sample_transcript.json`
- `backend/pytest.ini`
- `backend/requirements.txt`
- `backend/models.py`


## Deviations
Fixed bug in backend/models.py _now() function — changed from datetime.now(timezone.utc) to datetime.now(timezone.utc).replace(tzinfo=None) to match TIMESTAMP WITHOUT TIME ZONE column types. This was necessary for asyncpg compatibility and was not in the original task plan.

## Known Issues
None.
