BOLO-KESARI commited on
Commit
353364e
·
1 Parent(s): 9c339b7

Add test script and fix DB path logic

Browse files
Files changed (2) hide show
  1. backend/app/core/config.py +6 -1
  2. test_deployment.py +76 -0
backend/app/core/config.py CHANGED
@@ -10,7 +10,12 @@ class Settings(BaseSettings):
10
  """Application settings loaded from environment variables."""
11
 
12
  # Database
13
- DATABASE_URL: str = "sqlite:///./stock_analysis.db"
 
 
 
 
 
14
 
15
  # JWT Settings
16
  SECRET_KEY: str = "development_secret_key_change_in_production"
 
10
  """Application settings loaded from environment variables."""
11
 
12
  # Database
13
+ # Use /app/data for Docker persistence (if volume mounted) or just writable area
14
+ # Fallback to local relative path for development
15
+ # Database
16
+ # Use /app/data for Docker persistence (if volume mounted) or just writable area
17
+ # Fallback to local relative path for development
18
+ DATABASE_URL: str = "sqlite:///data/stock_analysis.db"
19
 
20
  # JWT Settings
21
  SECRET_KEY: str = "development_secret_key_change_in_production"
test_deployment.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import requests
3
+ import json
4
+ import time
5
+
6
+ BASE_URL = "https://pranit144-finance.hf.space"
7
+ # Optional: test local if needed
8
+ # BASE_URL = "http://localhost:8000"
9
+
10
+ def test_endpoint(name, method, path, data=None, token=None):
11
+ url = f"{BASE_URL}{path}"
12
+ headers = {"Content-Type": "application/json"}
13
+ if token:
14
+ headers["Authorization"] = f"Bearer {token}"
15
+
16
+ print(f"\n🚀 Testing {name}...")
17
+ print(f" {method} {url}")
18
+
19
+ try:
20
+ if method == "GET":
21
+ response = requests.get(url, headers=headers, timeout=15)
22
+ elif method == "POST":
23
+ response = requests.post(url, headers=headers, json=data, timeout=15)
24
+
25
+ print(f" Status: {response.status_code}")
26
+ try:
27
+ body = response.json()
28
+ print(f" Response: {json.dumps(body, indent=2)}")
29
+ return body
30
+ except:
31
+ print(f" Response: {response.text[:200]}")
32
+ return None
33
+ except Exception as e:
34
+ print(f" ❌ Error: {e}")
35
+ return None
36
+
37
+ def run_all_tests():
38
+ print(f"=== DEPLOYMENT TEST SUITE: {BASE_URL} ===")
39
+
40
+ # 1. Health
41
+ test_endpoint("Health Check", "GET", "/health")
42
+
43
+ # 2. Signup
44
+ timestamp = int(time.time())
45
+ test_email = f"test_user_{timestamp}@example.com"
46
+ signup_data = {
47
+ "email": test_email,
48
+ "password": "password123",
49
+ "name": "Test User",
50
+ "role": "STAFF"
51
+ }
52
+ signup_res = test_endpoint("Signup", "POST", "/auth/signup", data=signup_data)
53
+
54
+ # 3. Login
55
+ login_data = {
56
+ "email": test_email,
57
+ "password": "password123"
58
+ }
59
+ login_res = test_endpoint("Login", "POST", "/auth/login", data=login_data)
60
+
61
+ token = None
62
+ if login_res and "access_token" in login_res:
63
+ token = login_res["access_token"]
64
+ print(" ✅ Got Auth Token!")
65
+ else:
66
+ print(" ❌ Failed to get auth token")
67
+ return
68
+
69
+ # 4. Protected: Get Popular Stocks
70
+ test_endpoint("Popular Stocks (Auth)", "GET", "/stocks/popular", token=token)
71
+
72
+ # 5. Protected: Get Portfolio (Expected empty)
73
+ test_endpoint("Get Portfolio (Auth)", "GET", "/portfolio/", token=token)
74
+
75
+ if __name__ == "__main__":
76
+ run_all_tests()