Daily Test Coverage Improver - Fix Python test infrastructure and enable 88% coverage#247
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
…t imports - Add __init__.py to server/, backend/, backend/api/ to make them proper Python packages - Add __init__.py to tests/, tests/unit/, tests/integration/ for test discovery - Fix test_contact_handler.py to import correct classes and functions - Rewrite test_contact_handler.py with comprehensive tests for actual implementation - Fix test_api_endpoints.py to create FastAPI app before using TestClient - Remove test_validation.py which tried to import non-existent Python modules All 28 Python tests now pass with 88% coverage (138 statements, 16 missed)
This was referenced Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal and Rationale
Target: Python test infrastructure (Priority 2 from research phase)
This PR fixes the broken Python tests identified in Phase 1 research. The tests were failing due to:
__init__.pyfiles preventing module importsThis was a critical blocker preventing any Python test execution and coverage measurement.
Approach
Module Structure Setup
__init__.pyfiles to make Python packages importable:server/__init__.pybackend/__init__.pybackend/api/__init__.pytests/__init__.pytests/unit/__init__.pytests/integration/__init__.pyTest Fixes
test_contact_handler.py: Complete rewrite to match actual implementation
ContactFormHandler(notContactHandler)ContactFormData,AuditLogger,DataRetentionManagerhash_ip_address,sanitize_user_agent,validate_csrf_tokenhandle_data_export_request,handle_data_deletion_requestContactFormHandlerwith rate limiting, CSRF validation, consent checkstest_api_endpoints.py: Fixed FastAPI test setup
test_validation.py: Removed
src/utils/validationwhich are actually TypeScriptImpact Measurement
Before changes:
Test Coverage Results
Coverage by Module
Trade-offs
Complexity: Added minimal boilerplate (
__init__.pyfiles) necessary for Python packagingMaintainability: Tests now accurately reflect actual implementation, making them sustainable
Coverage gaps: 16 statements in server/contact_handler.py remain untested (mostly error paths and placeholder implementations)
Validation
Test Execution
All 28 tests pass successfully:
Test Categories
✅ ContactFormData validation (5 tests)
✅ Audit logging (1 test)
✅ Data retention policies (5 tests)
✅ Utility functions (6 tests)
✅ Contact form processing (6 tests)
✅ GDPR compliance (2 tests)
✅ API endpoints (2 tests)
Reproducibility
Setup
Run Tests
Future Work
Additional coverage opportunities identified: