donb-hf commited on
Commit
9512958
β€’
1 Parent(s): 1a64a9e

add validation script

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. test_blackbird_api.py +54 -0
.gitignore CHANGED
@@ -2,3 +2,4 @@
2
  .env
3
  __pycache__/config.cpython-310.pyc
4
  __pycache__/tool_handler.cpython-310.pyc
 
 
2
  .env
3
  __pycache__/config.cpython-310.pyc
4
  __pycache__/tool_handler.cpython-310.pyc
5
+ __pycache__/response_formatter.cpython-310.pyc
test_blackbird_api.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import requests
3
+ import json
4
+ import random
5
+
6
+ def load_dataset(dataset_name):
7
+ return pd.read_parquet(f"hf://datasets/dwb2023/{dataset_name}/data/train-00000-of-00001.parquet")
8
+
9
+ def test_endpoint(base_url, endpoint, payload):
10
+ url = f"{base_url}{endpoint}"
11
+ print(f"\nTesting {endpoint}")
12
+ print(f"Request: POST {url}")
13
+ print(f"Payload: {json.dumps(payload, indent=2)}")
14
+ try:
15
+ response = requests.post(url, json=payload)
16
+ print(f"Response Status: {response.status_code}")
17
+ print(f"Response Body: {json.dumps(response.json(), indent=2)}")
18
+ if response.status_code == 200:
19
+ print(f"βœ… {endpoint} - Success")
20
+ else:
21
+ print(f"❌ {endpoint} - Failed")
22
+ except requests.exceptions.RequestException as e:
23
+ print(f"❌ {endpoint} - Error: {str(e)}")
24
+
25
+ def main(base_url):
26
+ print(f"Testing Blackbird API at {base_url}\n")
27
+
28
+ # Load datasets
29
+ customers_df = load_dataset("blackbird-customers")
30
+ orders_df = load_dataset("blackbird-orders")
31
+
32
+ # Prepare test cases
33
+ random_customer = customers_df.sample(1).iloc[0]
34
+ random_order = orders_df.sample(1).iloc[0]
35
+ processing_order = orders_df[orders_df['status'] == 'Processing'].sample(1).iloc[0]
36
+
37
+ endpoints = [
38
+ ("/get_user", {"key": "email", "value": random_customer['email']}),
39
+ ("/update_user", {"user_id": random_customer['id'], "email": f"updated_{random_customer['email']}", "phone": f"updated_{random_customer['phone']}"}),
40
+ ("/get_order_by_id", {"order_id": random_order['id']}),
41
+ ("/get_customer_orders", {"customer_id": random_customer['id']}),
42
+ ("/cancel_order", {"order_id": processing_order['id']}),
43
+ ("/get_user_info", {"key": "email", "value": f"updated_{random_customer['email']}"})
44
+ ]
45
+
46
+ for endpoint, payload in endpoints:
47
+ test_endpoint(base_url, endpoint, payload)
48
+
49
+ # Test get_user with old email (should return 404)
50
+ test_endpoint(base_url, "/get_user", {"key": "email", "value": random_customer['email']})
51
+
52
+ if __name__ == "__main__":
53
+ base_url = "https://dwb2023-blackbird-svc.hf.space"
54
+ main(base_url)