CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/flask-testing

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

1.15x
Quality

99%

Does it follow best practices?

Impact

97%

1.15x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-5/

Task Tracker with CLI Commands Tests

Write tests for a Flask task tracking application that includes both API endpoints and CLI commands. The app uses the factory pattern and SQLite.

Models

  • User: id, username, email, password_hash, is_admin (boolean, default False)
  • Task: id, title, description, status (string: 'todo', 'in_progress', 'done', 'archived'), priority (string: 'low', 'medium', 'high'), assignee_id (FK to User, nullable), created_by_id (FK to User), created_at, updated_at

API Endpoints

  • POST /auth/login -- log in (username, password)
  • GET /api/tasks -- list tasks (authenticated, supports ?status= and ?priority= query params)
  • POST /api/tasks -- create task (authenticated)
  • GET /api/tasks/<id> -- get task detail (authenticated)
  • PATCH /api/tasks/<id> -- update task fields (authenticated, creator or assignee only)
  • PATCH /api/tasks/<id>/status -- update task status (authenticated, must follow valid transitions: todo->in_progress->done->archived)
  • DELETE /api/tasks/<id> -- delete task (admin only)

CLI Commands (registered via app.cli)

  • flask init-db -- initialize the database schema, prints "Database initialized."
  • flask seed-data -- seed sample tasks and users, prints "Seeded N tasks."
  • flask archive-done --days 30 -- archive tasks that have been 'done' for more than N days, prints "Archived N tasks."

Error Handling

All API errors return JSON with the shape {"error": {"message": "...", "code": "..."}}. Custom error handlers are registered for 400, 404, and 500.

Output

Produce test files under tests/ with comprehensive coverage of both the API and CLI commands. Include tests/conftest.py. Assume app code exists; you are only writing the tests.

evals

tile.json