PensionBot / test_evidence_pack.py
ChAbhishek28's picture
Fix evidence pack generation with proper data transformation
295d256
raw
history blame
3.89 kB
#!/usr/bin/env python3
"""
Test script to verify evidence pack generation works correctly
"""
import sys
import os
sys.path.append(os.path.dirname(__file__))
from evidence_pack_export import export_evidence_pack_pdf, export_evidence_pack_csv
from datetime import datetime
# Test data that mimics what the frontend would send
test_message_data = {
"text": "What are the pension eligibility criteria in Rajasthan? I need to know about minimum service requirements and retirement age.",
"sender": "bot",
"timestamp": datetime.now().isoformat(),
"sources": [
{"title": "Rajasthan Pension Rules 1998", "confidence": 0.85},
{"title": "Government Pension Manual", "confidence": 0.78}
]
}
def transform_test_data(raw_data):
"""Transform test data to evidence pack format (same as in app.py)"""
message_text = raw_data.get('text', '')
evidence_data = {
"clause_text": "Rajasthan Pension Rules - Eligibility Criteria: Government employees are eligible for pension after completing minimum qualifying service of 10 years. The normal retirement age is 58 years for Class IV employees and 60 years for other employees.",
"summary": "Rajasthan Pension Rules: Pension Eligibility and Service Requirements - Comprehensive guide on minimum service requirements and retirement age criteria for government employees.",
"role_checklist": [
"Verify minimum 10 years qualifying service",
"Check retirement age (58 for Class IV, 60 for others)",
"Confirm employee category and service record",
"Submit pension application 6 months before retirement",
"Prepare required documents and certificates"
],
"source_title": "Rajasthan Pension Rules - Voice Bot Response",
"clause_id": f"VB_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
"date": datetime.now().strftime("%Y-%m-%d"),
"url": "https://chabhishek28-pensionbot.hf.space",
"original_query": "What are the pension eligibility criteria in Rajasthan?",
"sources": raw_data.get('sources', []),
"timestamp": datetime.now().isoformat()
}
return evidence_data
def test_evidence_pack_generation():
"""Test both PDF and CSV evidence pack generation"""
print("πŸ§ͺ Testing Evidence Pack Generation...")
# Transform the test data
evidence_data = transform_test_data(test_message_data)
print("πŸ“‹ Generated evidence data:")
print(f" - Clause: {evidence_data['clause_text'][:80]}...")
print(f" - Summary: {evidence_data['summary'][:80]}...")
print(f" - Checklist items: {len(evidence_data['role_checklist'])}")
print(f" - Source: {evidence_data['source_title']}")
print(f" - Date: {evidence_data['date']}")
# Test PDF generation
print("\nπŸ“„ Testing PDF generation...")
try:
pdf_path = export_evidence_pack_pdf(evidence_data)
print(f"βœ… PDF generated successfully: {pdf_path}")
print(f" File size: {os.path.getsize(pdf_path)} bytes")
except Exception as e:
print(f"❌ PDF generation failed: {e}")
# Test CSV generation
print("\nπŸ“Š Testing CSV generation...")
try:
csv_path = export_evidence_pack_csv(evidence_data)
print(f"βœ… CSV generated successfully: {csv_path}")
print(f" File size: {os.path.getsize(csv_path)} bytes")
# Show CSV content
with open(csv_path, 'r', encoding='utf-8') as f:
lines = f.readlines()[:10] # First 10 lines
print(" CSV preview:")
for line in lines:
print(f" {line.strip()}")
except Exception as e:
print(f"❌ CSV generation failed: {e}")
if __name__ == "__main__":
test_evidence_pack_generation()
print("\nπŸŽ‰ Evidence pack test completed!")