137 lines
4.2 KiB
Python
137 lines
4.2 KiB
Python
import requests
|
|
import json
|
|
|
|
# Configuration
|
|
BASE_URL = "https://dev-api.oneskyit.com/v3/crud"
|
|
# Valid account id_random provided by user
|
|
ACCOUNT_ID = "nqOzejLCDXM"
|
|
|
|
headers = {
|
|
"X-Account-ID": ACCOUNT_ID,
|
|
"Content-Type": "application/json"
|
|
}
|
|
|
|
def test_search(obj_type, query, description):
|
|
"""
|
|
Helper to run a search test and print results.
|
|
"""
|
|
print(f"--- Testing: {description} ---")
|
|
url = f"{BASE_URL}/{obj_type}/search"
|
|
|
|
try:
|
|
response = requests.post(url, headers=headers, json=query)
|
|
print(f"Status Code: {response.status_code}")
|
|
|
|
data = response.json()
|
|
|
|
# Check if the result is a list or single object
|
|
result_data = data.get('data')
|
|
if isinstance(result_data, list):
|
|
print(f"Result Count: {len(result_data)}")
|
|
if len(result_data) > 0:
|
|
# Print first item as example
|
|
print(f"First Item Example: {json.dumps(result_data[0], indent=2)[:200]}...")
|
|
else:
|
|
print(f"Result Type: {type(result_data)}")
|
|
print(f"Result Data: {json.dumps(result_data, indent=2)}")
|
|
|
|
if response.status_code != 200:
|
|
print(f"Meta Details: {json.dumps(data.get('meta', {}), indent=2)}")
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print(f"Error: Could not connect to {BASE_URL}. Is the API running?")
|
|
except Exception as e:
|
|
print(f"Error during test: {e}")
|
|
print("-" * 40 + "\n")
|
|
|
|
if __name__ == "__main__":
|
|
print(f"Starting Aether V3 Search Tests against {BASE_URL}\n")
|
|
|
|
# 1. Simple Equality
|
|
# Tests 'eq' operator on 'journal'
|
|
query_eq = {
|
|
"and": [
|
|
{"field": "enable", "op": "eq", "value": True}
|
|
]
|
|
}
|
|
test_search("journal", query_eq, "Simple Equality (enable=True)")
|
|
|
|
# 2. LIKE search
|
|
# Tests 'like' operator with wildcards on 'name' field (corrected from 'title')
|
|
# Using '%' to catch any journals with names
|
|
query_like = {
|
|
"and": [
|
|
{"field": "name", "op": "like", "value": "%"}
|
|
]
|
|
}
|
|
test_search("journal", query_like, "LIKE search (name LIKE '%')")
|
|
|
|
# 3. Numeric Comparison
|
|
# Tests 'gt' (Greater Than) operator
|
|
query_gt = {
|
|
"and": [
|
|
{"field": "id", "op": "gt", "value": 0}
|
|
]
|
|
}
|
|
test_search("journal", query_gt, "Numeric Comparison (internal id > 0)")
|
|
|
|
# 4. Complex Nested Logic (AND + OR)
|
|
# Tests recursive grouping: (enable=True) AND (name LIKE % % OR summary IS NOT NULL)
|
|
query_nested = {
|
|
"and": [
|
|
{"field": "enable", "op": "eq", "value": True},
|
|
{
|
|
"or": [
|
|
{"field": "name", "op": "like", "value": "%Journal%"},
|
|
{"field": "summary", "op": "is_not_null"}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
test_search("journal", query_nested, "Nested Logic (AND + OR group)")
|
|
|
|
# 5. IN List
|
|
# Tests 'in' operator with a list of values
|
|
# Based on previous results, we know id 1 exists for journal
|
|
query_in = {
|
|
"and": [
|
|
{"field": "journal_id", "op": "in", "value": [1, 2, 3]}
|
|
]
|
|
}
|
|
test_search("journal_entry", query_in, "IN List search (journal_entry with journal_id in [1,2,3])")
|
|
|
|
# 6. NULL Check
|
|
# Tests 'is_null' operator
|
|
query_null = {
|
|
"and": [
|
|
{"field": "notes", "op": "is_null"}
|
|
]
|
|
}
|
|
test_search("site", query_null, "Null Check (notes is NULL)")
|
|
|
|
# 7. Event Search
|
|
query_event = {
|
|
"and": [
|
|
{"field": "enable", "op": "eq", "value": True},
|
|
{"field": "name", "op": "like", "value": "%"}
|
|
]
|
|
}
|
|
test_search("event", query_event, "Event Search (enable=True and has name)")
|
|
|
|
# 8. Event Badge Search
|
|
query_badge = {
|
|
"and": [
|
|
{"field": "event_id", "op": "gt", "value": 0}
|
|
]
|
|
}
|
|
test_search("event_badge", query_badge, "Event Badge Search (event_id > 0)")
|
|
|
|
# 9. Event Location Search
|
|
query_location = {
|
|
"and": [
|
|
{"field": "name", "op": "like", "value": "%"}
|
|
]
|
|
}
|
|
test_search("event_location", query_location, "Event Location Search (has name)")
|
|
|
|
print("Tests Complete.") |