bae705aa97
- Add NFC ePassport roadmap (ICAO 9303, eIDAS) - Add TensorFlow.js edge face detection (BlazeFace) - Add structured audit logger (GDPR-compliant) - Risk scoring support Part of KYC Apple Native UX v1.1.0
141 lines
3.8 KiB
Python
141 lines
3.8 KiB
Python
"""
|
|
API Integration Tests for IOM
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
|
|
BASE_URL = "http://localhost:8000"
|
|
|
|
def test_health():
|
|
"""Test health endpoint"""
|
|
r = requests.get(f"{BASE_URL}/health")
|
|
assert r.status_code == 200
|
|
data = r.json()
|
|
assert data["status"] == "healthy"
|
|
print("✓ Health check")
|
|
|
|
def test_taxonomy():
|
|
"""Test taxonomy endpoints"""
|
|
# List domains
|
|
r = requests.get(f"{BASE_URL}/taxonomy/domains")
|
|
assert r.status_code == 200
|
|
domains = r.json()
|
|
assert len(domains) == 5
|
|
print(f"✓ Domains: {len(domains)}")
|
|
|
|
# List systems
|
|
r = requests.get(f"{BASE_URL}/taxonomy/domains/BYG/systems")
|
|
assert r.status_code == 200
|
|
systems = r.json()
|
|
assert len(systems) > 0
|
|
print(f"✓ Systems in BYG: {len(systems)}")
|
|
|
|
# List objects
|
|
r = requests.get(f"{BASE_URL}/taxonomy/domains/BYG/systems/FAC/objects")
|
|
assert r.status_code == 200
|
|
objects = r.json()
|
|
assert len(objects) > 0
|
|
print(f"✓ Objects in BYG/FAC: {len(objects)}")
|
|
|
|
def test_goid():
|
|
"""Test GOID endpoints"""
|
|
# Generate
|
|
r = requests.post(f"{BASE_URL}/goid/generate", params={
|
|
"domain": "BYG",
|
|
"system": "FAC",
|
|
"subsystem": "WIN",
|
|
"obj_type": "GLA"
|
|
})
|
|
assert r.status_code == 200
|
|
goid = r.json()["goid"]
|
|
assert goid.startswith("BYG-FAC-WIN-GLA-")
|
|
print(f"✓ Generated GOID: {goid}")
|
|
|
|
# Validate
|
|
r = requests.get(f"{BASE_URL}/goid/validate/{goid}")
|
|
assert r.status_code == 200
|
|
assert r.json()["valid"] == True
|
|
print("✓ GOID valid")
|
|
|
|
# Parse
|
|
r = requests.get(f"{BASE_URL}/goid/parse/{goid}")
|
|
assert r.status_code == 200
|
|
parsed = r.json()
|
|
assert parsed["domain"] == "BYG"
|
|
print(f"✓ Parsed: {parsed['domain_name']}")
|
|
|
|
def test_defects():
|
|
"""Test defect endpoints"""
|
|
# List all
|
|
r = requests.get(f"{BASE_URL}/defects")
|
|
assert r.status_code == 200
|
|
defects = r.json()
|
|
assert len(defects) > 0
|
|
print(f"✓ Defect codes: {len(defects)}")
|
|
|
|
# Get specific
|
|
r = requests.get(f"{BASE_URL}/defects/2100")
|
|
assert r.status_code == 200
|
|
defect = r.json()
|
|
assert defect["code"] == "2100"
|
|
print(f"✓ Defect 2100: {defect['name']}")
|
|
|
|
# Search
|
|
r = requests.get(f"{BASE_URL}/defects/search/spricka")
|
|
assert r.status_code == 200
|
|
results = r.json()
|
|
print(f"✓ Search 'spricka': {len(results)} results")
|
|
|
|
def test_risk():
|
|
"""Test risk endpoints"""
|
|
# Calculate
|
|
r = requests.post(f"{BASE_URL}/risk/calculate", json={
|
|
"safety": 8,
|
|
"economic": 6,
|
|
"environmental": 2,
|
|
"operational": 5,
|
|
"legal": 4,
|
|
"aesthetic": 1
|
|
}, params={"object_type": "bridge"})
|
|
assert r.status_code == 200
|
|
result = r.json()
|
|
assert "total" in result
|
|
print(f"✓ Risk: {result['total']} ({result['level']})")
|
|
|
|
# From observation
|
|
r = requests.post(f"{BASE_URL}/risk/calculate-from-observation", params={
|
|
"condition": 3,
|
|
"object_type": "facade"
|
|
}, json=["2100", "2200"])
|
|
assert r.status_code == 200
|
|
result = r.json()
|
|
print(f"✓ Risk from obs: {result['total']} ({result['level']})")
|
|
|
|
def test_ledger():
|
|
"""Test ledger endpoints"""
|
|
# Installation
|
|
r = requests.post(f"{BASE_URL}/ledger/installation", params={
|
|
"goid": "TRN-BRG-ABT-CON-001",
|
|
"object_type": "abutment",
|
|
"cost": "4500000",
|
|
"installation_date": "2019-03-15",
|
|
"contractor": "Skanska AB"
|
|
})
|
|
assert r.status_code == 200
|
|
result = r.json()
|
|
assert len(result["transactions"]) == 2
|
|
print(f"✓ Ledger: {len(result['transactions'])} transactions")
|
|
|
|
if __name__ == "__main__":
|
|
print("=== IOM API Tests ===\n")
|
|
|
|
test_health()
|
|
test_taxonomy()
|
|
test_goid()
|
|
test_defects()
|
|
test_risk()
|
|
test_ledger()
|
|
|
|
print("\n=== All tests passed ===")
|