87 lines
2.6 KiB
Python
87 lines
2.6 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
Test Quick Analysis on Upload
|
||
|
|
Tests CVR detection, document type, and invoice number extraction
|
||
|
|
"""
|
||
|
|
|
||
|
|
import asyncio
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
# Add app directory to path
|
||
|
|
sys.path.insert(0, str(Path(__file__).parent / "app"))
|
||
|
|
|
||
|
|
from app.services.ollama_service import ollama_service
|
||
|
|
|
||
|
|
async def test_quick_analysis():
|
||
|
|
"""Test quick analysis with sample text"""
|
||
|
|
|
||
|
|
# Sample invoice text with CVR
|
||
|
|
sample_invoice = """
|
||
|
|
ALSO Danmark A/S
|
||
|
|
Jupitervej 4
|
||
|
|
6000 Kolding
|
||
|
|
|
||
|
|
CVR-nr.: 35812428
|
||
|
|
|
||
|
|
FAKTURA
|
||
|
|
|
||
|
|
Faktura nr.: INV-2024-12345
|
||
|
|
Dato: 2024-12-08
|
||
|
|
|
||
|
|
Beløb i alt: 5.965,18 DKK
|
||
|
|
"""
|
||
|
|
|
||
|
|
# Sample credit note text
|
||
|
|
sample_credit_note = """
|
||
|
|
Test Leverandør A/S
|
||
|
|
CVR: 12345678
|
||
|
|
|
||
|
|
KREDITNOTA
|
||
|
|
|
||
|
|
Kreditnota nr.: CN-2024-5678
|
||
|
|
Original faktura: INV-2024-1000
|
||
|
|
|
||
|
|
Beløb: -1.234,56 DKK
|
||
|
|
"""
|
||
|
|
|
||
|
|
print("🧪 Testing Quick Analysis\n")
|
||
|
|
print("=" * 60)
|
||
|
|
|
||
|
|
# Test 1: Invoice with CVR
|
||
|
|
print("\n📄 TEST 1: Invoice with CVR")
|
||
|
|
print("-" * 60)
|
||
|
|
result1 = await ollama_service.quick_analysis_on_upload(sample_invoice)
|
||
|
|
print(f"CVR: {result1['cvr']}")
|
||
|
|
print(f"Document Type: {result1['document_type']}")
|
||
|
|
print(f"Document Number: {result1['document_number']}")
|
||
|
|
print(f"Vendor ID: {result1['vendor_id']}")
|
||
|
|
print(f"Vendor Name: {result1['vendor_name']}")
|
||
|
|
|
||
|
|
assert result1['cvr'] == '35812428', f"Expected CVR 35812428, got {result1['cvr']}"
|
||
|
|
assert result1['document_type'] == 'invoice', f"Expected invoice, got {result1['document_type']}"
|
||
|
|
assert result1['document_number'] == 'INV-2024-12345', f"Expected INV-2024-12345, got {result1['document_number']}"
|
||
|
|
print("✅ Test 1 PASSED")
|
||
|
|
|
||
|
|
# Test 2: Credit Note
|
||
|
|
print("\n📄 TEST 2: Credit Note")
|
||
|
|
print("-" * 60)
|
||
|
|
result2 = await ollama_service.quick_analysis_on_upload(sample_credit_note)
|
||
|
|
print(f"CVR: {result2['cvr']}")
|
||
|
|
print(f"Document Type: {result2['document_type']}")
|
||
|
|
print(f"Document Number: {result2['document_number']}")
|
||
|
|
print(f"Vendor ID: {result2['vendor_id']}")
|
||
|
|
print(f"Vendor Name: {result2['vendor_name']}")
|
||
|
|
|
||
|
|
assert result2['cvr'] == '12345678', f"Expected CVR 12345678, got {result2['cvr']}"
|
||
|
|
assert result2['document_type'] == 'credit_note', f"Expected credit_note, got {result2['document_type']}"
|
||
|
|
assert result2['document_number'] == 'CN-2024-5678', f"Expected CN-2024-5678, got {result2['document_number']}"
|
||
|
|
print("✅ Test 2 PASSED")
|
||
|
|
|
||
|
|
print("\n" + "=" * 60)
|
||
|
|
print("✅ ALL TESTS PASSED!")
|
||
|
|
print("=" * 60)
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
asyncio.run(test_quick_analysis())
|