This directory contains integration tests that require actual database connections and verify SQLBot functionality against real databases.
-
Install integration dependencies:
pip install -r requirements-integration.txt
-
Set up Sakila test database:
python scripts/setup_sakila_db.py
-
Run integration tests:
# Run directly with pytest pytest -m "integration" tests/integration/ # Run with verbose output pytest -m "integration" tests/integration/ -v
The integration tests use the Sakila sample database, a well-known DVD rental store database that provides:
- 1000 films with ratings, categories, and rental information
- 599 customers with rental history and payments
- 16,000+ rental transactions for realistic data testing
- Complete relational structure with actors, categories, inventory, stores, and staff
- Standardized: Industry-standard sample database, available as SQLite for easy setup
- Realistic: Contains real-world business data patterns
- Comprehensive: Tests complex queries, joins, and aggregations
- Lightweight: SQLite version requires no server setup
- Well-documented: Extensive schema with proper relationships
# Install dependencies and set up Sakila database
pip install -r requirements-integration.txt
python scripts/setup_sakila_db.pyThis creates:
sakila.db- SQLite database file with all Sakila data~/.dbt/profiles.yml- dbt configuration for Sakila profile- Profile-specific schema and macros in
profiles/Sakila/
If you need to customize the setup:
# Skip creating local .dbt/profiles.yml (use global ~/.dbt/profiles.yml instead)
python scripts/setup_sakila_db.py --no-local-profile# Run all integration tests
pytest -m "integration" tests/integration/
# Run with verbose output
pytest -m "integration" tests/integration/ -v
# Run specific test file
pytest tests/integration/test_sakila_integration.py
# Run specific test files
pytest tests/integration/test_basic_setup.py
pytest tests/integration/test_sakila_integration.py
pytest tests/integration/test_sakila_comprehensive_integration.pyIntegration tests are organized into focused test files:
test_basic_setup.py- Basic database connectivity and setup verificationtest_sakila_integration.py- Core Sakila database functionality testingtest_sakila_comprehensive_integration.py- Safeguards, query routing, and end-to-end workflowstest_local_dbt_folder_integration.py- Local .dbt folder feature testing
# Required for integration tests
export DBT_PROFILE_NAME=Sakila
# Optional: Configure LLM testing (if using LLM features)
export OPENAI_API_KEY=your_api_key_heretest_basic_setup.py - Foundation verification:
- SQLite database file accessibility
- Data integrity verification (1000 films, 599 customers, etc.)
- Schema structure validation
- dbt profiles configuration
- Integration test dependencies
test_sakila_integration.py - Core functionality:
- Schema integration and profile path discovery
- dbt debug and connection testing
- Query compilation with
{{ source('sakila', 'table') }}syntax - Macro execution (
get_films_by_category,get_customer_rentals, etc.) - REPL integration and command-line functionality
test_sakila_comprehensive_integration.py - Advanced workflows:
- Safeguard systems (blocking dangerous queries)
- Query routing (SQL vs natural language)
- End-to-end CLI and session integration
- LLM tool integration with safeguards
test_local_dbt_folder_integration.py - Configuration features:
- Local .dbt folder detection and usage
- Profile management and environment setup
- Banner display integration
Shared test configuration providing:
- Fixtures: Database setup, environment configuration, mocking
- Markers: Automatic test categorization
- Skip Logic: Intelligent test skipping based on available dependencies
- Environment Management: Clean setup/teardown of test environment
The tests verify SQLBot can handle realistic business queries:
-- Film catalog queries
SELECT COUNT(*) FROM {{ source('sakila', 'film') }} WHERE rating = 'PG-13';
-- Customer analysis
SELECT c.first_name, c.last_name, COUNT(r.rental_id) as rental_count
FROM {{ source('sakila', 'customer') }} c
LEFT JOIN {{ source('sakila', 'rental') }} r ON c.customer_id = r.customer_id
GROUP BY c.customer_id;
-- Revenue analysis
SELECT c.name as category, SUM(p.amount) as total_revenue
FROM {{ source('sakila', 'category') }} c
JOIN {{ source('sakila', 'film_category') }} fc ON c.category_id = fc.category_id
JOIN {{ source('sakila', 'film') }} f ON fc.film_id = f.film_id
JOIN {{ source('sakila', 'inventory') }} i ON f.film_id = i.film_id
JOIN {{ source('sakila', 'rental') }} r ON i.inventory_id = r.inventory_id
JOIN {{ source('sakila', 'payment') }} p ON r.rental_id = p.rental_id
GROUP BY c.category_id, c.name;Tests verify Sakila-specific macros work correctly:
get_films_by_category('Action')- Films in specific categoryget_customer_rentals(123)- Customer rental historyget_top_actors_by_film_count(10)- Most prolific actorsget_revenue_by_category()- Revenue analysis by film categoryget_overdue_rentals()- Overdue rental tracking
-
"Sakila database not found"
python scripts/setup_sakila_db.py
-
"dbt command not found"
pip install -r requirements-integration.txt
-
"Profile 'Sakila' not found"
- Check
~/.dbt/profiles.ymlexists and contains Sakila configuration - Verify
profiles/Sakila/models/schema.ymlexists
- Check
-
"Local .dbt folder not detected"
- Check if
.dbt/profiles.ymlexists in project root - Verify profile configuration is correct
- Run
python -c "from sqlbot.core.config import SQLBotConfig; print(SQLBotConfig.detect_dbt_profiles_dir())"to debug
- Check if
# Check database setup
sqlite3 profiles/Sakila/data/sakila.db "SELECT COUNT(*) FROM film;"
# Check dbt configuration
env DBT_PROFILE_NAME=Sakila dbt debug --profile Sakila
# Check profile paths
python -c "from sqlbot.core.schema import SchemaLoader; s=SchemaLoader('Sakila'); print(s.get_profile_paths())"
# Run single test with full output
pytest tests/integration/test_basic_setup.py::TestBasicSetup::test_sakila_database_file_exists -v -sIntegration tests require additional dependencies not needed for core SQLBot functionality:
- dbt-sqlite>=1.0.0 - SQLite adapter for dbt
- pytest-timeout>=2.1.0 - Test timeout handling
- SQLite3 - Usually pre-installed on most systems
Optional:
- OpenAI API key - For LLM-related functionality (most tests work without it)