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-3/

Document Upload Service Tests

Write tests for a Flask document upload and management service. The app uses the factory pattern and SQLite.

Models

  • Document: id, filename (string), original_name (string), content_type (string), size_bytes (integer), uploaded_by (FK to User), created_at
  • User: id, username, email, api_key (string, unique)

Endpoints

  • POST /api/documents/upload -- upload a document (authenticated via API key in Authorization header as Bearer <api_key>)
    • Accepts multipart/form-data with a file field
    • Allowed types: PDF, PNG, JPEG, CSV (rejects others with 400)
    • Max size: 10MB (rejects larger with 413)
    • Returns 201 with document metadata
  • GET /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'].

Output

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.

evals

tile.json