Spaces:
Sleeping
Sleeping
File size: 3,800 Bytes
21f1a73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
"""Tests for error handling."""
import pytest
import json
from app import ClaimsGPT
class TestErrorHandling:
"""Test error handling in ClaimsGPT."""
def setup_method(self):
"""Setup test instance."""
self.app = ClaimsGPT()
def test_invalid_json_input(self):
"""Test handling of invalid JSON."""
invalid_json = '{"claim_type": "motor", invalid}'
result_json, status = self.app.process_claim(invalid_json)
result = json.loads(result_json)
assert 'error' in result
assert 'Invalid JSON' in result['error']
assert '❌' in status
def test_missing_claim_type(self):
"""Test handling of missing claim type."""
claim = json.dumps({
"policy_number": "TEST-12345",
"claim_amount": 5000.00
})
result_json, status = self.app.process_claim(claim)
result = json.loads(result_json)
assert 'error' in result
def test_invalid_claim_type(self):
"""Test handling of invalid claim type."""
claim = json.dumps({
"claim_type": "invalid_type",
"policy_number": "TEST-12345",
"claim_amount": 5000.00
})
result_json, status = self.app.process_claim(claim)
result = json.loads(result_json)
assert 'error' in result
assert 'Invalid claim type' in result['error']
def test_schema_validation_failure(self):
"""Test handling of schema validation failure."""
claim = json.dumps({
"claim_type": "motor",
"policy_number": "X", # Too short
"incident_date": "invalid-date",
"claim_amount": -1000, # Negative
"description": "Short", # Too short
"claimant_name": "A", # Too short
"vehicle_make": "Toyota",
"vehicle_model": "Camry",
"vehicle_year": 2022,
"license_plate": "ABC",
"accident_type": "collision",
"location": "Test",
"police_report_filed": False,
"other_party_involved": False,
"injuries_reported": False
})
result_json, status = self.app.process_claim(claim)
result = json.loads(result_json)
assert 'error' in result
assert 'Schema validation failed' in result['error']
assert len(result['details']) > 0
def test_empty_input(self):
"""Test handling of empty input."""
result_json, status = self.app.process_claim('')
result = json.loads(result_json)
assert 'error' in result
def test_successful_processing_returns_no_error(self):
"""Test that successful processing doesn't return error."""
claim = json.dumps({
"claim_type": "motor",
"policy_number": "MOT-2025-12345",
"incident_date": "2025-12-20",
"claim_amount": 5000.00,
"description": "Vehicle collision at intersection with damage",
"claimant_name": "John Doe",
"vehicle_make": "Toyota",
"vehicle_model": "Camry",
"vehicle_year": 2022,
"license_plate": "ABC-1234",
"accident_type": "collision",
"location": "Main St & 5th Ave, Seattle, WA",
"police_report_filed": True,
"police_report_number": "SPD-12345",
"other_party_involved": True,
"injuries_reported": False
})
result_json, status = self.app.process_claim(claim)
result = json.loads(result_json)
assert 'error' not in result
assert 'decision' in result
assert result['decision'] in ['APPROVED', 'REJECTED', 'REVIEW']
|