Skip to content

Commit 8d7b424

Browse files
committed
refactor(test_csv_upload.py): update API endpoint paths and response handling to improve clarity and functionality
fix(test_csv_upload.py): change job ID retrieval from "id" to "job_id" for consistency with API response structure feat(test_csv_upload.py): enhance API endpoint fetching and error handling for better debugging and user feedback
1 parent 7c4d6c3 commit 8d7b424

File tree

1 file changed

+61
-103
lines changed

1 file changed

+61
-103
lines changed

tests/test_csv_upload.py

Lines changed: 61 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def subscribe_to_datasource_jobs(client, datasource_id, callback=None, timeout=3
667667
try:
668668
# Query for all jobs with this datasource as source
669669
response = client.http_client.get(
670-
f"{client.base_url}/v1/jobs/status",
670+
f"{client.base_url}/v1/jobs/by-source",
671671
params={"source": "datasource", "source_id": datasource_id},
672672
)
673673

@@ -689,7 +689,7 @@ def subscribe_to_datasource_jobs(client, datasource_id, callback=None, timeout=3
689689

690690
# Start monitoring any new jobs we find
691691
for job in jobs:
692-
job_id = job.get("id")
692+
job_id = job.get("job_id")
693693
if job_id and job_id not in monitored_jobs:
694694
logger.info(
695695
f"Found new job to monitor: {job_id} (status: {job.get('status')})"
@@ -942,113 +942,71 @@ def main(): # noqa: C901
942942
# Step 9: List API endpoints
943943
print_step(9, "List API endpoints")
944944

945-
try:
946-
# Try to get endpoints through the API if available
947-
# This is a placeholder - adjust according to the actual API endpoints
948-
print("Available API endpoints:")
949-
for i, qp in enumerate(published_queries, 1):
950-
endpoint_path = f"/v1/live/{project.id}/{qp.id}/data"
951-
print(f" {i}. {qp.name}")
952-
print(f" Endpoint: {client.base_url}{endpoint_path}")
953-
print(" Method: GET")
954-
955-
# Try to get OpenAPI spec if available
956-
print("\nAPI Documentation (OpenAPI):")
957-
print(f" URL: {client.base_url}/v1/openapi/{project.id}")
958-
except Exception as e:
959-
print(f"Error listing endpoints: {e}")
945+
print("Fetching API endpoints for the project...")
946+
response = client.http_client.get(f"{client.base_url}/v1/apis/project/{project.id}")
947+
948+
if response.status_code == 200:
949+
apis = response.json()
950+
print(f"Found {len(apis)} APIs for project {project.id}")
951+
952+
for i, api in enumerate(apis, 1):
953+
print(f" {i}. API ID: {api.get('id')}")
954+
print(f" Path: {api.get('base_path', 'Unknown')}")
955+
print(f" Name: {api.get('name', 'Unnamed')}")
956+
print(f" Description: {api.get('description', 'Unknown')}")
957+
print(f" Version: {api.get('version', 'v1')}")
958+
else:
959+
print(f"Error fetching APIs: {response.status_code} {response.text}")
960+
raise Exception(f"Error fetching APIs: {response.status_code} {response.text}")
961+
962+
# Try to get endpoints through the API if available
963+
print("Available API endpoints:")
964+
for i, endpoint in enumerate(api["endpoints"]):
965+
path = endpoint["path"]
966+
url = f"{client.base_url}/live/{api['base_path']}/{api['version']}/{path}"
967+
print(f" {i}. {url}")
968+
else:
969+
print("No endpoints available to test")
970+
971+
# Try to get OpenAPI spec if available
972+
print("\nAPI Documentation (OpenAPI):")
973+
print(
974+
f" URL: {client.base_url}/live/{api['base_path']}/{api['version']}/openapi.json"
975+
)
976+
print("\nLLM Tools Compatibility:")
977+
print(
978+
f" URL: {client.base_url}/live/{api['base_path']}/{api['version']}/tools.json"
979+
)
960980

961981
# Step 10: Make API requests with custom parameters
962-
print_step(10, "Make API requests with custom parameters")
963-
964-
if published_queries:
965-
try:
966-
# Pick the first published query for testing
967-
test_query = published_queries[0]
968-
endpoint_path = f"/v1/live/{project.id}/{test_query.id}/data"
969-
full_url = f"{client.base_url}{endpoint_path}"
970-
971-
print(f"Testing API endpoint: {full_url}")
972-
print("With parameters: limit=5, sort_by=date")
982+
print_step(10, "Make API requests with default parameters")
973983

974-
headers = {
975-
"Authorization": f"Bearer {API_KEY}",
976-
"Content-Type": "application/json",
977-
}
984+
# Try to get endpoints through the API if available
985+
print("Available API endpoints:")
986+
for i, endpoint in enumerate(api["endpoints"]):
987+
path = endpoint["path"]
988+
url = f"{client.base_url}/live/{api['base_path']}/{api['version']}/{path}"
989+
print(f" {i}. {url}")
978990

979-
params = {"limit": 5, "sort_by": "date"}
980-
981-
response = requests.get(full_url, headers=headers, params=params)
991+
headers = {
992+
"Authorization": f"Bearer {API_KEY}",
993+
"Content-Type": "application/json",
994+
}
982995

983-
if response.status_code == 200:
984-
print("API request successful!")
985-
result = response.json()
986-
print(json.dumps(result, indent=2))
987-
else:
988-
print(f"API request failed with status code {response.status_code}")
989-
print(response.text)
990-
991-
# If real API fails, show mock data
992-
print("\nMock response for demonstration:")
993-
mock_response = {
994-
"data": [
995-
{
996-
"date": "2023-03-01",
997-
"symbol": "AAPL",
998-
"price": 145.91,
999-
"volume": 83521000,
1000-
},
1001-
{
1002-
"date": "2023-03-02",
1003-
"symbol": "AAPL",
1004-
"price": 149.58,
1005-
"volume": 75684300,
1006-
},
1007-
{
1008-
"date": "2023-03-03",
1009-
"symbol": "AAPL",
1010-
"price": 151.03,
1011-
"volume": 70898900,
1012-
},
1013-
],
1014-
"meta": {
1015-
"count": 3,
1016-
"total": 22,
1017-
"sort_by": "date",
1018-
"order": "asc",
1019-
},
1020-
}
1021-
print(json.dumps(mock_response, indent=2))
996+
response = requests.get(url, headers=headers)
997+
if response.status_code == 200:
998+
result = response.json()
999+
print(
1000+
f"\033[34mResponse data: {json.dumps(result, indent=2)[:500]}...\033[0m"
1001+
) # Truncate long responses
1002+
else:
1003+
print(f"Request failed with status code {response.status_code}")
1004+
print(f"Response: {response.text}")
1005+
else:
1006+
print("No endpoints available to test")
10221007

1023-
except Exception as e:
1024-
print(f"Error making API request: {e}")
1025-
1026-
# Show mock data if real request fails
1027-
print("\nMock response for demonstration:")
1028-
mock_response = {
1029-
"data": [
1030-
{
1031-
"date": "2023-03-01",
1032-
"symbol": "AAPL",
1033-
"price": 145.91,
1034-
"volume": 83521000,
1035-
},
1036-
{
1037-
"date": "2023-03-02",
1038-
"symbol": "AAPL",
1039-
"price": 149.58,
1040-
"volume": 75684300,
1041-
},
1042-
{
1043-
"date": "2023-03-03",
1044-
"symbol": "AAPL",
1045-
"price": 151.03,
1046-
"volume": 70898900,
1047-
},
1048-
],
1049-
"meta": {"count": 3, "total": 22, "sort_by": "date", "order": "asc"},
1050-
}
1051-
print(json.dumps(mock_response, indent=2))
1008+
if not published_queries:
1009+
raise Exception("No published queries found")
10521010

10531011
# Step 11: Use the chat endpoint with streaming response
10541012
print_step(11, "Use the chat endpoint with streaming response")

0 commit comments

Comments
 (0)