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 document upload and management service. The app uses the factory pattern and SQLite.
id, filename (string), original_name (string), content_type (string), size_bytes (integer), uploaded_by (FK to User), created_atid, username, email, api_key (string, unique)POST /api/documents/upload -- upload a document (authenticated via API key in Authorization header as Bearer <api_key>)
file fieldGET /api/documents -- list user's documents (authenticated)GET /api/documents/<id> -- get document metadata (authenticated, owner only)DELETE /api/documents/<id> -- delete document (authenticated, owner only)GET /api/documents/<id>/download -- download document file (authenticated, owner only)The app factory is create_app(test_config=None) in app/__init__.py. File storage uses the filesystem at app.config['UPLOAD_FOLDER'].
Produce test files under tests/ with comprehensive test coverage. Include tests/conftest.py with all fixtures. Assume the app code already exists; you are only writing the tests.