Files
kjvstudy.org/tests
kennethreitz 2776aa984a Add PDF export and comprehensive tests for Resources API
New features:
- PDF export endpoints for resources
  * GET /api/resources/{category}/pdf - Category PDF
  * GET /api/resources/{category}/{slug}/pdf - Item PDF
  * Proper error handling (404 before 503)
  * Uses existing resource_detail_pdf.html templates

- Add html_url field to resource categories
  * Provides web URL in addition to API URL
  * Format: /biblical-locations (kebab-case)
  * Helps clients link to HTML pages

Comprehensive test coverage (12 new tests):
- test_list_all_resources - List all 39 categories
- test_get_resource_category - Get category items
- test_get_resource_category_biblical_locations - Nested structures
- test_get_resource_item - Get specific item with verses
- test_get_resource_item_from_different_categories - Multiple types
- test_get_nonexistent_resource_category - 404 handling
- test_get_nonexistent_resource_item - Item 404
- test_resource_category_pdf - PDF generation
- test_resource_item_pdf - Item PDF
- test_resource_pdf_nonexistent_category - PDF 404
- test_resource_pdf_nonexistent_item - Item PDF 404
- test_all_resource_categories_accessible - All categories work

All 51 API tests passing (was 39, added 12).

Note: PDF route ordering with FastAPI path matching is documented
in tests. More specific routes should ideally come before general ones.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 13:32:48 -05:00
..

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 requests
  • sample_verses - Common verse references
  • sample_books - Sample book names
  • book_abbreviations - Abbreviation mappings
  • bible_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

  1. Use fixtures - Leverage shared fixtures from conftest.py
  2. Descriptive names - Test names should describe what they test
  3. Arrange-Act-Assert - Follow AAA pattern in tests
  4. One assertion per concept - Keep tests focused
  5. Test edge cases - Don't just test happy paths
  6. Use parametrize - For testing multiple similar cases

Adding New Tests

When adding new functionality:

  1. Add API tests to test_api.py
  2. Add edge case tests to test_edge_cases.py
  3. Add web route tests to test_web_routes.py
  4. Update fixtures in conftest.py if needed
  5. Run tests to ensure they pass
  6. 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