1+ #!/usr/bin/env python3
2+ """
3+ Infrastructure test script for SmartQuery backend services
4+ This script tests the configuration and setup of our infrastructure services
5+ """
6+
7+ import os
8+ import sys
9+ import asyncio
10+ from pathlib import Path
11+
12+ # Add backend to path
13+ backend_path = Path (__file__ ).parent .parent / "backend"
14+ sys .path .insert (0 , str (backend_path ))
15+
16+ def test_docker_compose_config ():
17+ """Test Docker Compose configuration"""
18+ print ("🐳 Testing Docker Compose Configuration..." )
19+
20+ docker_compose_path = Path (__file__ ).parent .parent / "docker-compose.yml"
21+ if docker_compose_path .exists ():
22+ print ("✅ docker-compose.yml exists" )
23+
24+ # Read and check basic structure
25+ with open (docker_compose_path ) as f :
26+ content = f .read ()
27+
28+ services = ["postgres" , "redis" , "minio" , "celery-worker" , "celery-flower" ]
29+ for service in services :
30+ if service in content :
31+ print (f"✅ { service } service configured" )
32+ else :
33+ print (f"❌ { service } service missing" )
34+
35+ # Check for required volumes
36+ if "volumes:" in content :
37+ print ("✅ Docker volumes configured" )
38+
39+ # Check for networks
40+ if "networks:" in content :
41+ print ("✅ Docker networks configured" )
42+
43+ else :
44+ print ("❌ docker-compose.yml not found" )
45+
46+ print ()
47+
48+ def test_backend_structure ():
49+ """Test backend project structure"""
50+ print ("📁 Testing Backend Project Structure..." )
51+
52+ backend_path = Path (__file__ ).parent .parent / "backend"
53+ required_files = [
54+ "main.py" ,
55+ "celery_app.py" ,
56+ "requirements.txt" ,
57+ "Dockerfile.celery" ,
58+ "api/health.py" ,
59+ "services/database_service.py" ,
60+ "services/redis_service.py" ,
61+ "services/storage_service.py" ,
62+ "tasks/file_processing.py"
63+ ]
64+
65+ for file_path in required_files :
66+ full_path = backend_path / file_path
67+ if full_path .exists ():
68+ print (f"✅ { file_path } " )
69+ else :
70+ print (f"❌ { file_path } missing" )
71+
72+ print ()
73+
74+ def test_database_init ():
75+ """Test database initialization scripts"""
76+ print ("🗄️ Testing Database Initialization..." )
77+
78+ db_init_path = Path (__file__ ).parent .parent / "database" / "init" / "01_init.sql"
79+ if db_init_path .exists ():
80+ print ("✅ Database initialization script exists" )
81+
82+ with open (db_init_path ) as f :
83+ content = f .read ()
84+
85+ tables = ["users" , "projects" , "chat_messages" ]
86+ for table in tables :
87+ if f"CREATE TABLE IF NOT EXISTS { table } " in content :
88+ print (f"✅ { table } table creation script" )
89+ else :
90+ print (f"❌ { table } table creation script missing" )
91+ else :
92+ print ("❌ Database initialization script missing" )
93+
94+ print ()
95+
96+ def test_environment_config ():
97+ """Test environment configuration"""
98+ print ("⚙️ Testing Environment Configuration..." )
99+
100+ # Check for required environment variables structure
101+ required_env_vars = [
102+ "DATABASE_URL" ,
103+ "REDIS_URL" ,
104+ "MINIO_ENDPOINT" ,
105+ "MINIO_ACCESS_KEY" ,
106+ "MINIO_SECRET_KEY" ,
107+ "CELERY_BROKER_URL" ,
108+ "CELERY_RESULT_BACKEND"
109+ ]
110+
111+ print ("Required environment variables:" )
112+ for var in required_env_vars :
113+ if var in ["MINIO_ACCESS_KEY" , "MINIO_SECRET_KEY" ]:
114+ print (f"🔑 { var } (configured in docker-compose)" )
115+ else :
116+ print (f"✅ { var } (configured in docker-compose)" )
117+
118+ print ()
119+
120+ def test_service_imports ():
121+ """Test that services can be imported"""
122+ print ("📦 Testing Service Imports..." )
123+
124+ try :
125+ from services .database_service import db_service
126+ print ("✅ Database service imports successfully" )
127+ except Exception as e :
128+ print (f"❌ Database service import failed: { e } " )
129+
130+ try :
131+ from services .redis_service import redis_service
132+ print ("✅ Redis service imports successfully" )
133+ except Exception as e :
134+ print (f"❌ Redis service import failed: { e } " )
135+
136+ try :
137+ from services .storage_service import storage_service
138+ print ("✅ Storage service imports successfully" )
139+ except Exception as e :
140+ print (f"❌ Storage service import failed: { e } " )
141+
142+ try :
143+ from celery_app import celery_app
144+ print ("✅ Celery app imports successfully" )
145+ except Exception as e :
146+ print (f"❌ Celery app import failed: { e } " )
147+
148+ print ()
149+
150+ def test_requirements ():
151+ """Test requirements.txt has necessary dependencies"""
152+ print ("📋 Testing Requirements..." )
153+
154+ req_path = Path (__file__ ).parent .parent / "backend" / "requirements.txt"
155+ if req_path .exists ():
156+ with open (req_path ) as f :
157+ content = f .read ()
158+
159+ dependencies = [
160+ "psycopg2-binary" ,
161+ "redis" ,
162+ "celery" ,
163+ "minio" ,
164+ "sqlalchemy"
165+ ]
166+
167+ for dep in dependencies :
168+ if dep in content :
169+ print (f"✅ { dep } " )
170+ else :
171+ print (f"❌ { dep } missing from requirements" )
172+ else :
173+ print ("❌ requirements.txt not found" )
174+
175+ print ()
176+
177+ def main ():
178+ """Run all infrastructure tests"""
179+ print ("🚀 SmartQuery Infrastructure Test Suite" )
180+ print ("=" * 50 )
181+ print ()
182+
183+ test_docker_compose_config ()
184+ test_backend_structure ()
185+ test_database_init ()
186+ test_environment_config ()
187+ test_service_imports ()
188+ test_requirements ()
189+
190+ print ("✨ Infrastructure test completed!" )
191+ print ()
192+ print ("📝 Next steps:" )
193+ print ("1. Install Docker and Docker Compose" )
194+ print ("2. Run: docker compose up -d" )
195+ print ("3. Test with: cd backend && python main.py" )
196+ print ("4. Check health: curl http://localhost:8000/health/" )
197+
198+ if __name__ == "__main__" :
199+ main ()
0 commit comments