File size: 1,532 Bytes
4e7b77b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
"""

Test database connection in Docker environment

"""

from app.services.database_service import DatabaseManager
import os
import sys
import sqlite3
import logging

# Add the app directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'app'))


def test_database_connection():
    """Test database connection and initialization"""
    print("Testing database connection...")

    try:
        # Test with default path
        db_manager = DatabaseManager()
        print(f"βœ… Database manager created with path: {db_manager.db_path}")

        # Test initialization
        db_manager.initialize()
        print("βœ… Database initialized successfully")

        # Test connection
        if db_manager.is_connected():
            print("βœ… Database connection verified")
        else:
            print("❌ Database connection failed")
            return False

        # Test basic operations
        cursor = db_manager.connection.cursor()
        cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
        tables = cursor.fetchall()
        print(f"βœ… Found {len(tables)} tables in database")

        db_manager.close()
        print("βœ… Database connection closed successfully")

        return True

    except Exception as e:
        print(f"❌ Database test failed: {e}")
        return False


if __name__ == "__main__":
    success = test_database_connection()
    sys.exit(0 if success else 1)