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 blog API. The app uses the factory pattern and SQLite. The models are:
id, title (string), body (text), author_id (FK to User), created_at (datetime), published (boolean, default False)id, post_id (FK to Post), author_id (FK to User), body (text), created_at (datetime)id, name (string, unique), with a many-to-many relationship to PostThe API endpoints are:
GET /api/posts -- list published posts with their tagsPOST /api/posts -- create a new post (requires authentication)GET /api/posts/<id> -- retrieve a single postPUT /api/posts/<id> -- update a post (author only, requires authentication)DELETE /api/posts/<id> -- delete a post (author only, requires authentication)GET /api/posts/<id>/comments -- list comments for a postPOST /api/posts/<id>/comments -- add a comment (requires authentication)GET /api/tags -- list all tagsThe app factory is create_app(test_config=None) in app/__init__.py. Database operations use app.db module with init_db() and get_db().
Produce test files under tests/ with comprehensive test coverage for the above endpoints. Include a tests/conftest.py with all necessary fixtures. Assume the models and routes already exist; you are only writing the tests.