|
|
@@ -0,0 +1,44 @@
|
|
|
+import time
|
|
|
+import httpx
|
|
|
+import asyncio
|
|
|
+import json
|
|
|
+
|
|
|
+async def run_tests():
|
|
|
+ url = "http://127.0.0.1:8000"
|
|
|
+
|
|
|
+ async with httpx.AsyncClient() as client:
|
|
|
+ # Create test user for token
|
|
|
+ try:
|
|
|
+ await client.post(f"{url}/api/register", json={"username":"validator","password":"pwdtest123","confirmPassword":"pwdtest123"})
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+
|
|
|
+ res = await client.post(f"{url}/api/login", json={"username":"validator","password":"pwdtest123"})
|
|
|
+ token = res.json().get("token", "")
|
|
|
+ headers = {"Authorization": f"Bearer {token}"}
|
|
|
+
|
|
|
+ print("=== TEST 1: Empty Query ===")
|
|
|
+ t0 = time.perf_counter()
|
|
|
+ r1 = await client.get(f"{url}/api/food/search?q=", headers=headers)
|
|
|
+ t1 = time.perf_counter()
|
|
|
+ print(f"Timing: {(t1-t0)*1000:.2f} ms")
|
|
|
+ print(f"Payload snippet: {r1.text[:100]}")
|
|
|
+
|
|
|
+ print("\n=== TEST 2: Single Letter ('c') ===")
|
|
|
+ t0 = time.perf_counter()
|
|
|
+ r2 = await client.get(f"{url}/api/food/search?q=c", headers=headers)
|
|
|
+ t1 = time.perf_counter()
|
|
|
+ print(f"Timing: {(t1-t0)*1000:.2f} ms")
|
|
|
+ res2 = r2.json().get('results', [])
|
|
|
+ print(f"Returned Items: {len(res2)}")
|
|
|
+ if res2:
|
|
|
+ print(f"Expected Field Verification: {list(res2[0].keys())}")
|
|
|
+
|
|
|
+ print("\n=== TEST 3: No Match ('xyzabcd') ===")
|
|
|
+ t0 = time.perf_counter()
|
|
|
+ r3 = await client.get(f"{url}/api/food/search?q=xyzabcd", headers=headers)
|
|
|
+ t1 = time.perf_counter()
|
|
|
+ print(f"Timing: {(t1-t0)*1000:.2f} ms")
|
|
|
+ print(f"Response: {r3.json()}")
|
|
|
+
|
|
|
+asyncio.run(run_tests())
|