Spaces:
Sleeping
Sleeping
| """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'] | |