-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_system.py
More file actions
61 lines (57 loc) · 1.81 KB
/
test_system.py
File metadata and controls
61 lines (57 loc) · 1.81 KB
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
56
57
58
59
60
61
import sys
print("Starting script...", flush=True)
try:
import requests
print("Requests imported", flush=True)
from backend.database import SessionLocal
print("SessionLocal imported", flush=True)
from backend.models import Product, Order
print("Models imported", flush=True)
import websockets
print("Websockets imported", flush=True)
import asyncio
import json
except Exception as e:
print(f"Import failed: {e}", flush=True)
sys.exit(1)
def seed_product():
print("Seeding...", flush=True)
try:
db = SessionLocal()
if db.query(Product).count() == 0:
p = Product(
name="Test Burger",
description="Tasty",
price=9.99,
category="Burgers",
is_available=True,
modifiers={"size": ["S", "M"]}
)
db.add(p)
db.commit()
print("Seeded Product.", flush=True)
else:
print("Products already exist.", flush=True)
db.close()
except Exception as e:
print(f"Seeding failed: {e}", flush=True)
def test_api():
print("Testing API...", flush=True)
try:
r = requests.get("http://127.0.0.1:8000/products/")
print(f"GET /products/: Status {r.status_code}", flush=True)
print(f"Body: {r.text}", flush=True)
except Exception as e:
print(f"API Test Failed: {e}", flush=True)
async def test_ws():
print("Testing WS...", flush=True)
uri = "ws://127.0.0.1:8000/ws/kitchen"
try:
async with websockets.connect(uri) as websocket:
print("WebSocket Connected!", flush=True)
except Exception as e:
print(f"WebSocket Test Failed: {e}", flush=True)
if __name__ == "__main__":
seed_product()
test_api()
asyncio.run(test_ws())