Write correct Flask tests -- app factory with test config, application context fixtures, database isolation, file uploads, auth testing, error handlers, mock.patch placement, and essential API test patterns
98
99%
Does it follow best practices?
Impact
97%
1.15xAverage score across 5 eval scenarios
Passed
No known issues
Write tests for a Flask e-commerce checkout API. The app uses the factory pattern, SQLAlchemy, and integrates with an external payment service.
id, name, price_cents (integer), stock (integer)id, user_id (FK to User), created_atid, cart_id (FK to Cart), product_id (FK to Product), quantity (integer)id, user_id (FK to User), status (string: 'pending', 'confirmed', 'shipped', 'cancelled'), total_cents (integer), created_atid, username, email, password_hashThe checkout endpoint is POST /api/checkout and accepts {"cart_id": <int>}. The view is in app/routes/orders.py and does:
charge_card(amount_cents, user) imported in app/routes/orders.py as from app.services.payment import charge_cardsend_confirmation_email(order) imported in app/routes/orders.py as from app.services.email import send_confirmation_emailIf charge_card raises PaymentError, the order is created with status='pending' and no email is sent.
POST /auth/login -- log inGET /api/cart -- get current user's cart (authenticated)POST /api/cart/items -- add item to cart (authenticated)GET /api/orders -- list user's orders (authenticated)GET /api/orders/<id> -- get order detail (authenticated)Produce test files under tests/ with comprehensive test coverage for the checkout flow. Include tests/conftest.py. Assume app code exists; you are only writing the tests.