Spec-to-Test-Cases Auto-Generator
Paste a spec. Get a runnable pytest skeleton covering each acceptance criterion.
Spec summary
Stripe webhook handler must verify signatures, deduplicate by event ID, and return 200 within 5s
Acceptance criteria (4)
- - Reject requests with missing signature header
- - Reject requests with invalid HMAC
- - Process duplicate event IDs only once
- - Respond within 5s on happy path
Generated pytest skeleton
import pytest
from app.webhook import handler
def test_rejects_missing_signature(client):
r = client.post("/webhook", json={"id": "evt_1"})
assert r.status_code == 401
def test_rejects_invalid_hmac(client):
r = client.post("/webhook", headers={"stripe-signature": "bad"}, json={"id": "evt_1"})
assert r.status_code == 401
@pytest.mark.parametrize("event_id", ["evt_dup_1", "evt_dup_2"])
def test_dedupes_event(client, event_id, valid_sig):
r1 = client.post("/webhook", headers={"stripe-signature": valid_sig}, json={"id": event_id})
r2 = client.post("/webhook", headers={"stripe-signature": valid_sig}, json={"id": event_id})
assert r1.status_code == 200
assert r2.status_code == 200
assert r2.json()["dedupe"] is True
def test_responds_within_5_seconds(client, valid_sig, benchmark):
result = benchmark(lambda: client.post("/webhook", headers={"stripe-signature": valid_sig}, json={"id": "evt_speed"}))
assert benchmark.stats["max"] < 5.0