#!/usr/bin/env python """ Focused test script that tests the most important functionality without getting caught up in serialization format complexities """ import sys from datetime import datetime from models import UserStatus, UserType, SkillLevel, EmploymentType, Candidate, Employer, Location, Skill def test_model_creation(): """Test that we can create models successfully""" print("๐Ÿงช Testing model creation...") # Create supporting objects location = Location(text="Austin, TX USA") skill = Skill(name="Python", category="Programming", level=SkillLevel.ADVANCED) # Create candidate candidate = Candidate( email="test@example.com", user_type=UserType.CANDIDATE, username="test_candidate", created_at=datetime.now(), updated_at=datetime.now(), status=UserStatus.ACTIVE, first_name="John", last_name="Doe", full_name="John Doe", skills=[skill], experience=[], education=[], preferred_job_types=[EmploymentType.FULL_TIME], location=location, languages=[], certifications=[], ) # Create employer employer = Employer( user_type=UserType.EMPLOYER, first_name="Mary", last_name="Smith", full_name="Mary Smith", email="hr@company.com", created_at=datetime.now(), updated_at=datetime.now(), status=UserStatus.ACTIVE, company_name="Test Company", industry="Technology", company_size="50-200", company_description="A test company", location=location, ) print(f"โœ… Candidate: {candidate.first_name} {candidate.last_name}") print(f"โœ… Employer: {employer.company_name}") print(f"โœ… User types: {candidate.user_type}, {employer.user_type}") return candidate, employer def test_json_api_format(): """Test JSON serialization in API format (the most important use case)""" print("\n๐Ÿ“ก Testing JSON API format...") candidate, employer = test_model_creation() # Serialize to JSON (API format) candidate_json = candidate.model_dump_json(by_alias=True) employer_json = employer.model_dump_json(by_alias=True) print(f"โœ… Candidate JSON: {len(candidate_json)} chars") print(f"โœ… Employer JSON: {len(employer_json)} chars") # Deserialize from JSON candidate_back = Candidate.model_validate_json(candidate_json) employer_back = Employer.model_validate_json(employer_json) # Verify data integrity assert candidate_back.email == candidate.email assert candidate_back.first_name == candidate.first_name assert employer_back.company_name == employer.company_name print("โœ… JSON round-trip successful") print("โœ… Data integrity verified") return True def test_api_dict_format(): """Test dictionary format with aliases (for API requests/responses)""" print("\n๐Ÿ“Š Testing API dictionary format...") candidate, employer = test_model_creation() # Create API format dictionaries candidate_dict = candidate.model_dump(by_alias=True) employer_dict = employer.model_dump(by_alias=True) # Verify camelCase aliases are used assert "firstName" in candidate_dict assert "lastName" in candidate_dict assert "createdAt" in candidate_dict assert "companyName" in employer_dict print("โœ… API format dictionaries created") print("โœ… CamelCase aliases verified") # Test deserializing from API format candidate_back = Candidate.model_validate(candidate_dict) employer_back = Employer.model_validate(employer_dict) assert candidate_back.email == candidate.email assert employer_back.company_name == employer.company_name print("โœ… API format round-trip successful") return True def test_validation_constraints(): """Test that validation constraints work""" print("\n๐Ÿ”’ Testing validation constraints...") try: # Create a candidate with invalid email Candidate( user_type=UserType.CANDIDATE, email="invalid-email", username="test_invalid", created_at=datetime.now(), updated_at=datetime.now(), status=UserStatus.ACTIVE, first_name="Jane", last_name="Doe", full_name="Jane Doe", ) print("โŒ Validation should have failed but didn't") return False except ValueError as e: print(f"โœ… Validation error caught: {e}") return True def test_enum_values(): """Test that enum values work correctly""" print("\n๐Ÿ“‹ Testing enum values...") # Test that enum values are properly handled candidate, employer = test_model_creation() # Check enum values in serialization candidate_dict = candidate.model_dump(by_alias=True) assert candidate_dict["status"] == "active" assert candidate_dict["userType"] == "candidate" assert employer.user_type == UserType.EMPLOYER print("โœ… Enum values correctly serialized") print(f"โœ… User types: candidate={candidate.user_type}, employer={employer.user_type}") return True def main(): """Run all focused tests""" print("๐ŸŽฏ Focused Pydantic Model Tests") print("=" * 40) try: test_model_creation() test_json_api_format() test_api_dict_format() test_validation_constraints() test_enum_values() print("\n๐ŸŽ‰ All focused tests passed!") print("=" * 40) print("โœ… Models work correctly") print("โœ… JSON API format works") print("โœ… Validation constraints work") print("โœ… Enum values work") print("โœ… Ready for type generation!") return True except Exception as e: print(f"\nโŒ Test failed: {type(e).__name__}: {e}") import traceback traceback.print_exc() print(f"\nโŒ {traceback.format_exc()}") return False if __name__ == "__main__": success = main() sys.exit(0 if success else 1)