Files
tilbudgivern/tests/test_pdf_generation.py
alexpolo1 26d3452d59 Add comprehensive tests for API verification, frontend integration, and PDF generation
- Implemented a new test suite for production API verification using curl, ensuring all critical endpoints respond correctly and return valid JSON.
- Added frontend integration tests to check for critical errors in the UI and verify key UI elements are present and functional.
- Created test data for quotes and project calculations to facilitate testing.
- Developed a script to check offers in the Ordrestyring system, including detailed task descriptions.
- Added tests for generating PDFs from quote data, ensuring the output is valid and contains expected information.
- Implemented a test script for the Røsevangen project, integrating with the Ordrestyring API and verifying database entries.
2025-11-07 08:02:07 +00:00

133 lines
4.7 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify PDF generation works correctly
"""
import sys
import os
sys.path.append('/mnt/HC_Volume_103713257/tilbudgivern/backend')
from pdf_generator import TilbudgivernPDFGenerator
from datetime import datetime
import json
# Create test data that matches the expected structure in pdf_generator.py
test_data = {
'quote_number': f'TG-{datetime.now().strftime("%Y%m%d")}-TEST',
'project': {
'customer_name': 'Test Kunde A/S',
'customer_address': 'Testvej 123, 4000 Roskilde',
'project_description': 'udskiftning af tag på enfamiliehus'
},
'geometry': {
'total_area': 105.0,
'roof_type': 'Komplet tagudskiftning med B7 eternit',
'roof_pitch': 35
},
'labor': {
'total_work_hours': 85.5,
'carpenter_count': 2,
'hourly_rate': 580.0
},
'materials': [
{
'material_category': 'Eternit B7 tagplader 920x1320mm',
'quantity': 223,
'total_price': 54635.00
},
{
'material_category': 'Lindab Rainline tagrende 125mm',
'quantity': 14,
'total_price': 3430.00
},
{
'material_category': 'Trykimprægnerede lægter 30x50mm',
'quantity': 228,
'total_price': 4218.00
},
{
'material_category': 'Eternit rygning inkl. elementer',
'quantity': 12,
'total_price': 2040.00
},
{
'material_category': 'Lindab nedløb komplet system',
'quantity': 4,
'total_price': 2180.00
}
],
'calculation': {
'total_labor_cost': 49590.00, # 85.5 * 580
'total_material_cost': 66503.00,
'overhead_percentage': 15.0,
'profit_percentage': 20.0,
'vat_percentage': 25.0
}
}
# Output paths
output_pdf = '/mnt/HC_Volume_103713257/tilbudgivern/Test_Tilbud.pdf'
output_json = '/mnt/HC_Volume_103713257/tilbudgivern/test_data.json'
# Save test data to JSON
print("💾 Gemmer test data til JSON...")
with open(output_json, 'w', encoding='utf-8') as f:
json.dump(test_data, f, indent=2, ensure_ascii=False)
print(f"✅ JSON gemt: {output_json}")
# Generate PDF
print("\n🔨 GENERERER TEST PDF...")
print(f"📋 Kunde: {test_data['project']['customer_name']}")
print(f"📍 Adresse: {test_data['project']['customer_address']}")
print(f"📐 Tagareal: {test_data['geometry']['total_area']}")
print(f"⏱️ Arbejdstimer: {test_data['labor']['total_work_hours']} timer")
try:
generator = TilbudgivernPDFGenerator()
success = generator.generate_pdf(test_data, output_pdf)
if success:
# Check if file exists and has content
if os.path.exists(output_pdf):
file_size = os.path.getsize(output_pdf)
print(f"\n✅ PDF GENERERET SUCCESFULDT!")
print(f"📄 Fil: {output_pdf}")
print(f"📊 Størrelse: {file_size:,} bytes")
if file_size > 1000:
print(f"✓ PDF indeholder data (ikke tom)")
# Calculate expected values
labor = test_data['calculation']['total_labor_cost']
materials = test_data['calculation']['total_material_cost']
subtotal = labor + materials
overhead = subtotal * 0.15
profit = subtotal * 0.20
before_vat = subtotal + overhead + profit
vat = before_vat * 0.25
total_with_vat = before_vat + vat
print(f"\n💰 PRISBEREGNING:")
print(f" Arbejdsløn: {labor:>12,.2f} kr")
print(f" Materialer: {materials:>12,.2f} kr")
print(f" ─────────────────────────────")
print(f" Subtotal: {subtotal:>12,.2f} kr")
print(f" Overhead (15%): {overhead:>12,.2f} kr")
print(f" Profit (20%): {profit:>12,.2f} kr")
print(f" Moms (25%): {vat:>12,.2f} kr")
print(f" ═════════════════════════════")
print(f" TOTAL: {total_with_vat:>12,.2f} kr")
print(f"\n✓ PDF kan nu åbnes og verificeres")
else:
print(f"⚠️ ADVARSEL: PDF er meget lille ({file_size} bytes) - muligvis tom!")
else:
print(f"❌ FEJL: PDF fil blev ikke oprettet!")
else:
print(f"❌ FEJL: PDF generering returnerede False")
except Exception as e:
print(f"❌ FEJL ved generering: {e}")
import traceback
traceback.print_exc()