Skip to content

Redesign database error handling test for project creation API #40

Description

@frankbria

Problem

The test test_create_project_handles_database_errors in tests/api/test_project_creation_api.py:215 is currently skipped with the reason:

Database close() creates ungraceful crashes, not 500 errors. This test design is flawed.

Current State

The test attempts to verify that database errors are handled gracefully by the project creation API endpoint and return proper 500 Internal Server Error responses. However, the current approach of forcibly closing the database connection causes ungraceful crashes instead of testable error conditions.

Proposed Solution

Redesign this test to properly validate database error handling:

  1. Mock database operations: Instead of closing the database, use mocking to simulate database errors (e.g., sqlite3.OperationalError, sqlite3.IntegrityError)
  2. Test specific error scenarios:
    • Disk full error
    • Database locked error
    • Constraint violation error
  3. Verify proper error responses: Ensure the API returns 500 status code with appropriate error messages
  4. Add error logging validation: Verify that errors are properly logged for debugging

Acceptance Criteria

  • Test no longer uses db.close() to trigger errors
  • Test uses mocking or dependency injection to simulate database failures
  • Test verifies 500 status code is returned
  • Test verifies error response contains meaningful message
  • Test passes consistently in CI/CD pipeline
  • Skip decorator is removed

File Location

tests/api/test_project_creation_api.py:215-221

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtesting

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions