mirror of
https://github.com/kennethreitz/kjvstudy.org.git
synced 2026-06-05 23:00:16 +00:00
f7013de63a
Major improvements to statistics endpoint and display: API Enhancements: - Add person_id to PersonStat model for accurate linking - Integrate biographies.json data to supplement GEDCOM ages - Support name aliases (e.g., "Mathusala or Methuselah" -> "Methuselah") - Fix Methuselah showing as longest lived (969 years vs Adam's 930) - Increase age data coverage from 1 to 53 people with known ages - Improve average lifespan calculation (241.5 years with better data) Template Improvements: - Add clickable links to person pages in statistics - Use actual GEDCOM person IDs instead of name slugs - Remove average lifespan display from table (cleaner UI) Test Updates: - Add person_id field assertions to stats endpoint test - Verify correct response structure with IDs Statistics now show: - 479 total people in genealogy - 41 generations from Adam to Jesus - Methuselah as longest lived (969 years) - David with most children (19) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
KJV Study API Tests
Comprehensive test suite for the KJV Study API and web application.
Test Files
test_api.py
Core API endpoint tests covering:
- Health checks
- Verse endpoints (single, range, verse of the day)
- Book endpoints (list, details, chapters, full text)
- Bible endpoint (entire Bible)
- Search functionality
- Interlinear data
- Cross-references
- Topics and reading plans
- Book name normalization
test_edge_cases.py
Edge case and error handling tests:
- Invalid inputs and error responses
- Verse range edge cases
- Book abbreviations (comprehensive)
- Search functionality edge cases
- Book boundaries (shortest, longest, etc.)
- Cross-references edge cases
- Interlinear data edge cases
- Topics and reading plans edge cases
- Performance tests with large data
- Content validation
test_web_routes.py
Web page and HTML endpoint tests:
- Homepage
- Book listing and detail pages
- Chapter and verse pages
- Search pages
- Topics and reading plans pages
- Resource pages
- 404 handling
- Redirects
- HTML structure and metadata
- Navigation elements
- Accessibility features
- Content types
conftest.py
Shared pytest configuration and fixtures:
client- TestClient for API requestssample_verses- Common verse referencessample_books- Sample book namesbook_abbreviations- Abbreviation mappingsbible_facts- Known Bible facts for validation
Running Tests
Run all tests
uv run pytest tests/ -v
Run specific test file
uv run pytest tests/test_api.py -v
Run specific test class
uv run pytest tests/test_api.py::TestVerseEndpoints -v
Run specific test
uv run pytest tests/test_api.py::TestVerseEndpoints::test_get_single_verse -v
Run with coverage
uv run pytest tests/ --cov=kjvstudy_org --cov-report=html
Run tests in parallel (faster)
uv run pytest tests/ -n auto
Test Categories
Functional Tests
- API endpoints return correct data
- Web pages load correctly
- Search functionality works
- Data integrity
Edge Cases
- Invalid inputs
- Boundary conditions
- Error handling
- Performance with large datasets
Integration Tests
- Book name normalization
- Cross-references linking
- Interlinear data availability
- Content validation
Fixtures
Fixtures are defined in conftest.py and automatically available to all test files:
- client: FastAPI TestClient for making requests
- sample_verses: Dictionary of common verse references
- sample_books: Dictionary of sample book names
- book_abbreviations: Mapping of abbreviations to full names
- bible_facts: Known facts about the KJV Bible
Best Practices
- Use fixtures - Leverage shared fixtures from conftest.py
- Descriptive names - Test names should describe what they test
- Arrange-Act-Assert - Follow AAA pattern in tests
- One assertion per concept - Keep tests focused
- Test edge cases - Don't just test happy paths
- Use parametrize - For testing multiple similar cases
Adding New Tests
When adding new functionality:
- Add API tests to
test_api.py - Add edge case tests to
test_edge_cases.py - Add web route tests to
test_web_routes.py - Update fixtures in
conftest.pyif needed - Run tests to ensure they pass
- Add documentation if needed
CI/CD Integration
These tests are designed to run in CI/CD pipelines:
# Example GitHub Actions workflow
- name: Run tests
run: uv run pytest tests/ -v --cov