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 recipe sharing application. The app uses the factory pattern, SQLAlchemy, and Flask-Login for authentication.
id, username (unique), email, password_hashid, title, description, ingredients (text), instructions (text), author_id (FK to User), created_at, is_public (boolean, default True)id, user_id (FK to User), recipe_id (FK to Recipe), created_atPOST /auth/register -- register a new user (username, email, password)POST /auth/login -- log in (username, password), returns sessionPOST /auth/logout -- log outGET /api/recipes -- list public recipesPOST /api/recipes -- create recipe (authenticated)GET /api/recipes/<id> -- get recipe detailPUT /api/recipes/<id> -- update recipe (author only)DELETE /api/recipes/<id> -- delete recipe (author only)POST /api/recipes/<id>/favorite -- favorite a recipe (authenticated)DELETE /api/recipes/<id>/favorite -- unfavorite (authenticated)GET /api/users/me/favorites -- list my favorites (authenticated)The app factory is create_app(test_config=None) in app/__init__.py. It uses SQLAlchemy with db.create_all() for schema setup.
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.