Spaces:
Sleeping
Sleeping
Upload test_cart.py
Browse files- test_cart.py +52 -0
test_cart.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
BASE_URL = "http://localhost:8000/api"
|
| 4 |
+
|
| 5 |
+
# 1. Register User
|
| 6 |
+
print("Registering...")
|
| 7 |
+
res = requests.post(f"{BASE_URL}/auth/register", json={
|
| 8 |
+
"name": "Test User",
|
| 9 |
+
"email": "cartuser@vortex.com",
|
| 10 |
+
"password": "Password123!"
|
| 11 |
+
})
|
| 12 |
+
print("Register:", res.status_code, res.json())
|
| 13 |
+
|
| 14 |
+
# 2. Login
|
| 15 |
+
print("Logging in...")
|
| 16 |
+
res = requests.post(f"{BASE_URL}/auth/login", json={
|
| 17 |
+
"email": "cartuser@vortex.com",
|
| 18 |
+
"password": "Password123!"
|
| 19 |
+
})
|
| 20 |
+
print("Login:", res.status_code, res.json())
|
| 21 |
+
token = res.json()["value"]["tokens"]["access_token"]
|
| 22 |
+
headers = {"Authorization": f"Bearer {token}"}
|
| 23 |
+
|
| 24 |
+
# 3. Add item 1
|
| 25 |
+
print("Adding product 1...")
|
| 26 |
+
res = requests.post(f"{BASE_URL}/cart/items", json={
|
| 27 |
+
"product_id": 1,
|
| 28 |
+
"quantity": 2
|
| 29 |
+
}, headers=headers)
|
| 30 |
+
print("Add item 1:", res.status_code, res.json())
|
| 31 |
+
|
| 32 |
+
# 4. Add item 2
|
| 33 |
+
print("Adding product 2...")
|
| 34 |
+
res = requests.post(f"{BASE_URL}/cart/items", json={
|
| 35 |
+
"product_id": 2,
|
| 36 |
+
"quantity": 1
|
| 37 |
+
}, headers=headers)
|
| 38 |
+
print("Add item 2:", res.status_code, res.json())
|
| 39 |
+
|
| 40 |
+
# 5. Apply coupon
|
| 41 |
+
print("Applying coupon...")
|
| 42 |
+
res = requests.post(f"{BASE_URL}/cart/coupon", json={
|
| 43 |
+
"code": "WELCOME10"
|
| 44 |
+
}, headers=headers)
|
| 45 |
+
print("Apply coupon:", res.status_code, res.json())
|
| 46 |
+
|
| 47 |
+
# 6. Get Cart
|
| 48 |
+
print("Fetching cart...")
|
| 49 |
+
res = requests.get(f"{BASE_URL}/cart", headers=headers)
|
| 50 |
+
print("Get Cart:", res.status_code)
|
| 51 |
+
import json
|
| 52 |
+
print(json.dumps(res.json(), indent=2))
|