adding test files for more coverage
MR: Increase Test Coverage for Family Management & Book Number Generation
Description
This Merge Request increases the test coverage for the EHRS FastAPI project by adding comprehensive unit and integration tests for recently introduced features: Family Management, Sequential Book Number Generation, and the Refactored Patient Creation logic.
In total, 65 new and updated tests have been added, ensuring business logic correctness, API contract compliance, and protection against regressions.
Key Changes
1. New: Family Management Tests
- Service Layer ([tests/test_services/test_family_service.py]): 26 tests covering CRUD operations, relationship validation (e.g., single "head" rule), and family deletion. Includes both mocked unit tests and real PostgreSQL integration tests.
- API Layer ([tests/test_api/test_family_routes.py]): 22 route-contract tests for all family endpoints, ensuring proper HTTP status codes (200, 400, 404, 500) and response formats.
2. New: Book Number Service Tests
- Service Layer ([tests/test_services/test_book_no_service.py]): 5 unit tests for the PostgreSQL sequence-based [generate_book_no]function, verifying atomic sequential generation and fallback logic.
3. Updated: Patient Service Tests
-
[tests/test_services/test_patient_service.py]:
- Replaced stale tests that relied on deleted "reuse existing user" logic.
- Added tests for the refactored create_patient behavior (always creates a new user, handles optional [book_no]).
- Fixed Pydantic validation errors in pre-existing tests by providing required fields (
patient_age,patient_sex) and valid Indian phone number patterns.
Verification Results
Tests were executed using uv run pytest.
Summary
- Tests Passed: 65
- Regressions: 0 (Full suite regression check performed; pre-existing failures in other modules remain unrelated).
Edited by Vaishnavi Prabhala