feat: implement V3 Uniform Lookup System with hierarchical overrides and site-based whitelisting
This commit is contained in:
86
tests/e2e/test_e2e_v3_lookup.py
Normal file
86
tests/e2e/test_e2e_v3_lookup.py
Normal file
@@ -0,0 +1,86 @@
|
||||
import requests
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Ensure local imports work if needed
|
||||
sys.path.append(os.getcwd())
|
||||
|
||||
# Configuration
|
||||
BASE_URL = "https://dev-api.oneskyit.com/v3/lookup"
|
||||
HEADERS = {
|
||||
"x-aether-api-key": "PMM4n50teUCaOMMTN8qOJA", # Standard Agent Key
|
||||
"x-account-id": "_XY7DXtc9MY" # One Sky IT Demo
|
||||
}
|
||||
|
||||
# TODO: SET THIS to your demo site's random ID
|
||||
SITE_ID_RANDOM = "92vkYC4fVEl"
|
||||
|
||||
def print_result(label, success, message=""):
|
||||
status = "✅ PASS" if success else "❌ FAIL"
|
||||
print(f"{status} | {label} {': ' + message if message else ''}")
|
||||
|
||||
def test_lookup_list(lu_type, site_id=None):
|
||||
label = f"GET /{lu_type}/list"
|
||||
url = f"{BASE_URL}/{lu_type}/list"
|
||||
params = {}
|
||||
if site_id:
|
||||
params["site_id"] = site_id
|
||||
label += f" (Site: {site_id})"
|
||||
|
||||
try:
|
||||
start_time = time.time()
|
||||
response = requests.get(url, headers=HEADERS, params=params)
|
||||
duration = time.time() - start_time
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json().get('data', [])
|
||||
msg = f"Found {len(data)} items ({duration:.2f}s)"
|
||||
print_result(label, True, msg)
|
||||
return data
|
||||
else:
|
||||
print_result(label, False, f"Status {response.status_code}: {response.text[:100]}")
|
||||
return None
|
||||
except Exception as e:
|
||||
print_result(label, False, str(e))
|
||||
return None
|
||||
|
||||
def test_lookup_resolve(lu_type, query):
|
||||
url = f"{BASE_URL}/{lu_type}/resolve"
|
||||
params = {"q": query}
|
||||
try:
|
||||
response = requests.get(url, headers=HEADERS, params=params)
|
||||
if response.status_code == 200:
|
||||
data = response.json().get('data', {})
|
||||
name = data.get('name')
|
||||
print_result(f"GET /{lu_type}/resolve?q={query}", True, f"Resolved to '{name}'")
|
||||
return True
|
||||
else:
|
||||
print_result(f"GET /{lu_type}/resolve?q={query}", False, f"Status {response.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print_result(f"GET /{lu_type}/resolve?q={query}", False, str(e))
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"🚀 Starting V3 Lookup E2E Suite ({BASE_URL})\n")
|
||||
start_suite = time.time()
|
||||
|
||||
# 1. Basic Lists (Phase 1)
|
||||
test_lookup_list("country")
|
||||
test_lookup_list("time_zone")
|
||||
|
||||
# 2. Whitelist Test (Phase 2)
|
||||
if SITE_ID_RANDOM != "SET_ME_TO_SITE_ID":
|
||||
print("\n--- Testing Site Whitelist Policy ---")
|
||||
# Should return only whitelisted items
|
||||
test_lookup_list("country", site_id=SITE_ID_RANDOM)
|
||||
test_lookup_list("time_zone", site_id=SITE_ID_RANDOM)
|
||||
else:
|
||||
print("\n⚠️ Skipping Phase 2 test: SITE_ID_RANDOM not set.")
|
||||
|
||||
# 3. Resolve Test
|
||||
print("\n--- Testing Resolve ---")
|
||||
test_lookup_resolve("country", "US")
|
||||
|
||||
print(f"\n⏱️ Suite completed in {time.time() - start_suite:.2f}s")
|
||||
Reference in New Issue
Block a user