bmc_hub/keepforlater/test_ai_analyze.py
Christian a604a3cc44 Add comprehensive test suite for vTiger integration and ticket module
- Implemented test scripts for vTiger account retrieval, contact data, and modules.
- Created a detailed test suite for the ticket module, covering database schema validation, ticket number generation, prepaid card constraints, and service logic.
- Added tests for vTiger field inspection and various queries related to accounts and sales orders.
- Introduced SQL migration scripts for the ALSO Cloud Billing foundation, including import jobs, lines, and mapping tables with necessary constraints and indices.
- Enhanced workflow columns in the import lines table to support matching and validation timestamps.
2026-06-20 03:29:51 +02:00

49 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Test AI analyze endpoint med CVR filter"""
import requests
import pdfplumber
import json
from pathlib import Path
# Extract PDF text
pdf_path = Path("uploads/5082481.pdf")
all_text = []
with pdfplumber.open(pdf_path) as pdf:
for page in pdf.pages:
page_text = page.extract_text(layout=True, x_tolerance=2, y_tolerance=2)
if page_text:
all_text.append(page_text)
full_text = "\n".join(all_text)
# Call AI analyze endpoint
print("🧪 Testing AI analyze endpoint...")
response = requests.post(
'http://localhost:8000/api/v1/supplier-invoices/ai/analyze',
json={'pdf_text': full_text[:2000]}, # First 2000 chars as in the actual code
headers={'Content-Type': 'application/json'}
)
print(f"Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"\n✅ AI Analysis Result:")
print(f" CVR: {result.get('cvr')}")
print(f" Invoice Number: {result.get('invoice_number')}")
print(f" Date: {result.get('invoice_date')}")
print(f" Total: {result.get('total_amount')}")
print(f" Detection Patterns: {result.get('detection_patterns')}")
# Check CVR filter
found_cvr = result.get('cvr')
OWN_CVR = "44687369"
if found_cvr == OWN_CVR:
print(f"\n❌ FAIL: AI returned OWN_CVR {OWN_CVR} - filter didn't work!")
elif found_cvr == "29522790":
print(f"\n✅ PASS: AI found correct vendor CVR {found_cvr} (DCS ApS)")
else:
print(f"\n⚠️ WARNING: AI found CVR {found_cvr} - unexpected value")
else:
print(f"❌ Error: {response.text}")