Spaces:
Sleeping
Sleeping
| """Tests for validation utilities.""" | |
| import pytest | |
| import json | |
| from utils.validators import validate_json_input, validate_claim_schema, validate_required_fields | |
| from schemas.motor_claim import MotorClaim | |
| from schemas.medical_claim import MedicalClaim | |
| class TestJSONValidation: | |
| """Test JSON validation.""" | |
| def test_valid_json(self): | |
| """Test valid JSON input.""" | |
| valid_json = '{"claim_type": "motor", "amount": 1000}' | |
| result = validate_json_input(valid_json) | |
| assert result.is_valid is True | |
| assert result.data is not None | |
| def test_invalid_json(self): | |
| """Test invalid JSON input.""" | |
| invalid_json = '{"claim_type": "motor", "amount": }' | |
| result = validate_json_input(invalid_json) | |
| assert result.is_valid is False | |
| assert len(result.errors) > 0 | |
| def test_empty_string(self): | |
| """Test empty string input.""" | |
| result = validate_json_input('') | |
| assert result.is_valid is False | |
| class TestMotorClaimValidation: | |
| """Test motor claim schema validation.""" | |
| def test_valid_motor_claim(self): | |
| """Test valid motor claim.""" | |
| claim_data = { | |
| "claim_type": "motor", | |
| "policy_number": "MOT-2025-12345", | |
| "incident_date": "2025-12-20", | |
| "claim_amount": 5000.00, | |
| "description": "Vehicle collision at intersection with significant 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 = validate_claim_schema(claim_data, MotorClaim) | |
| assert result.is_valid is True | |
| def test_missing_required_fields(self): | |
| """Test motor claim with missing fields.""" | |
| claim_data = { | |
| "claim_type": "motor", | |
| "policy_number": "MOT-2025-12345" | |
| } | |
| result = validate_claim_schema(claim_data, MotorClaim) | |
| assert result.is_valid is False | |
| assert len(result.errors) > 0 | |
| def test_invalid_date_format(self): | |
| """Test motor claim with invalid date.""" | |
| claim_data = { | |
| "claim_type": "motor", | |
| "policy_number": "MOT-2025-12345", | |
| "incident_date": "2025-13-45", # Invalid date | |
| "claim_amount": 5000.00, | |
| "description": "Vehicle collision at intersection", | |
| "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", | |
| "police_report_filed": False, | |
| "other_party_involved": False, | |
| "injuries_reported": False | |
| } | |
| result = validate_claim_schema(claim_data, MotorClaim) | |
| assert result.is_valid is False | |
| class TestMedicalClaimValidation: | |
| """Test medical claim schema validation.""" | |
| def test_valid_medical_claim(self): | |
| """Test valid medical claim.""" | |
| claim_data = { | |
| "claim_type": "medical", | |
| "policy_number": "MED-2025-54321", | |
| "incident_date": "2025-12-18", | |
| "claim_amount": 12500.00, | |
| "description": "Emergency appendectomy surgery with hospital stay", | |
| "claimant_name": "Robert Johnson", | |
| "patient_name": "Robert Johnson", | |
| "patient_dob": "1985-06-15", | |
| "diagnosis_code": "K35.80", | |
| "treatment_type": "surgery", | |
| "provider_name": "Seattle General Hospital", | |
| "treatment_date": "2025-12-18", | |
| "prescription_required": True, | |
| "hospitalization_required": True, | |
| "hospitalization_days": 2, | |
| "pre_existing_condition": False | |
| } | |
| result = validate_claim_schema(claim_data, MedicalClaim) | |
| assert result.is_valid is True | |
| def test_hospitalization_validation(self): | |
| """Test hospitalization days validation.""" | |
| claim_data = { | |
| "claim_type": "medical", | |
| "policy_number": "MED-2025-54321", | |
| "incident_date": "2025-12-18", | |
| "claim_amount": 12500.00, | |
| "description": "Emergency surgery with hospital stay", | |
| "claimant_name": "Robert Johnson", | |
| "patient_name": "Robert Johnson", | |
| "patient_dob": "1985-06-15", | |
| "diagnosis_code": "K35.80", | |
| "treatment_type": "surgery", | |
| "provider_name": "Seattle General Hospital", | |
| "treatment_date": "2025-12-18", | |
| "prescription_required": True, | |
| "hospitalization_required": True, | |
| "hospitalization_days": 0, # Invalid: required but 0 | |
| "pre_existing_condition": False | |
| } | |
| result = validate_claim_schema(claim_data, MedicalClaim) | |
| assert result.is_valid is False | |