CI - Continuous Integration / Run Tests (push) Failing after 0s
CI - Continuous Integration / Build and Verify (push) Has been skipped
CI - Continuous Integration / Security Scan (push) Failing after 0s
Complete CI/CD Pipeline / Code Quality & Security (push) Failing after 0s
Complete CI/CD Pipeline / Run Tests (push) Has been skipped
Complete CI/CD Pipeline / Build Docker Image (push) Has been skipped
Complete CI/CD Pipeline / Container Security Scan (push) Has been skipped
Complete CI/CD Pipeline / Deploy to Development (GitOps) (push) Has been skipped
Complete CI/CD Pipeline / Deploy to Production (GitOps) (push) Has been skipped
Complete CI/CD Pipeline / Post-deployment Verification (push) Failing after 0s
Complete CI/CD Pipeline / Notify Results (push) Successful in 0s
OpenAPI Spec Validation / Generate OpenAPI Spec (push) Failing after 2s
OpenAPI Spec Validation / Detect Breaking Changes (push) Has been skipped
OpenAPI Spec Validation / Validate OpenAPI Spec (push) Has been skipped
OpenAPI Spec Validation / Generate API Documentation (push) Has been skipped
OpenAPI Spec Validation / OpenAPI Validation Summary (push) Successful in 0s
Test Matrix / Lint (push) Failing after 1s
Test Matrix / Test (${{ matrix.python-version }}, ${{ matrix.test-type }}) (macos-latest, 3.11, unit) (push) Has been skipped
Test Matrix / Test (${{ matrix.python-version }}, ${{ matrix.test-type }}) (ubuntu-latest, 3.10, integration) (push) Has been skipped
Test Matrix / Test (${{ matrix.python-version }}, ${{ matrix.test-type }}) (ubuntu-latest, 3.10, unit) (push) Has been skipped
Test Matrix / Test (${{ matrix.python-version }}, ${{ matrix.test-type }}) (ubuntu-latest, 3.11, integration) (push) Has been skipped
Test Matrix / Test (${{ matrix.python-version }}, ${{ matrix.test-type }}) (ubuntu-latest, 3.11, unit) (push) Has been skipped
Test Matrix / Test (${{ matrix.python-version }}, ${{ matrix.test-type }}) (ubuntu-latest, 3.12, integration) (push) Has been skipped
Test Matrix / Test (${{ matrix.python-version }}, ${{ matrix.test-type }}) (ubuntu-latest, 3.12, unit) (push) Has been skipped
Test Matrix / E2E Tests (push) Has been skipped
Test Matrix / Coverage Summary (push) Has been skipped
Test Matrix / Security Scan (push) Failing after 3s
Test Matrix / Build Docker Image (push) Has been skipped
Test Matrix / All Tests Passed (push) Failing after 0s
TODO to Issue / Create Issues from TODOs (push) Failing after 0s
Update Project Dashboard / Generate Project Dashboard (push) Failing after 1s
Security Scanning / SAST (Bandit + Semgrep) (push) Failing after 20s
Security Scanning / Dependency Scanning (Safety + Trivy) (push) Failing after 4s
Security Scanning / Container Scanning (push) Failing after 0s
Security Scanning / Secret Scanning (push) Failing after 0s
Security Scanning / License Compliance (push) Failing after 4s
Security Scanning / Security Summary (push) Failing after 2s
**Summary:** Implemented 5 complete API modules for left-behind children psychological risk detection platform with comprehensive test coverage and 100% pass rate. **Implemented Modules:** 1. **Issue #37 - Risk Assessment API** (32/32 tests, 50.00% coverage) - POST /risk-assessments - Create risk assessment - GET /risk-assessments - List assessments - GET /risk-assessments/{id} - Get assessment details - PUT /risk-assessments/{id} - Update assessment - DELETE /risk-assessments/{id} - Delete assessment 2. **Issue #38 - Data Collection API** (26/26 tests, 49.69% coverage) - POST /data/voice - Upload voice data - GET /data/voice - List voice data - POST /data/text - Submit text data - GET /data/text - List text data 3. **Issue #39 - Resource Library API** (40/40 tests, 71.06% coverage) - POST /resources - Create resource - GET /resources - List resources with filters - GET /resources/{id} - Get resource details - PUT /resources/{id} - Update resource - DELETE /resources/{id} - Delete resource - POST /resources/{id}/usage - Track usage 4. **Issue #40 - Communication API** (54/54 tests, 46.79% coverage) - POST /communications/conversations - Create conversation - GET /communications/conversations - List conversations - POST /communications/conversations/{id}/messages - Send message - GET /communications/conversations/{id}/messages - Get messages - POST /communications/consultations - Schedule consultation - GET /communications/consultations - List consultations - PUT /communications/consultations/{id} - Update consultation 5. **Issue #41 - Analytics Dashboard API** (31/31 tests, 40.88% coverage) - GET /analytics/overview - Platform statistics - GET /analytics/children/{id}/summary - Child summary - GET /analytics/risk-trends - Risk assessment trends - GET /analytics/resource-usage - Resource usage stats - GET /analytics/consultation-stats - Consultation statistics **Technical Achievements:** - ✅ 183/183 tests passing (100% pass rate) - ✅ Full async implementation (AsyncSession + asyncpg) - ✅ Role-based access control (RBAC) - ✅ Eager loading to prevent N+1 queries - ✅ OpenTelemetry distributed tracing - ✅ Comprehensive error handling - ✅ Database constraint compliance - ✅ Composite primary key handling (UUID) **Key Fixes:** - Fixed UUID type matching in composite keys (ConversationParticipant) - Added selectinload() for async relationship loading - Corrected risk score category constraints (low: 0-25, medium: 26-50, high: 51-75, critical: 76-100) - Wrapped pg_sleep() with text() for SQLAlchemy 2.0 - Fixed all Data Collection field naming issues **Project Status:** - Total API coverage: 40.69% - All core modules: ✅ Complete - Next: Issue #42 (OrbStack Deployment) **Updated Files:** - backend/api/analytics.py (296 lines) - backend/api/communications.py (344 lines) - backend/api/resources.py (273 lines) - backend/api/data.py (updated) - backend/api/risk_assessments.py (updated) - backend/main.py (registered all routers) - tests/unit/test_api_*.py (183 comprehensive tests) - README.md (added progress table) **Breaking Changes:** None (all backward compatible) Closes #37, #38, #39, #40, #41 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Testing Guide
Comprehensive testing framework for Gold Template project.
Test Structure
tests/
├── unit/ # Fast, isolated unit tests
│ ├── test_models.py # Database model tests
│ └── test_api_endpoints.py # API endpoint tests
├── integration/ # Integration tests with dependencies
│ ├── test_database.py # Database integration tests
│ └── test_api_integration.py # Full API workflow tests
├── e2e/ # End-to-end tests
│ ├── test_auth_flow.py # Authentication flows
│ └── test_crud_operations.py # CRUD workflows
├── conftest.py # Shared fixtures
├── factories.py # Test data factories
└── README.md # This file
Running Tests
All Tests
pytest
By Category
# Unit tests only (fast)
pytest tests/unit/ -v
# Integration tests
pytest tests/integration/ -v
# E2E tests (requires running app)
pytest tests/e2e/ -v -m e2e
By Marker
# Run only async tests
pytest -m asyncio
# Skip slow tests
pytest -m "not slow"
# Run integration tests
pytest -m integration
Coverage
Generate Coverage Report
# Terminal report
pytest --cov=backend --cov-report=term-missing
# HTML report (opens in browser)
pytest --cov=backend --cov-report=html
open htmlcov/index.html
# XML report (for CI)
pytest --cov=backend --cov-report=xml
Coverage Goals
- Overall: >80%
- Critical paths: >95%
- New code: 100%
Test Fixtures
Database Fixtures
test_engine: In-memory SQLite database enginetest_session: Async database sessiontest_client: FastAPI test client with DB override
Data Fixtures
sample_user_data: Single user datasample_item_data: Single item datamultiple_users_data: List of users
Test Factories
Use factories to generate realistic test data:
from tests.factories import create_user, create_item
# Create single user with defaults
user = create_user()
# Create user with custom values
user = create_user(username="custom_user", email="[email protected]")
# Create multiple users
users = create_users(10)
E2E Tests
E2E tests require:
- Running application instance
- Playwright installation
Setup E2E Tests
# Install Playwright
pip install playwright
playwright install
# Start application
python -m uvicorn backend.main:app --reload
# Run E2E tests
pytest tests/e2e/ -v
CI Integration
Tests run automatically in CI on:
- Every push to main/develop
- Every pull request
- Manual workflow dispatch
CI Configuration
See .github/workflows/ci.yml for:
- Parallel test execution
- Coverage reporting
- Test result uploads
Best Practices
Writing Unit Tests
import pytest
class TestUserModel:
@pytest.mark.asyncio
async def test_create_user(self, test_session):
# Arrange
user_data = create_user()
# Act
user = User(**user_data)
test_session.add(user)
await test_session.commit()
# Assert
assert user.id is not None
Writing Integration Tests
@pytest.mark.asyncio
async def test_user_crud_workflow(test_client):
# Create
response = await test_client.post("/users/", json=user_data)
assert response.status_code == 201
# Read
user_id = response.json()["id"]
response = await test_client.get(f"/users/{user_id}")
assert response.status_code == 200
Test Naming
- Use descriptive names:
test_create_user_with_valid_data - Follow pattern:
test_<action>_<scenario>_<expected_result> - Group related tests in classes
Test Organization
- One test file per module
- Group related tests in classes
- Use descriptive class names:
TestUserAuthentication
Troubleshooting
Tests Fail Due to Database Lock
# Remove test database
rm test.db
# Run tests again
pytest
Async Tests Not Running
# Ensure pytest-asyncio is installed
pip install pytest-asyncio
# Check pytest.ini has asyncio_mode = auto
Coverage Not Showing
# Ensure pytest-cov is installed
pip install pytest-cov
# Check .coveragerc configuration
E2E Tests Failing
# Ensure application is running
lsof -i :8000
# Reinstall Playwright browsers
playwright install --force
Performance
Test Execution Time
- Unit tests: <10 seconds
- Integration tests: <30 seconds
- E2E tests: <2 minutes
- Full suite: <5 minutes
Optimization Tips
- Use
pytest-xdistfor parallel execution - Mock external dependencies
- Use in-memory database for tests
- Cache expensive fixtures