-
-
Notifications
You must be signed in to change notification settings - Fork 602
Open
Description
Is there an existing issue for this?
- I have searched the existing issues
What happened?
Issue Description:
Currently, the FastAPI album route tests directly patch internal database helper functions (e.g., db_get_album, db_insert_album, db_update_album) to simulate database behavior.
This causes the tests to be tightly coupled to the internal implementation rather than validating the API’s behavior.
Consequences:
- Any internal refactor (e.g., renaming, moving, or restructuring DB logic) will break tests, even if the API’s external behavior remains correct.
- Tests are verifying implementation details instead of expected responses.
- This increases maintenance burden and discourages contributors from refactoring internal logic.
Proposed Improvement
Refactor the tests to focus on API contract and observable behavior:
1. HTTP status codes
2. Response JSON schema
3. Side effects visible through the API (e.g., album created, updated, deleted)
Mock external dependencies (like database session or ORM) at the boundary, rather than patching internal functions.
Ensure tests are resilient to internal refactors while still verifying correctness.
Why This Matters
- Improves long-term maintainability of the codebase
- Reduces fragility of tests
- Makes it easier for new contributors to modify or extend database logic without breaking tests
- Aligns with best practices for OSS project testing
Record
- I agree to follow this project's Code of Conduct
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels